report logfile access issues
committer: Valeriy Yatsko <dwr@it-penza.org>
This commit is contained in:
parent
731fac317d
commit
cdf7c361aa
1 changed files with 48 additions and 0 deletions
48
src/logger.c
48
src/logger.c
|
@ -73,12 +73,57 @@ 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
|
||||
open_logfiles(void)
|
||||
|
@ -94,9 +139,12 @@ 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
close_logfiles(void)
|
||||
|
|
Loading…
Reference in a new issue