[ https://issues.apache.org/jira/browse/TS-3160?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14189732#comment-14189732 ]
ASF GitHub Bot commented on TS-3160: ------------------------------------ GitHub user hopkings2008 opened a pull request: https://github.com/apache/trafficserver/pull/135 TS-3160 fix problem of mis-closing fd before forking traffic_manager In traffic_cop 'main' function, before it forks traffic_manager, it will first close stdin, stdout, and stderr and then redirect them to /dev/null. But when it closes the fd opened by /dev/null, it doesn't check whether the fd is 0, 1 or 2. So, in current code logic, the fd may be 1, and after close it, later opened file will uses the fd 1, and printf will corrupt that file. 1826 if (!stdout_flag) { 1827 close(STDIN_FILENO); 1828 close(STDOUT_FILENO); 1829 close(STDERR_FILENO); 1830 if ((fd = open("/dev/null", O_WRONLY, 0)) >= 0) { 1831 fcntl(fd, F_DUPFD, STDIN_FILENO); 1832 fcntl(fd, F_DUPFD, STDOUT_FILENO); 1833 fcntl(fd, F_DUPFD, STDERR_FILENO); 1834 close(fd); //zouyu this doesn't check the fd value 0, 1 or 2. 1835 } else { 1836 ink_fputln(stderr, "Unable to open /dev/null"); 1837 return 0; 1838 } 1839 } You can merge this pull request into a Git repository by running: $ git pull https://github.com/yahoo/trafficserver TS-3160 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/trafficserver/pull/135.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #135 ---- commit 12343b3b52697e890419832cdeffe83585366df4 Author: zouyu <z...@yahoo-inc.com> Date: 2014-10-30T07:11:29Z TS-3160 fix problem of mis-closing fd before forking traffic_manager ---- > traffic_cop mis-closed fd before forking traffic_manager > -------------------------------------------------------- > > Key: TS-3160 > URL: https://issues.apache.org/jira/browse/TS-3160 > Project: Traffic Server > Issue Type: Bug > Components: Cop > Reporter: zouyu > > In traffic_cop 'main' function, before it forks traffic_manager, it will > first close stdin, stdout, and stderr and then redirect them to /dev/null. > But when it closes the fd opened by /dev/null, it doesn't check whether the > fd is 0, 1 or 2. So, in current code logic, the fd may be 1, and after close > it, later opened file will uses the fd 1, and printf will corrupt that file. > 1826 if (!stdout_flag) { > 1827 close(STDIN_FILENO); > 1828 close(STDOUT_FILENO); > 1829 close(STDERR_FILENO); > 1830 if ((fd = open("/dev/null", O_WRONLY, 0)) >= 0) { > 1831 fcntl(fd, F_DUPFD, STDIN_FILENO); > 1832 fcntl(fd, F_DUPFD, STDOUT_FILENO); > 1833 fcntl(fd, F_DUPFD, STDERR_FILENO); > 1834 close(fd); //zouyu this doesn't check the fd value 0, 1 or 2. > 1835 } else { > 1836 ink_fputln(stderr, "Unable to open /dev/null"); > 1837 return 0; > 1838 } > 1839 } -- This message was sent by Atlassian JIRA (v6.3.4#6332)