diff options
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 70 |
1 files changed, 35 insertions, 35 deletions
@@ -31,38 +31,38 @@ # define O_LARGEFILE 0 #endif -/** +/** * open the errorlog - * + * * we have 3 possibilities: * - stderr (default) - * - syslog + * - syslog * - logfile - * + * * if the open failed, report to the user and die - * + * */ int log_error_open(server *srv) { int fd; int close_stderr = 1; - + #ifdef HAVE_SYSLOG_H /* perhaps someone wants to use syslog() */ openlog("lighttpd", LOG_CONS | LOG_PID, LOG_DAEMON); #endif srv->errorlog_mode = ERRORLOG_STDERR; - + if (srv->srvconf.errorlog_use_syslog) { srv->errorlog_mode = ERRORLOG_SYSLOG; } else if (!buffer_is_empty(srv->srvconf.errorlog_file)) { const char *logfile = srv->srvconf.errorlog_file->ptr; - + if (-1 == (srv->errorlog_fd = open(logfile, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) { - log_error_write(srv, __FILE__, __LINE__, "SSSS", + log_error_write(srv, __FILE__, __LINE__, "SSSS", "opening errorlog '", logfile, "' failed: ", strerror(errno)); - + return -1; } #ifdef FD_CLOEXEC @@ -71,15 +71,15 @@ int log_error_open(server *srv) { #endif srv->errorlog_mode = ERRORLOG_FILE; } - + log_error_write(srv, __FILE__, __LINE__, "s", "server started"); - + #ifdef HAVE_VALGRIND_VALGRIND_H /* don't close stderr for debugging purposes if run in valgrind */ if (RUNNING_ON_VALGRIND) close_stderr = 0; #endif if (srv->errorlog_mode == ERRORLOG_STDERR) close_stderr = 0; - + /* move stderr to /dev/null */ if (close_stderr && -1 != (fd = open("/dev/null", O_WRONLY))) { @@ -90,33 +90,33 @@ int log_error_open(server *srv) { return 0; } -/** +/** * open the errorlog - * + * * if the open failed, report to the user and die * if no filename is given, use syslog instead - * + * */ int log_error_cycle(server *srv) { /* only cycle if we are not in syslog-mode */ - + if (srv->errorlog_mode == ERRORLOG_FILE) { const char *logfile = srv->srvconf.errorlog_file->ptr; /* already check of opening time */ - + int new_fd; - + if (-1 == (new_fd = open(logfile, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) { /* write to old log */ - log_error_write(srv, __FILE__, __LINE__, "SSSSS", + log_error_write(srv, __FILE__, __LINE__, "SSSSS", "cycling errorlog '", logfile, "' failed: ", strerror(errno), ", falling back to syslog()"); - + close(srv->errorlog_fd); srv->errorlog_fd = -1; -#ifdef HAVE_SYSLOG_H +#ifdef HAVE_SYSLOG_H srv->errorlog_mode = ERRORLOG_SYSLOG; #endif } else { @@ -125,15 +125,15 @@ int log_error_cycle(server *srv) { srv->errorlog_fd = new_fd; } } - + log_error_write(srv, __FILE__, __LINE__, "s", "logfiles cycled"); - + return 0; } int log_error_close(server *srv) { log_error_write(srv, __FILE__, __LINE__, "s", "server stopped"); - + switch(srv->errorlog_mode) { case ERRORLOG_FILE: close(srv->errorlog_fd); @@ -146,13 +146,13 @@ int log_error_close(server *srv) { case ERRORLOG_STDERR: break; } - + return 0; } int log_error_write(server *srv, const char *filename, unsigned int line, const char *fmt, ...) { va_list ap; - + switch(srv->errorlog_mode) { case ERRORLOG_FILE: case ERRORLOG_STDERR: @@ -161,7 +161,7 @@ int log_error_write(server *srv, const char *filename, unsigned int line, const buffer_prepare_copy(srv->ts_debug_str, 255); strftime(srv->ts_debug_str->ptr, srv->ts_debug_str->size - 1, "%Y-%m-%d %H:%M:%S", localtime(&(srv->cur_ts))); srv->ts_debug_str->used = strlen(srv->ts_debug_str->ptr) + 1; - + srv->last_generated_debug_ts = srv->cur_ts; } @@ -173,19 +173,19 @@ int log_error_write(server *srv, const char *filename, unsigned int line, const BUFFER_COPY_STRING_CONST(srv->errorlog_buf, "("); break; } - + buffer_append_string(srv->errorlog_buf, filename); BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "."); buffer_append_long(srv->errorlog_buf, line); BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, ") "); - - + + for(va_start(ap, fmt); *fmt; fmt++) { int d; char *s; buffer *b; off_t o; - + switch(*fmt) { case 's': /* string */ s = va_arg(ap, char *); @@ -227,7 +227,7 @@ int log_error_write(server *srv, const char *filename, unsigned int line, const break; case '(': case ')': - case '<': + case '<': case '>': case ',': case ' ': @@ -236,7 +236,7 @@ int log_error_write(server *srv, const char *filename, unsigned int line, const } } va_end(ap); - + switch(srv->errorlog_mode) { case ERRORLOG_FILE: BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "\n"); @@ -250,7 +250,7 @@ int log_error_write(server *srv, const char *filename, unsigned int line, const syslog(LOG_ERR, "%s", srv->errorlog_buf->ptr); break; } - + return 0; } |