diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-02-11 20:00:31 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-02-11 20:00:31 +0000 |
commit | cccf7ac1715ec17045c6b55f90920c847a9cd312 (patch) | |
tree | 9af361d6926dea8b7409e8f916b087fa9451363c /Foundation/GTMServiceManagement.c | |
parent | c60f8abf7deacc732a980272f13a12e144c579b6 (diff) |
[Author: dmaclach]
Fix up HORRIBLE bug closing bad file descriptors.
R=thomasvl
DELTA=5 (1 added, 0 deleted, 4 changed)
Diffstat (limited to 'Foundation/GTMServiceManagement.c')
-rw-r--r-- | Foundation/GTMServiceManagement.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Foundation/GTMServiceManagement.c b/Foundation/GTMServiceManagement.c index 62d280d..564358d 100644 --- a/Foundation/GTMServiceManagement.c +++ b/Foundation/GTMServiceManagement.c @@ -436,15 +436,16 @@ static int open_devnull(int fd) { void spc_sanitize_files(void) { int standard_fds[] = { STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO }; - size_t standard_fds_count = sizeof(standard_fds) / sizeof(standard_fds[0]); + int standard_fds_count + = (int)(sizeof(standard_fds) / sizeof(standard_fds[0])); // Make sure all open descriptors other than the standard ones are closed - size_t fds = getdtablesize(); - for (size_t i = standard_fds_count; i < fds; ++i) close(standard_fds[i]); + int fds = getdtablesize(); + for (int i = standard_fds_count; i < fds; ++i) close(i); // Verify that the standard descriptors are open. If they're not, attempt to // open them using /dev/null. If any are unsuccessful, abort. - for (size_t i = 0; i < standard_fds_count; ++i) { + for (int i = 0; i < standard_fds_count; ++i) { struct stat st; int fd = standard_fds[i]; if (fstat(fd, &st) == -1 && (errno != EBADF || !open_devnull(fd))) { |