Changeset 2163
- Timestamp:
- 04/29/2008 08:59:39 PM (2 weeks ago)
- Files:
-
- branches/lighttpd-1.4.x/NEWS (modified) (1 diff)
- branches/lighttpd-1.4.x/src/log.c (modified) (3 diffs)
- branches/lighttpd-1.4.x/src/log.h (modified) (1 diff)
- branches/lighttpd-1.4.x/src/mod_accesslog.c (modified) (1 diff)
- branches/lighttpd-1.4.x/src/mod_cgi.c (modified) (2 diffs)
- branches/lighttpd-1.4.x/src/mod_fastcgi.c (modified) (2 diffs)
- branches/lighttpd-1.4.x/src/mod_rrdtool.c (modified) (2 diffs)
- branches/lighttpd-1.4.x/src/server.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/lighttpd-1.4.x/NEWS
r2162 r2163 25 25 * Do not rely on PATH_MAX (POSIX does not require it) (#580) 26 26 * Disable logging to access.log if filename is an empty string 27 * Implement a clean way to open /dev/null and use it to close stdin/out/err in the needed places (#624) 27 28 28 29 - 1.4.19 - 2008-03-10 branches/lighttpd-1.4.x/src/log.c
r1957 r2163 32 32 #endif 33 33 34 /* Close fd and _try_ to get a /dev/null for it instead. 35 * close() alone may trigger some bugs when a 36 * process opens another file and gets fd = STDOUT_FILENO or STDERR_FILENO 37 * and later tries to just print on stdout/stderr 38 * 39 * Returns 0 on success and -1 on failure (fd gets closed in all cases) 40 */ 41 int openDevNull(int fd) { 42 int tmpfd; 43 close(fd); 44 #if defined(__WIN32) 45 /* Cygwin should work with /dev/null */ 46 tmpfd = open("nul", O_RDWR); 47 #else 48 tmpfd = open("/dev/null", O_RDWR); 49 #endif 50 if (tmpfd != -1 && tmpfd != fd) { 51 dup2(tmpfd, fd); 52 close(tmpfd); 53 } 54 return (tmpfd != -1) ? 0 : -1; 55 } 56 34 57 /** 35 58 * open the errorlog … … 45 68 46 69 int log_error_open(server *srv) { 47 int fd;48 70 int close_stderr = 1; 49 71 … … 79 101 if (RUNNING_ON_VALGRIND) close_stderr = 0; 80 102 #endif 81 if (srv->errorlog_mode == ERRORLOG_STDERR) close_stderr = 0; 103 104 if (srv->errorlog_mode == ERRORLOG_STDERR && srv->srvconf.dont_daemonize) { 105 /* We can only log to stderr in dont-daemonize mode; 106 * if we do daemonize and no errorlog file is specified, we log into /dev/null 107 */ 108 close_stderr = 0; 109 } 82 110 83 111 /* move stderr to /dev/null */ 84 if (close_stderr && 85 -1 != (fd = open("/dev/null", O_WRONLY))) { 86 close(STDERR_FILENO); 87 dup2(fd, STDERR_FILENO); 88 close(fd); 89 } 112 if (close_stderr) openDevNull(STDERR_FILENO); 90 113 return 0; 91 114 } branches/lighttpd-1.4.x/src/log.h
r1371 r2163 3 3 4 4 #include "server.h" 5 6 /* Close fd and _try_ to get a /dev/null for it instead. 7 * Returns 0 on success and -1 on failure (fd gets closed in all cases) 8 */ 9 int openDevNull(int fd); 5 10 6 11 #define WP() log_error_write(srv, __FILE__, __LINE__, ""); branches/lighttpd-1.4.x/src/mod_accesslog.c
r2162 r2163 499 499 close(to_log_fds[1]); 500 500 501 openDevNull(STDERR_FILENO); 502 501 503 /* we don't need the client socket */ 502 504 for (i = 3; i < 256; i++) { branches/lighttpd-1.4.x/src/mod_cgi.c
r2153 r2163 988 988 } 989 989 990 openDevNull(STDERR_FILENO); 991 990 992 /* we don't need the client socket */ 991 993 for (i = 3; i < 256; i++) { … … 996 998 execve(args[0], args, env.ptr); 997 999 998 log_error_write(srv, __FILE__, __LINE__, "sss", "CGI failed:", strerror(errno), args[0]);1000 /* log_error_write(srv, __FILE__, __LINE__, "sss", "CGI failed:", strerror(errno), args[0]); */ 999 1001 1000 1002 /* */ branches/lighttpd-1.4.x/src/mod_fastcgi.c
r2150 r2163 938 938 } 939 939 940 openDevNull(STDERR_FILENO); 941 940 942 /* we don't need the client socket */ 941 943 for (i = 3; i < 256; i++) { … … 1001 1003 execve(arg.ptr[0], arg.ptr, env.ptr); 1002 1004 1003 log_error_write(srv, __FILE__, __LINE__, "sbs",1004 "execve failed for:", host->bin_path, strerror(errno)); 1005 /* log_error_write(srv, __FILE__, __LINE__, "sbs", 1006 "execve failed for:", host->bin_path, strerror(errno)); */ 1005 1007 1006 1008 exit(errno); branches/lighttpd-1.4.x/src/mod_rrdtool.c
r1371 r2163 149 149 args[i++] = NULL; 150 150 151 openDevNull(STDERR_FILENO); 152 151 153 /* we don't need the client socket */ 152 154 for (i = 3; i < 256; i++) { … … 157 159 execv(args[0], args); 158 160 159 log_error_write(srv, __FILE__, __LINE__, "sss", "spawing rrdtool failed: ", strerror(errno), args[0]);161 /* log_error_write(srv, __FILE__, __LINE__, "sss", "spawing rrdtool failed: ", strerror(errno), args[0]); */ 160 162 161 163 /* */ branches/lighttpd-1.4.x/src/server.c
r2151 r2163 574 574 575 575 /* close stdin and stdout, as they are not needed */ 576 /* move stdin to /dev/null */ 577 if (-1 != (fd = open("/dev/null", O_RDONLY))) { 578 close(STDIN_FILENO); 579 dup2(fd, STDIN_FILENO); 580 close(fd); 581 } 582 583 /* move stdout to /dev/null */ 584 if (-1 != (fd = open("/dev/null", O_WRONLY))) { 585 close(STDOUT_FILENO); 586 dup2(fd, STDOUT_FILENO); 587 close(fd); 588 } 576 openDevNull(STDIN_FILENO); 577 openDevNull(STDOUT_FILENO); 589 578 590 579 if (0 != config_set_defaults(srv)) {

