samples/c/0/log.c
int log_error_cycle(server *srv) {
	/* only cycle if we are not in syslog-mode */
	
	if (0 == srv->log_using_syslog) {
		const char *logfile = srv->srvconf.error_logfile->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", 
					"cycling errorlog '", logfile,
					"' failed: ", strerror(errno),
					", falling back to syslog()");
			
			close(srv->log_error_fd);
			srv->log_error_fd = -1;
#ifdef HAVE_SYSLOG_H	
			/* fall back to syslog() */
			srv->log_using_syslog = 1;
			
			openlog("lighttpd", LOG_CONS, LOG_LOCAL0);
#endif
		} else {
			/* ok, new log is open, close the old one */
			close(srv->log_error_fd);
			srv->log_error_fd = new_fd;
		}
	}
	
	log_error_write(srv, __FILE__, __LINE__, "s", "logfiles cycled");
	
	return 0;
}
/** 
 * open the errorlog
 * 
 * if the open failed, report to the user and die
 * if no filename is given, use syslog instead
 * 
 */
open the errorlog

if the open failed, report to the user and die
if no filename is given, use syslog instead
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) {
	if (0 == srv->log_using_syslog) {
		const char *logfile = srv->srvconf.error_logfile->ptr;
		int new_fd;
		if (-1 == (new_fd = open(logfile, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE, 0644))) {
			log_error_write(srv, __FILE__, __LINE__, "SSSSS", 
					"cycling errorlog '", logfile,
					"' failed: ", strerror(errno),
					", falling back to syslog()");
			close(srv->log_error_fd);
			srv->log_error_fd = -1;
#ifdef HAVE_SYSLOG_H	
			srv->log_using_syslog = 1;
			openlog("lighttpd", LOG_CONS, LOG_LOCAL0);
#endif
		} else {
			close(srv->log_error_fd);
			srv->log_error_fd = new_fd;
		}
	}
	log_error_write(srv, __FILE__, __LINE__, "s", "logfiles cycled");
	return 0;
}
int log_error_cycle ( server * srv ) { if ( 0 == srv -> log_using_syslog ) { const char * logfile = srv -> srvconf . error_logfile -> ptr ; int new_fd ; if ( -1 == ( new_fd = open ( logfile , O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE , 0644 ) ) ) { log_error_write ( srv , __FILE__ , __LINE__ , " " , " " , logfile , " " , strerror ( errno ) , " " ) ; close ( srv -> log_error_fd ) ; srv -> log_error_fd = -1 ; #ifdef HAVE_SYSLOG_H srv -> log_using_syslog = 1 ; openlog ( " " , LOG_CONS , LOG_LOCAL0 ) ; #endif } else { close ( srv -> log_error_fd ) ; srv -> log_error_fd = new_fd ; } } log_error_write ( srv , __FILE__ , __LINE__ , " " , " " ) ; return 0 ; }
open the errorlog
open the errorlog
/* only cycle if we are not in syslog-mode */ /* already check of opening time */ /* write to old log */ /* fall back to syslog() */ /* ok, new log is open, close the old one */