]> mj.ucw.cz Git - libucw.git/blobdiff - lib/log-file.c
Merge with git+ssh://git.ucw.cz/projects/sherlock/GIT/sherlock.git#v3.11
[libucw.git] / lib / log-file.c
index c6575cc42f726d3f4b1870315aea423fa8e74acc..401e797c3edeca4d4e5a529bc4b0e12debb13c30 100644 (file)
@@ -1,13 +1,15 @@
 /*
  *     UCW Library -- Keeping of Log Files
  *
 /*
  *     UCW Library -- Keeping of Log Files
  *
- *     (c) 1997--2005 Martin Mares <mj@ucw.cz>
+ *     (c) 1997--2006 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
  */
 
 #include "lib/lib.h"
  *
  *     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 "lib/threads.h"
 
 #include <stdio.h>
 #include <string.h>
 
 #include <stdio.h>
 #include <string.h>
@@ -30,6 +32,7 @@ do_log_switch(struct tm *tm)
   if (!log_name_patt ||
       log_filename[0] && !log_params)
     return 0;
   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)
   log_switch_nest++;
   l = strftime(name, log_filename_size, log_name_patt, tm);
   if (l < 0 || l >= log_filename_size)
@@ -37,17 +40,15 @@ do_log_switch(struct tm *tm)
   if (strcmp(name, log_filename))
     {
       strcpy(log_filename, name);
   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);
       if (fd < 0)
        die("Unable to open log file %s: %m", name);
-      close(2);
-      dup(fd);
+      dup2(fd, 2);
       close(fd);
       close(fd);
-      close(1);
-      dup(2);
       switched = 1;
     }
   log_switch_nest--;
       switched = 1;
     }
   log_switch_nest--;
+  ucwlib_unlock();
   return switched;
 }
 
   return switched;
 }
 
@@ -66,7 +67,7 @@ internal_log_switch(struct tm *tm)
 }
 
 void
 }
 
 void
-log_file(byte *name)
+log_file(const char *name)
 {
   if (name)
     {
 {
   if (name)
     {