X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Flog-file.c;h=0b22ff243e8811618dadf45c201b17b9051f74ec;hb=e371dcc1cd2857036374dd9597705faed0427006;hp=20dea918c80ae13813913ecd05f58a7b4d99971d;hpb=830fe27b64b0c11567d19b36b45940f99922b050;p=libucw.git diff --git a/lib/log-file.c b/lib/log-file.c index 20dea918..0b22ff24 100644 --- a/lib/log-file.c +++ b/lib/log-file.c @@ -1,7 +1,7 @@ /* * UCW Library -- Keeping of Log Files * - * (c) 1997--2005 Martin Mares + * (c) 1997--2006 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -9,6 +9,7 @@ #include "lib/lib.h" #include "lib/lfs.h" +#include "lib/threads.h" #include #include @@ -19,7 +20,7 @@ static char *log_name_patt; static int log_params; static int log_filename_size; -volatile int log_switch_nest; +static int log_switch_nest; static int do_log_switch(struct tm *tm) @@ -31,6 +32,7 @@ do_log_switch(struct tm *tm) if (!log_name_patt || log_filename[0] && !log_params) return 0; + ucwlib_lock(); log_switch_nest++; l = strftime(name, log_filename_size, log_name_patt, tm); if (l < 0 || l >= log_filename_size) @@ -41,14 +43,12 @@ do_log_switch(struct tm *tm) 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); - dup(fd); + dup2(fd, 2); close(fd); - close(1); - dup(2); switched = 1; } log_switch_nest--; + ucwlib_unlock(); return switched; } @@ -67,7 +67,7 @@ internal_log_switch(struct tm *tm) } void -log_file(byte *name) +log_file(const char *name) { if (name) { @@ -94,6 +94,19 @@ log_fork(void) log_pid = getpid(); } +void +log_switch_disable(void) +{ + log_switch_nest++; +} + +void +log_switch_enable(void) +{ + ASSERT(log_switch_nest); + log_switch_nest--; +} + #ifdef TEST int main(int argc, char **argv)