Changeset 38:546c34da7ac6
- Timestamp:
- 06/27/06 11:53:04
(2 years ago)
- Author:
- Allan Saddi <allan@saddi.com>
- branch:
- default
- convert_revision:
- svn:46762da8-4eb7-0310-94e9-d918b60927c8/flup/trunk@2016
- Message:
Set close-on-exec flag on all server sockets.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r37 |
r38 |
|
| | 1 | 2006-06-27 Allan Saddi <asaddi@kalahari.flup.org> |
|---|
| | 2 | |
|---|
| | 3 | * Set close-on-exec flag on all server sockets. Thanks to |
|---|
| | 4 | Ralf Schmitt for reporting the problem. |
|---|
| | 5 | |
|---|
| 1 | 6 | 2006-06-18 Allan Saddi <asaddi@europa.saddi.net> |
|---|
| 2 | 7 | |
|---|
| r33 |
r38 |
|
| 54 | 54 | socket.socketpair = socketpair |
|---|
| 55 | 55 | |
|---|
| | 56 | try: |
|---|
| | 57 | import fcntl |
|---|
| | 58 | except ImportError: |
|---|
| | 59 | def setCloseOnExec(sock): |
|---|
| | 60 | pass |
|---|
| | 61 | else: |
|---|
| | 62 | def setCloseOnExec(sock): |
|---|
| | 63 | fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC) |
|---|
| | 64 | |
|---|
| 56 | 65 | class PreforkServer(object): |
|---|
| 57 | 66 | """ |
|---|
| … | … | |
| 103 | 112 | sock.setblocking(0) |
|---|
| 104 | 113 | |
|---|
| | 114 | # Set close-on-exec |
|---|
| | 115 | setCloseOnExec(sock) |
|---|
| | 116 | |
|---|
| 105 | 117 | # Main loop. |
|---|
| 106 | 118 | while self._keepGoing: |
|---|
| … | … | |
| 256 | 268 | parent, child = socket.socketpair() |
|---|
| 257 | 269 | parent.setblocking(0) |
|---|
| | 270 | setCloseOnExec(parent) |
|---|
| 258 | 271 | child.setblocking(0) |
|---|
| | 272 | setCloseOnExec(child) |
|---|
| 259 | 273 | try: |
|---|
| 260 | 274 | pid = os.fork() |
|---|
| … | … | |
| 318 | 332 | raise |
|---|
| 319 | 333 | |
|---|
| | 334 | setCloseOnExec(clientSock) |
|---|
| | 335 | |
|---|
| 320 | 336 | # Check if this client is allowed. |
|---|
| 321 | 337 | if not self._isClientAllowed(addr): |
|---|
| r30 |
r38 |
|
| 35 | 35 | from threadpool import ThreadPool |
|---|
| 36 | 36 | |
|---|
| | 37 | try: |
|---|
| | 38 | import fcntl |
|---|
| | 39 | except ImportError: |
|---|
| | 40 | def setCloseOnExec(sock): |
|---|
| | 41 | pass |
|---|
| | 42 | else: |
|---|
| | 43 | def setCloseOnExec(sock): |
|---|
| | 44 | fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC) |
|---|
| | 45 | |
|---|
| 37 | 46 | __all__ = ['ThreadedServer'] |
|---|
| 38 | 47 | |
|---|
| … | … | |
| 55 | 64 | self._installSignalHandlers() |
|---|
| 56 | 65 | |
|---|
| | 66 | # Set close-on-exec |
|---|
| | 67 | setCloseOnExec(sock) |
|---|
| | 68 | |
|---|
| 57 | 69 | # Main loop. |
|---|
| 58 | 70 | while self._keepGoing: |
|---|
| … | … | |
| 72 | 84 | raise |
|---|
| 73 | 85 | |
|---|
| | 86 | setCloseOnExec(clientSock) |
|---|
| | 87 | |
|---|
| 74 | 88 | if not self._isClientAllowed(addr): |
|---|
| 75 | 89 | clientSock.close() |
|---|