Repository: trafficserver Updated Branches: refs/heads/master 96ae19b66 -> e938aa4c1
TS-3287: Use dup2() instead of close()/fnctl() to avoid race condition. Check return value of dup2() for errors. Coverity CID #1199994 Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/e938aa4c Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/e938aa4c Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/e938aa4c Branch: refs/heads/master Commit: e938aa4c15700d654e026e44a0d6aad9117849a6 Parents: 96ae19b Author: Phil Sorber <[email protected]> Authored: Thu Feb 5 16:25:38 2015 -0700 Committer: Phil Sorber <[email protected]> Committed: Thu Feb 5 16:25:38 2015 -0700 ---------------------------------------------------------------------- cmd/traffic_cop/traffic_cop.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e938aa4c/cmd/traffic_cop/traffic_cop.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_cop/traffic_cop.cc b/cmd/traffic_cop/traffic_cop.cc index e214877..ccbc976 100644 --- a/cmd/traffic_cop/traffic_cop.cc +++ b/cmd/traffic_cop/traffic_cop.cc @@ -1875,13 +1875,19 @@ main(int /* argc */, char *argv[]) // Detach STDIN, STDOUT, and STDERR (basically, "nohup"). /leif if (!stdout_flag) { - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); if ((fd = open("/dev/null", O_WRONLY, 0)) >= 0) { - fcntl(fd, F_DUPFD, STDIN_FILENO); - fcntl(fd, F_DUPFD, STDOUT_FILENO); - fcntl(fd, F_DUPFD, STDERR_FILENO); + if ((dup2(fd, STDIN_FILENO)) < 0) { + ink_fputln(stderr, "Unable to detach stdin"); + return 0; + } + if ((dup2(fd, STDOUT_FILENO)) < 0) { + ink_fputln(stderr, "Unable to detach stdout"); + return 0; + } + if ((dup2(fd, STDERR_FILENO)) < 0) { + ink_fputln(stderr, "Unable to detach stderr"); + return 0; + } close(fd); } else { ink_fputln(stderr, "Unable to open /dev/null");
