X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/bec4db9b38a0f515162a066c4e51a58bb9497cc4..62a2743ab7aef4888c53c7dbc1c46c28d19a95b2:/src/logger.c?ds=sidebyside diff --git a/src/logger.c b/src/logger.c index 56af880..b6d3dcc 100644 --- a/src/logger.c +++ b/src/logger.c @@ -31,7 +31,6 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: s_log.c 3209 2007-02-11 16:54:43Z jilles $ */ #include "stdinc.h" @@ -73,11 +72,56 @@ static struct log_struct log_table[LAST_LOGFILE] = { &ConfigFileEntry.fname_ioerrorlog, &log_ioerror } }; +static void +verify_logfile_access(const char *filename) +{ + char *dirname, *d; + char buf[512]; + d = rb_dirname(filename); + dirname = LOCAL_COPY(d); + rb_free(d); + + if(access(dirname, F_OK) == -1) + { + rb_snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - parent directory %s does not exist", filename, dirname); + if(testing_conf || server_state_foreground) + fprintf(stderr, "%s\n", buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); + return; + } + + if(access(filename, F_OK) == -1) + { + if(access(dirname, W_OK) == -1) + { + rb_snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - access to parent directory %s failed: %s", + filename, dirname, strerror(errno)); + if(testing_conf || server_state_foreground) + fprintf(stderr, "%s\n", buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); + } + return; + } + + if(access(filename, W_OK) == -1) + { + rb_snprintf(buf, sizeof(buf), "WARNING: Access denied for logfile %s: %s", filename, strerror(errno)); + if(testing_conf || server_state_foreground) + fprintf(stderr, "%s\n", buf); + sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf); + return; + } + return; +} + void init_main_logfile(void) { + verify_logfile_access(logFileName); if(log_main == NULL) + { log_main = fopen(logFileName, "a"); + } } void @@ -94,7 +138,10 @@ open_logfiles(void) { /* reopen those with paths */ if(!EmptyString(*log_table[i].name)) + { + verify_logfile_access(*log_table[i].name); *log_table[i].logfile = fopen(*log_table[i].name, "a"); + } } } @@ -132,7 +179,8 @@ ilog(ilogfile dest, const char *format, ...) rb_vsnprintf(buf, sizeof(buf), format, args); va_end(args); - rb_snprintf(buf2, sizeof(buf2), "%s %s\n", smalldate(), buf); + rb_snprintf(buf2, sizeof(buf2), "%s %s\n", + smalldate(rb_current_time()), buf); if(fputs(buf2, logfile) < 0) { @@ -218,11 +266,10 @@ report_operspy(struct Client *source_p, const char *token, const char *arg) } const char * -smalldate(void) +smalldate(time_t ltime) { static char buf[MAX_DATE_STRING]; struct tm *lt; - time_t ltime = rb_current_time(); lt = localtime(<ime);