]> mj.ucw.cz Git - libucw.git/blobdiff - lib/log-file.c
significant simplifications of the interface
[libucw.git] / lib / log-file.c
index 5916acb5bf648d50575359b209a7a40c31fd5b20..c6575cc42f726d3f4b1870315aea423fa8e74acc 100644 (file)
@@ -1,7 +1,7 @@
 /*
- *     Sherlock Library -- Keeping of Log Files
+ *     UCW Library -- Keeping of Log Files
  *
- *     (c) 1997--2004 Martin Mares <mj@ucw.cz>
+ *     (c) 1997--2005 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -10,7 +10,6 @@
 #include "lib/lib.h"
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 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)
@@ -45,15 +45,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 +84,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);
     }
 }