Changeset 475
- Timestamp:
- 07/26/2005 08:26:28 AM (3 years ago)
- Location:
- branches/lighttpd-1.3.x/src
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/lighttpd-1.3.x/src/base.h
r470 r475 408 408 unsigned short port; 409 409 buffer *bindhost; 410 buffer *error_logfile; 410 411 buffer *errorlog_file; 412 unsigned short errorlog_use_syslog; 413 411 414 unsigned short dont_daemonize; 412 415 buffer *changeroot; … … 414 417 buffer *groupname; 415 418 416 buffer *license;417 419 buffer *pid_file; 418 420 … … 456 458 server_socket_array srv_sockets; 457 459 458 int log_error_fd; 459 int log_using_syslog; 460 /* the errorlog */ 461 int errorlog_fd; 462 enum { ERRORLOG_STDERR, ERRORLOG_FILE, ERRORLOG_SYSLOG } errorlog_mode; 463 buffer *errorlog_buf; 464 460 465 fdevents *ev, *ev_ins; 461 466 … … 463 468 void *plugin_slots; 464 469 470 /* counters */ 465 471 int con_opened; 466 472 int con_read; … … 478 484 buffer *parse_full_path; 479 485 buffer *response_header; 480 buffer *error_log;481 486 buffer *response_range; 482 487 buffer *tmp_buf; -
branches/lighttpd-1.3.x/src/config.c
r447 r475 77 77 78 78 { "dir-listing.encoding", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 41 */ 79 { "server.errorlog-use-syslog", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 42 */ 79 80 80 81 { "server.host", "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, … … 93 94 /* 0 */ 94 95 cv[0].destination = srv->srvconf.bindhost; 95 cv[1].destination = srv->srvconf.error _logfile;96 cv[1].destination = srv->srvconf.errorlog_file; 96 97 cv[3].destination = srv->srvconf.changeroot; 97 98 cv[4].destination = srv->srvconf.username; … … 107 108 cv[36].destination = &(srv->srvconf.log_request_header_on_error); 108 109 cv[37].destination = &(srv->srvconf.log_state_handling); 110 111 cv[42].destination = &(srv->srvconf.errorlog_use_syslog); 109 112 110 113 srv->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); -
branches/lighttpd-1.3.x/src/log.c
r1 r475 33 33 * open the errorlog 34 34 * 35 * we have 3 possibilities: 36 * - stderr (default) 37 * - syslog 38 * - logfile 39 * 35 40 * if the open failed, report to the user and die 36 * if no filename is given, use syslog instead37 41 * 38 42 */ … … 42 46 int close_stderr = 1; 43 47 44 if (srv->srvconf.error_logfile->used) { 45 const char *logfile = srv->srvconf.error_logfile->ptr; 46 47 if (-1 == (srv->log_error_fd = open(logfile, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) { 48 #ifdef HAVE_SYSLOG_H 49 /* perhaps someone wants to use syslog() */ 50 openlog("lighttpd", LOG_CONS | LOG_PID, LOG_DAEMON); 51 #endif 52 srv->errorlog_mode = ERRORLOG_STDERR; 53 54 if (srv->srvconf.errorlog_use_syslog) { 55 srv->errorlog_mode = ERRORLOG_SYSLOG; 56 } else if (!buffer_is_empty(srv->srvconf.errorlog_file)) { 57 const char *logfile = srv->srvconf.errorlog_file->ptr; 58 59 if (-1 == (srv->errorlog_fd = open(logfile, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) { 48 60 log_error_write(srv, __FILE__, __LINE__, "SSSS", 49 61 "opening errorlog '", logfile, … … 54 66 #ifdef FD_CLOEXEC 55 67 /* close fd on exec (cgi) */ 56 fcntl(srv->log_error_fd, F_SETFD, FD_CLOEXEC); 57 #endif 58 } else { 59 srv->log_error_fd = -1; 60 #ifdef HAVE_SYSLOG_H 61 /* syslog-mode */ 62 srv->log_using_syslog = 1; 63 openlog("lighttpd", LOG_CONS, LOG_LOCAL0); 64 #endif 68 fcntl(srv->errorlog_fd, F_SETFD, FD_CLOEXEC); 69 #endif 70 srv->errorlog_mode = ERRORLOG_FILE; 65 71 } 66 72 … … 71 77 if (RUNNING_ON_VALGRIND) close_stderr = 0; 72 78 #endif 73 79 if (srv->errorlog_mode == ERRORLOG_STDERR) close_stderr = 0; 80 74 81 /* move stderr to /dev/null */ 75 82 if (close_stderr && … … 93 100 /* only cycle if we are not in syslog-mode */ 94 101 95 if ( 0 == srv->log_using_syslog) {96 const char *logfile = srv->srvconf.error _logfile->ptr;102 if (srv->errorlog_mode == ERRORLOG_FILE) { 103 const char *logfile = srv->srvconf.errorlog_file->ptr; 97 104 /* already check of opening time */ 98 105 … … 106 113 ", falling back to syslog()"); 107 114 108 close(srv-> log_error_fd);109 srv-> log_error_fd = -1;115 close(srv->errorlog_fd); 116 srv->errorlog_fd = -1; 110 117 #ifdef HAVE_SYSLOG_H 111 /* fall back to syslog() */ 112 srv->log_using_syslog = 1; 113 114 openlog("lighttpd", LOG_CONS, LOG_LOCAL0); 118 srv->errorlog_mode = ERRORLOG_SYSLOG; 115 119 #endif 116 120 } else { 117 121 /* ok, new log is open, close the old one */ 118 close(srv-> log_error_fd);119 srv-> log_error_fd = new_fd;122 close(srv->errorlog_fd); 123 srv->errorlog_fd = new_fd; 120 124 } 121 125 } … … 129 133 log_error_write(srv, __FILE__, __LINE__, "s", "server stopped"); 130 134 131 if (srv->log_error_fd >= 0) { 132 close(srv->log_error_fd); 133 } else if(srv->log_using_syslog) { 135 switch(srv->errorlog_mode) { 136 case ERRORLOG_FILE: 137 close(srv->errorlog_fd); 138 break; 139 case ERRORLOG_SYSLOG: 134 140 #ifdef HAVE_SYSLOG_H 135 141 closelog(); 136 142 #endif 143 break; 144 case ERRORLOG_STDERR: 145 break; 137 146 } 138 147 … … 143 152 va_list ap; 144 153 145 if (srv->log_using_syslog == 0) { 154 switch(srv->errorlog_mode) { 155 case ERRORLOG_FILE: 156 case ERRORLOG_STDERR: 146 157 /* cache the generated timestamp */ 147 158 if (srv->cur_ts != srv->last_generated_debug_ts) { … … 153 164 } 154 165 155 buffer_copy_string_buffer(srv->error_log, srv->ts_debug_str); 156 BUFFER_APPEND_STRING_CONST(srv->error_log, ": ("); 157 } else { 158 BUFFER_COPY_STRING_CONST(srv->error_log, "("); 159 } 160 buffer_append_string(srv->error_log, filename); 161 BUFFER_APPEND_STRING_CONST(srv->error_log, "."); 162 buffer_append_long(srv->error_log, line); 163 BUFFER_APPEND_STRING_CONST(srv->error_log, ") "); 166 buffer_copy_string_buffer(srv->errorlog_buf, srv->ts_debug_str); 167 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, ": ("); 168 break; 169 case ERRORLOG_SYSLOG: 170 /* syslog is generating its own timestamps */ 171 BUFFER_COPY_STRING_CONST(srv->errorlog_buf, "("); 172 break; 173 } 174 175 buffer_append_string(srv->errorlog_buf, filename); 176 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "."); 177 buffer_append_long(srv->errorlog_buf, line); 178 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, ") "); 164 179 165 180 … … 173 188 case 's': /* string */ 174 189 s = va_arg(ap, char *); 175 buffer_append_string(srv->error _log, s);176 BUFFER_APPEND_STRING_CONST(srv->error _log, " ");190 buffer_append_string(srv->errorlog_buf, s); 191 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " "); 177 192 break; 178 193 case 'b': /* buffer */ 179 194 b = va_arg(ap, buffer *); 180 buffer_append_string_buffer(srv->error _log, b);181 BUFFER_APPEND_STRING_CONST(srv->error _log, " ");195 buffer_append_string_buffer(srv->errorlog_buf, b); 196 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " "); 182 197 break; 183 198 case 'd': /* int */ 184 199 d = va_arg(ap, int); 185 buffer_append_long(srv->error _log, d);186 BUFFER_APPEND_STRING_CONST(srv->error _log, " ");200 buffer_append_long(srv->errorlog_buf, d); 201 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " "); 187 202 break; 188 203 case 'o': /* off_t */ 189 204 o = va_arg(ap, off_t); 190 buffer_append_off_t(srv->error _log, o);191 BUFFER_APPEND_STRING_CONST(srv->error _log, " ");205 buffer_append_off_t(srv->errorlog_buf, o); 206 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " "); 192 207 break; 193 208 case 'x': /* int (hex) */ 194 209 d = va_arg(ap, int); 195 BUFFER_APPEND_STRING_CONST(srv->error _log, "0x");196 buffer_append_hex(srv->error _log, d);197 BUFFER_APPEND_STRING_CONST(srv->error _log, " ");210 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "0x"); 211 buffer_append_hex(srv->errorlog_buf, d); 212 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " "); 198 213 break; 199 214 case 'S': /* string */ 200 215 s = va_arg(ap, char *); 201 buffer_append_string(srv->error _log, s);216 buffer_append_string(srv->errorlog_buf, s); 202 217 break; 203 218 case 'B': /* buffer */ 204 219 b = va_arg(ap, buffer *); 205 buffer_append_string_buffer(srv->error _log, b);220 buffer_append_string_buffer(srv->errorlog_buf, b); 206 221 break; 207 222 case 'D': /* int */ 208 223 d = va_arg(ap, int); 209 buffer_append_long(srv->error _log, d);224 buffer_append_long(srv->errorlog_buf, d); 210 225 break; 211 226 case '(': … … 215 230 case ',': 216 231 case ' ': 217 buffer_append_string_len(srv->error _log, fmt, 1);232 buffer_append_string_len(srv->errorlog_buf, fmt, 1); 218 233 break; 219 234 } … … 221 236 va_end(ap); 222 237 223 BUFFER_APPEND_STRING_CONST(srv->error_log, "\n"); 224 225 if (srv->log_error_fd >= 0) { 226 write(srv->log_error_fd, srv->error_log->ptr, srv->error_log->used - 1); 227 } else if (srv->log_using_syslog == 0) { 228 /* only available at startup time */ 229 write(STDERR_FILENO, srv->error_log->ptr, srv->error_log->used - 1); 230 } else { 231 #ifdef HAVE_SYSLOG_H 232 syslog(LOG_ERR, "%s", srv->error_log->ptr); 233 #endif 234 } 235 236 return 0; 237 } 238 238 switch(srv->errorlog_mode) { 239 case ERRORLOG_FILE: 240 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "\n"); 241 write(srv->errorlog_fd, srv->errorlog_buf->ptr, srv->errorlog_buf->used - 1); 242 break; 243 case ERRORLOG_STDERR: 244 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "\n"); 245 write(STDERR_FILENO, srv->errorlog_buf->ptr, srv->errorlog_buf->used - 1); 246 break; 247 case ERRORLOG_SYSLOG: 248 syslog(LOG_ERR, "%s", srv->errorlog_buf->ptr); 249 break; 250 } 251 252 return 0; 253 } 254 -
branches/lighttpd-1.3.x/src/mod_accesslog.c
r410 r475 446 446 447 447 if (s->use_syslog) { 448 if (srv->log_using_syslog == 0) {449 log_error_write(srv, __FILE__, __LINE__, "s",450 "accesslog can only be written to syslog if errorlog is also sent to syslog. ABORTING.");451 452 return HANDLER_ERROR;453 }454 455 448 /* ignore the next checks */ 456 449 continue; -
branches/lighttpd-1.3.x/src/mod_cgi.c
r365 r475 742 742 close(to_cgi_fds[1]); 743 743 744 if (srv->log_error_fd >= 0) { 744 /* HACK: 745 * this is not nice, but it works 746 * 747 * we feed the stderr of the CGI to our errorlog, if possible 748 */ 749 if (srv->errorlog_mode == ERRORLOG_FILE) { 745 750 close(STDERR_FILENO); 746 dup2(srv-> log_error_fd, STDERR_FILENO);751 dup2(srv->errorlog_fd, STDERR_FILENO); 747 752 } 748 753 … … 922 927 /* we don't need the client socket */ 923 928 for (i = 3; i < 256; i++) { 924 if (i != srv-> log_error_fd) close(i);929 if (i != srv->errorlog_fd) close(i); 925 930 } 926 931 -
branches/lighttpd-1.3.x/src/mod_rrdtool.c
r448 r475 133 133 134 134 close(STDERR_FILENO); 135 if (srv->log_error_fd != -1) { 136 dup2(srv->log_error_fd, STDERR_FILENO); 137 close(srv->log_error_fd); 135 136 if (srv->errorlog_mode == ERRORLOG_FILE) { 137 dup2(srv->errorlog_fd, STDERR_FILENO); 138 close(srv->errorlog_fd); 138 139 } 139 140 -
branches/lighttpd-1.3.x/src/server.c
r449 r475 123 123 CLEAN(ts_debug_str); 124 124 CLEAN(ts_date_str); 125 CLEAN(error _log);125 CLEAN(errorlog_buf); 126 126 CLEAN(response_range); 127 127 CLEAN(tmp_buf); … … 132 132 buffer_copy_string(srv->empty_string, ""); 133 133 134 CLEAN(srvconf.error _logfile);134 CLEAN(srvconf.errorlog_file); 135 135 CLEAN(srvconf.groupname); 136 136 CLEAN(srvconf.username); 137 137 CLEAN(srvconf.changeroot); 138 138 CLEAN(srvconf.bindhost); 139 CLEAN(srvconf.license);140 139 CLEAN(srvconf.event_handler); 141 140 CLEAN(srvconf.pid_file); … … 173 172 174 173 /* use syslog */ 175 srv->log_error_fd = -1; 174 srv->errorlog_fd = -1; 175 srv->errorlog_mode = ERRORLOG_STDERR; 176 176 177 177 srv->split_vals = array_init(); … … 204 204 CLEAN(ts_debug_str); 205 205 CLEAN(ts_date_str); 206 CLEAN(error _log);206 CLEAN(errorlog_buf); 207 207 CLEAN(response_range); 208 208 CLEAN(tmp_buf); … … 211 211 CLEAN(empty_string); 212 212 213 CLEAN(srvconf.error _logfile);213 CLEAN(srvconf.errorlog_file); 214 214 CLEAN(srvconf.groupname); 215 215 CLEAN(srvconf.username); 216 216 CLEAN(srvconf.changeroot); 217 217 CLEAN(srvconf.bindhost); 218 CLEAN(srvconf.license);219 218 CLEAN(srvconf.event_handler); 220 219 CLEAN(srvconf.pid_file);

