about summary refs log tree commit diff
path: root/nscd
diff options
context:
space:
mode:
Diffstat (limited to 'nscd')
-rw-r--r--nscd/dbg_log.c20
-rw-r--r--nscd/dbg_log.h5
-rw-r--r--nscd/nscd.c3
-rw-r--r--nscd/nscd_conf.c12
4 files changed, 28 insertions, 12 deletions
diff --git a/nscd/dbg_log.c b/nscd/dbg_log.c
index b854170428..bcd9426020 100644
--- a/nscd/dbg_log.c
+++ b/nscd/dbg_log.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998, 2000 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 2000, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
 
@@ -19,6 +19,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
+#include <string.h>
 #include <syslog.h>
 #include <unistd.h>
 #include "dbg_log.h"
@@ -28,14 +29,25 @@
    if in debug mode and no debug file, we write the messages to stderr,
    else to syslog.  */
 
+static char *logfilename;
 FILE *dbgout;
 int debug_level;
 
-int
+void
 set_logfile (const char *logfile)
 {
-  dbgout = fopen (logfile, "a");
-  return dbgout == NULL ? 0 : 1;
+  logfilename = strdup (logfile);
+}
+
+int
+init_logfile (void)
+{
+  if (logfilename)
+    {
+      dbgout = fopen (logfilename, "a");
+      return dbgout == NULL ? 0 : 1;
+    }
+  return 1;
 }
 
 void
diff --git a/nscd/dbg_log.h b/nscd/dbg_log.h
index 705aa022ac..6cec54cae9 100644
--- a/nscd/dbg_log.h
+++ b/nscd/dbg_log.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998, 2000 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 2000, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
 
@@ -25,6 +25,7 @@ extern int debug_level;
 extern void dbg_log (const char *str, ...)
      __attribute__ ((__format__ (__printf__, 1, 2)));;
 
-extern int set_logfile (const char *logfile);
+extern void set_logfile (const char *logfile);
+extern int init_logfile (void);
 
 #endif
diff --git a/nscd/nscd.c b/nscd/nscd.c
index d01f9355ae..50d3cfcf5f 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -223,6 +223,9 @@ main (int argc, char **argv)
       if (write_pid (_PATH_NSCDPID) < 0)
         dbg_log ("%s: %s", _PATH_NSCDPID, strerror (errno));
 
+      if (!init_logfile ())
+	dbg_log (_("Could not create log file"));
+
       /* Ignore job control signals.  */
       signal (SIGTTOU, SIG_IGN);
       signal (SIGTTIN, SIG_IGN);
diff --git a/nscd/nscd_conf.c b/nscd/nscd_conf.c
index 23c28ceef0..5ede3d1122 100644
--- a/nscd/nscd_conf.c
+++ b/nscd/nscd_conf.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998, 2000, 2003 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
 
@@ -55,6 +55,9 @@ nscd_parse_file (const char *fname, struct database dbs[lastdb])
   if (fp == NULL)
     return -1;
 
+  /* The stream is not used by more than one thread.  */
+  (void) __fsetlocking (fp, FSETLOCKING_BYCALLER);
+
   line = NULL;
   len = 0;
 
@@ -166,10 +169,7 @@ nscd_parse_file (const char *fname, struct database dbs[lastdb])
 	    dbg_log ("server %s is not supported\n", arg1);
 	}
       else if (strcmp (entry, "logfile") == 0)
-	{
-	  if (!set_logfile (arg1))
-	    dbg_log (_("Could not create log file \"%s\""), arg1);
-	}
+	set_logfile (arg1);
       else if (strcmp (entry, "debug-level") == 0)
 	{
 	  int level = atoi (arg1);
@@ -204,7 +204,7 @@ nscd_parse_file (const char *fname, struct database dbs[lastdb])
       else
 	dbg_log (_("Unknown option: %s %s %s"), entry, arg1, arg2);
     }
-  while (!feof (fp));
+  while (!feof_unlocked (fp));
 
   /* Free the buffer.  */
   free (line);