X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Flog-file.c;h=20dea918c80ae13813913ecd05f58a7b4d99971d;hb=7b9f085a0cc79ca3263b1fdaff66119bd03a49f6;hp=ca144d6eda50cda4f33b1ad573f8be17932104b9;hpb=cad27e97e6370f96903d42aaf345c099af0a03bd;p=libucw.git diff --git a/lib/log-file.c b/lib/log-file.c index ca144d6e..20dea918 100644 --- a/lib/log-file.c +++ b/lib/log-file.c @@ -1,16 +1,16 @@ /* * UCW Library -- Keeping of Log Files * - * (c) 1997--2004 Martin Mares + * (c) 1997--2005 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. */ #include "lib/lib.h" +#include "lib/lfs.h" #include -#include #include #include #include @@ -19,17 +19,18 @@ static char *log_name_patt; static int log_params; static int log_filename_size; -int log_switch_nest; +volatile int log_switch_nest; -static void +static int do_log_switch(struct tm *tm) { int fd, l; char name[log_filename_size]; + int switched = 0; if (!log_name_patt || log_filename[0] && !log_params) - return; + return 0; log_switch_nest++; l = strftime(name, log_filename_size, log_name_patt, tm); if (l < 0 || l >= log_filename_size) @@ -37,7 +38,7 @@ do_log_switch(struct tm *tm) if (strcmp(name, log_filename)) { strcpy(log_filename, name); - fd = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666); + fd = sh_open(name, O_WRONLY | O_CREAT | O_APPEND, 0666); if (fd < 0) die("Unable to open log file %s: %m", name); close(2); @@ -45,15 +46,17 @@ do_log_switch(struct tm *tm) close(fd); close(1); dup(2); + switched = 1; } log_switch_nest--; + return switched; } -void +int log_switch(void) { time_t tim = time(NULL); - do_log_switch(localtime(&tim)); + return do_log_switch(localtime(&tim)); } static void @@ -82,8 +85,6 @@ log_file(byte *name) log_filename[0] = 0; log_switch(); log_switch_hook = internal_log_switch; - close(0); - open("/dev/null", O_RDWR, 0); } }