X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Flog-file.c;h=0b22ff243e8811618dadf45c201b17b9051f74ec;hb=e371dcc1cd2857036374dd9597705faed0427006;hp=1ef69a14456ff4a64828266ed9e220a75fa81e02;hpb=46e157026fd164f2babccca4d1bcc57400b37c78;p=libucw.git diff --git a/lib/log-file.c b/lib/log-file.c index 1ef69a14..0b22ff24 100644 --- a/lib/log-file.c +++ b/lib/log-file.c @@ -20,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) @@ -43,11 +43,8 @@ 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--; @@ -70,7 +67,7 @@ internal_log_switch(struct tm *tm) } void -log_file(byte *name) +log_file(const char *name) { if (name) { @@ -97,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)