Gentoo Archives: gentoo-commits

From: "Christian Hoffmann (hoffie)" <hoffie@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in www-servers/lighttpd/files/1.4.20: 03_all_lighttpd-1.4.11-errorlog-pipe.diff
Date: Tue, 30 Sep 2008 14:58:11
Message-Id: E1Kkgfx-0002tl-4o@stork.gentoo.org
1 hoffie 08/09/30 14:58:09
2
3 Added: 03_all_lighttpd-1.4.11-errorlog-pipe.diff
4 Log:
5 version bump to 1.4.20, including fixes for the security issues outlined in bug 238180; removing old
6 (Portage version: 2.2_rc11/cvs/Linux 2.6.26-gentoo x86_64)
7 (Signed Manifest commit)
8
9 Revision Changes Path
10 1.1 www-servers/lighttpd/files/1.4.20/03_all_lighttpd-1.4.11-errorlog-pipe.diff
11
12 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/www-servers/lighttpd/files/1.4.20/03_all_lighttpd-1.4.11-errorlog-pipe.diff?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/www-servers/lighttpd/files/1.4.20/03_all_lighttpd-1.4.11-errorlog-pipe.diff?rev=1.1&content-type=text/plain
14
15 Index: 03_all_lighttpd-1.4.11-errorlog-pipe.diff
16 ===================================================================
17 Initial patch from http://trac.lighttpd.net/trac/ticket/296
18 Updated to apply against 1.4.20 by hoffie
19 Upstream will only accept it once it has been changed to make the pipe logging more generic
20
21 diff -r 447bac6969ef src/base.h
22 --- a/src/base.h Tue Aug 19 18:04:17 2008 +0200
23 +++ b/src/base.h Tue Aug 19 19:45:00 2008 +0200
24 @@ -530,7 +530,7 @@
25
26 /* the errorlog */
27 int errorlog_fd;
28 - enum { ERRORLOG_STDERR, ERRORLOG_FILE, ERRORLOG_SYSLOG } errorlog_mode;
29 + enum { ERRORLOG_STDERR, ERRORLOG_FILE, ERRORLOG_SYSLOG, ERRORLOG_PIPE } errorlog_mode;
30 buffer *errorlog_buf;
31
32 fdevents *ev, *ev_ins;
33 diff -r 447bac6969ef src/log.c
34 --- a/src/log.c Tue Aug 19 18:04:17 2008 +0200
35 +++ b/src/log.c Tue Aug 19 19:45:00 2008 +0200
36 @@ -57,10 +57,11 @@
37 /**
38 * open the errorlog
39 *
40 - * we have 3 possibilities:
41 + * we have 4 possibilities:
42 * - stderr (default)
43 * - syslog
44 * - logfile
45 + * - pipe
46 *
47 * if the open failed, report to the user and die
48 *
49 @@ -79,21 +80,80 @@
50 srv->errorlog_mode = ERRORLOG_SYSLOG;
51 } else if (!buffer_is_empty(srv->srvconf.errorlog_file)) {
52 const char *logfile = srv->srvconf.errorlog_file->ptr;
53 + if (logfile[0] == '|') {
54 +#ifdef HAVE_FORK
55 + /* create write pipe and spawn process */
56
57 - if (-1 == (srv->errorlog_fd = open(logfile, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) {
58 - log_error_write(srv, __FILE__, __LINE__, "SSSS",
59 + int to_log_fds[2];
60 + int fd;
61 + pid_t pid;
62 +
63 + if (pipe(to_log_fds)) {
64 + log_error_write(srv, __FILE__, __LINE__, "ss",
65 + "pipe failed: ", strerror(errno));
66 + return -1;
67 + }
68 +
69 + /* fork, execve */
70 + switch (pid = fork()) {
71 + case 0:
72 + /* child */
73 +
74 + close(STDIN_FILENO);
75 + dup2(to_log_fds[0], STDIN_FILENO);
76 + close(to_log_fds[0]);
77 + /* not needed */
78 + close(to_log_fds[1]);
79 +
80 + /* we don't need the client socket */
81 + for (fd = 3; fd < 256; fd++) {
82 + close(fd);
83 + }
84 +
85 + /* exec the log-process (skip the | )
86 + *
87 + */
88 +
89 + execl("/bin/sh", "sh", "-c", logfile + 1, NULL);
90 +
91 + log_error_write(srv, __FILE__, __LINE__, "sss",
92 + "spawning log-process failed: ",
93 + strerror(errno), logfile + 1);
94 +
95 + exit(-1);
96 + break;
97 + case -1:
98 + /* error */
99 + log_error_write(srv, __FILE__, __LINE__, "ss", "fork failed:", strerror(errno));
100 + break;
101 + default:
102 + close(to_log_fds[0]);
103 +
104 + srv->errorlog_fd = to_log_fds[1];
105 +
106 + break;
107 + }
108 + srv->errorlog_mode = ERRORLOG_PIPE;
109 +#else
110 + log_error_write(srv, __FILE__, __LINE__, "SSS",
111 + "opening errorlog '", logfile,"' impossible");
112 + return -1;
113 +#endif
114 + } else {
115 + if (-1 == (srv->errorlog_fd = open(logfile, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) {
116 + log_error_write(srv, __FILE__, __LINE__, "SSSS",
117 "opening errorlog '", logfile,
118 "' failed: ", strerror(errno));
119
120 - return -1;
121 + return -1;
122 + }
123 + srv->errorlog_mode = ERRORLOG_FILE;
124 }
125 #ifdef FD_CLOEXEC
126 /* close fd on exec (cgi) */
127 fcntl(srv->errorlog_fd, F_SETFD, FD_CLOEXEC);
128 #endif
129 - srv->errorlog_mode = ERRORLOG_FILE;
130 }
131 -
132 log_error_write(srv, __FILE__, __LINE__, "s", "server started");
133
134 #ifdef HAVE_VALGRIND_VALGRIND_H
135 @@ -122,7 +182,7 @@
136 */
137
138 int log_error_cycle(server *srv) {
139 - /* only cycle if we are not in syslog-mode */
140 + /* only cycle if the error log is a file */
141
142 if (srv->errorlog_mode == ERRORLOG_FILE) {
143 const char *logfile = srv->srvconf.errorlog_file->ptr;
144 @@ -154,6 +214,7 @@
145
146 int log_error_close(server *srv) {
147 switch(srv->errorlog_mode) {
148 + case ERRORLOG_PIPE: /* fall through */
149 case ERRORLOG_FILE:
150 close(srv->errorlog_fd);
151 break;
152 @@ -173,6 +234,7 @@
153 va_list ap;
154
155 switch(srv->errorlog_mode) {
156 + case ERRORLOG_PIPE:
157 case ERRORLOG_FILE:
158 case ERRORLOG_STDERR:
159 /* cache the generated timestamp */
160 @@ -257,6 +319,7 @@
161 va_end(ap);
162
163 switch(srv->errorlog_mode) {
164 + case ERRORLOG_PIPE: /* fall through */
165 case ERRORLOG_FILE:
166 buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("\n"));
167 write(srv->errorlog_fd, srv->errorlog_buf->ptr, srv->errorlog_buf->used - 1);
168 diff -r 447bac6969ef src/mod_cgi.c
169 --- a/src/mod_cgi.c Tue Aug 19 18:04:17 2008 +0200
170 +++ b/src/mod_cgi.c Tue Aug 19 19:45:00 2008 +0200
171 @@ -781,7 +781,7 @@
172 *
173 * we feed the stderr of the CGI to our errorlog, if possible
174 */
175 - if (srv->errorlog_mode == ERRORLOG_FILE) {
176 + if ((srv->errorlog_mode == ERRORLOG_FILE) || (srv->errorlog_mode == ERRORLOG_PIPE)) {
177 close(STDERR_FILENO);
178 dup2(srv->errorlog_fd, STDERR_FILENO);
179 }
180 diff -r 447bac6969ef src/mod_rrdtool.c
181 --- a/src/mod_rrdtool.c Tue Aug 19 18:04:17 2008 +0200
182 +++ b/src/mod_rrdtool.c Tue Aug 19 19:45:00 2008 +0200
183 @@ -134,7 +134,7 @@
184
185 close(STDERR_FILENO);
186
187 - if (srv->errorlog_mode == ERRORLOG_FILE) {
188 + if ((srv->errorlog_mode == ERRORLOG_FILE) || (srv->errorlog_mode == ERRORLOG_PIPE)) {
189 dup2(srv->errorlog_fd, STDERR_FILENO);
190 close(srv->errorlog_fd);
191 }