|
@@ -445,7 +445,7 @@ tor_log2(uint64_t u64)
|
|
|
r += 2;
|
|
|
}
|
|
|
if (u64 >= (U64_LITERAL(1)<<1)) {
|
|
|
- u64 >>= 1;
|
|
|
+ // u64 >>= 1; // not using this any more.
|
|
|
r += 1;
|
|
|
}
|
|
|
return r;
|
|
@@ -3616,7 +3616,7 @@ start_daemon(void)
|
|
|
} else { /* Child */
|
|
|
close(daemon_filedes[0]); /* we only write */
|
|
|
|
|
|
- pid = setsid(); /* Detach from controlling terminal */
|
|
|
+ (void) setsid(); /* Detach from controlling terminal */
|
|
|
/*
|
|
|
* Fork one more time, so the parent (the session group leader) can exit.
|
|
|
* This means that we, as a non-session group leader, can never regain a
|
|
@@ -4314,7 +4314,6 @@ tor_spawn_background(const char *const filename, const char **argv,
|
|
|
int stderr_pipe[2];
|
|
|
int stdin_pipe[2];
|
|
|
int fd, retval;
|
|
|
- ssize_t nbytes;
|
|
|
process_handle_t *process_handle;
|
|
|
int status;
|
|
|
|
|
@@ -4335,7 +4334,7 @@ tor_spawn_background(const char *const filename, const char **argv,
|
|
|
and we are not allowed to use unsafe functions between fork and exec */
|
|
|
error_message_length = strlen(error_message);
|
|
|
|
|
|
- child_state = CHILD_STATE_PIPE;
|
|
|
+ // child_state = CHILD_STATE_PIPE;
|
|
|
|
|
|
/* Set up pipe for redirecting stdout, stderr, and stdin of child */
|
|
|
retval = pipe(stdout_pipe);
|
|
@@ -4372,7 +4371,7 @@ tor_spawn_background(const char *const filename, const char **argv,
|
|
|
return status;
|
|
|
}
|
|
|
|
|
|
- child_state = CHILD_STATE_MAXFD;
|
|
|
+ // child_state = CHILD_STATE_MAXFD;
|
|
|
|
|
|
#ifdef _SC_OPEN_MAX
|
|
|
if (-1 == max_fd) {
|
|
@@ -4387,7 +4386,7 @@ tor_spawn_background(const char *const filename, const char **argv,
|
|
|
max_fd = DEFAULT_MAX_FD;
|
|
|
#endif /* defined(_SC_OPEN_MAX) */
|
|
|
|
|
|
- child_state = CHILD_STATE_FORK;
|
|
|
+ // child_state = CHILD_STATE_FORK;
|
|
|
|
|
|
pid = fork();
|
|
|
if (0 == pid) {
|
|
@@ -4423,7 +4422,7 @@ tor_spawn_background(const char *const filename, const char **argv,
|
|
|
if (-1 == retval)
|
|
|
goto error;
|
|
|
|
|
|
- child_state = CHILD_STATE_CLOSEFD;
|
|
|
+ // child_state = CHILD_STATE_CLOSEFD;
|
|
|
|
|
|
close(stderr_pipe[0]);
|
|
|
close(stderr_pipe[1]);
|
|
@@ -4439,7 +4438,7 @@ tor_spawn_background(const char *const filename, const char **argv,
|
|
|
close(fd);
|
|
|
}
|
|
|
|
|
|
- child_state = CHILD_STATE_EXEC;
|
|
|
+ // child_state = CHILD_STATE_EXEC;
|
|
|
|
|
|
/* Call the requested program. We need the cast because
|
|
|
execvp doesn't define argv as const, even though it
|
|
@@ -4458,7 +4457,8 @@ tor_spawn_background(const char *const filename, const char **argv,
|
|
|
error:
|
|
|
{
|
|
|
/* XXX: are we leaking fds from the pipe? */
|
|
|
- int n;
|
|
|
+ int n, err=0;
|
|
|
+ ssize_t nbytes;
|
|
|
|
|
|
n = format_helper_exit_status(child_state, errno, hex_errno);
|
|
|
|
|
@@ -4467,13 +4467,14 @@ tor_spawn_background(const char *const filename, const char **argv,
|
|
|
value, but there is nothing we can do if it fails */
|
|
|
/* TODO: Don't use STDOUT, use a pipe set up just for this purpose */
|
|
|
nbytes = write(STDOUT_FILENO, error_message, error_message_length);
|
|
|
+ err = (nbytes < 0);
|
|
|
nbytes = write(STDOUT_FILENO, hex_errno, n);
|
|
|
+ err += (nbytes < 0);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- (void) nbytes;
|
|
|
+ _exit(err?254:255);
|
|
|
+ }
|
|
|
|
|
|
- _exit(255);
|
|
|
/* Never reached, but avoids compiler warning */
|
|
|
return status; // LCOV_EXCL_LINE
|
|
|
}
|
|
@@ -4540,7 +4541,7 @@ tor_spawn_background(const char *const filename, const char **argv,
|
|
|
}
|
|
|
|
|
|
*process_handle_out = process_handle;
|
|
|
- return process_handle->status;
|
|
|
+ return status;
|
|
|
#endif /* defined(_WIN32) */
|
|
|
}
|
|
|
|