aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMServiceManagement.c
diff options
context:
space:
mode:
Diffstat (limited to 'Foundation/GTMServiceManagement.c')
-rw-r--r--Foundation/GTMServiceManagement.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Foundation/GTMServiceManagement.c b/Foundation/GTMServiceManagement.c
index 20fb6cc..eddde4a 100644
--- a/Foundation/GTMServiceManagement.c
+++ b/Foundation/GTMServiceManagement.c
@@ -435,16 +435,17 @@ static int open_devnull(int fd) {
void spc_sanitize_files(void) {
int standard_fds[] = { STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO };
- int standard_fds_count = sizeof(standard_fds) / sizeof(standard_fds[0]);
+ size_t standard_fds_count = sizeof(standard_fds) / sizeof(standard_fds[0]);
// Make sure all open descriptors other than the standard ones are closed
- int fds = getdtablesize();
- for (int fd = standard_fds_count; fd < fds; fd++) close(fd);
+ size_t fds = getdtablesize();
+ for (size_t i = standard_fds_count; i < fds; ++i) close(standard_fds[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 (int fd = 0; fd < standard_fds_count; fd++) {
+ for (size_t 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))) {
abort();
}