dgaudet 97/10/01 22:10:36
Modified: htdocs/manual new_features_1_3.html src CHANGES src/main http_main.c http_log.c Log: detach from stdin/out/err when booting PR: 523 Reviewed by: Dean Gaudet, Brian Behlendorf, Jim Jagielski Revision Changes Path 1.24 +6 -0 apachen/htdocs/manual/new_features_1_3.html Index: new_features_1_3.html =================================================================== RCS file: /export/home/cvs/apachen/htdocs/manual/new_features_1_3.html,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- new_features_1_3.html 1997/09/30 23:24:28 1.23 +++ new_features_1_3.html 1997/10/02 05:10:26 1.24 @@ -304,6 +304,12 @@ <a href="mod/mod_cern_meta.html">mod_cern_meta</a> is now configurable on a per-directory basis. +<li><strong>Detaching from stdin/out/err</strong><br> + On boot Apache will now detach from stdin, stdout, and stderr. It + does not detach from stderr until it has successfully read the config + files. So you will see errors in the config file. This should make + it easier to start Apache via rsh or crontab. + <li><strong>API Additions</strong><br> For all those module writers and code hackers: 1.454 +8 -1 apachen/src/CHANGES Index: CHANGES =================================================================== RCS file: /export/home/cvs/apachen/src/CHANGES,v retrieving revision 1.453 retrieving revision 1.454 diff -u -r1.453 -r1.454 --- CHANGES 1997/09/30 21:48:37 1.453 +++ CHANGES 1997/10/02 05:10:30 1.454 @@ -1,5 +1,12 @@ Changes with Apache 1.3b1 - + + *) When booting, apache will now detach itself from stdin, stdout, + and stderr. stderr will not be detached until after the config + files have been read so you will be able to see initial error + messages. After that all errors are logged in the error_log. + This makes it more convenient to start apache via rsh, ssh, + or crontabs. [Dean Gaudet] PR#523 + *) mod_proxy was sending HTTP/1.1 responses to ftp requests by mistake. Also removed the auto-generated link to www.apache.org that was the source of so many misdirected bug reports. [Roy Fielding, Marc Slemko] 1.227 +19 -0 apachen/src/main/http_main.c Index: http_main.c =================================================================== RCS file: /export/home/cvs/apachen/src/main/http_main.c,v retrieving revision 1.226 retrieving revision 1.227 diff -u -r1.226 -r1.227 --- http_main.c 1997/09/25 01:03:22 1.226 +++ http_main.c 1997/10/02 05:10:33 1.227 @@ -2077,6 +2077,25 @@ exit(1); } #endif + + /* close out the standard file descriptors */ + if (freopen("/dev/null", "r", stdin) == NULL) { + fprintf(stderr, "httpd: unable to replace stdin with /dev/null: %s\n", + strerror(errno)); + /* continue anyhow -- note we can't close out descriptor 0 because we + * have nothing to replace it with, and if we didn't have a descriptor + * 0 the next file would be created with that value ... leading to + * havoc. + */ + } + if (freopen("/dev/null", "w", stdout) == NULL) { + fprintf(stderr, "httpd: unable to replace stdout with /dev/null: %s\n", + strerror(errno)); + } + /* stderr is a tricky one, we really want it to be the error_log, + * but we haven't opened that yet. So leave it alone for now and it'll + * be reopened moments later. + */ #endif /* ndef WIN32 */ } 1.35 +27 -0 apachen/src/main/http_log.c Index: http_log.c =================================================================== RCS file: /export/home/cvs/apachen/src/main/http_log.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- http_log.c 1997/09/12 20:37:33 1.34 +++ http_log.c 1997/10/02 05:10:34 1.35 @@ -224,8 +224,35 @@ void open_logs (server_rec *s_main, pool *p) { server_rec *virt, *q; +#ifndef WIN32 + int replace_stderr; +#endif open_error_log (s_main, p); + +#ifndef WIN32 + replace_stderr = 1; + if (s_main->error_log) { + /* replace stderr with this new log */ + fflush(stderr); + if (dup2(fileno(s_main->error_log), 2) == -1) { + aplog_error(APLOG_MARK, APLOG_CRIT, s_main, + "unable to replace stderr with error_log: %s", + strerror(errno)); + } else { + replace_stderr = 0; + } + } + /* note that stderr may still need to be replaced with something + * because it points to the old error log, or back to the tty + * of the submitter. + */ + if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) { + aplog_error(APLOG_MARK, APLOG_CRIT, s_main, + "unable to replace stderr with /dev/null: %s", + strerror(errno)); + } +#endif for (virt = s_main->next; virt; virt = virt->next) { if (virt->error_fname)