[PATCH] NSCD deadlock with debug logfile

Thorsten Kukuk kukuk@suse.de
Sat Feb 14 12:36:00 GMT 2004


Hi,

If you enable the log file of nscd, nscd will hang forever with
kernel 2.6 (Don't know why only with 2.6, but it is a nscd bug).

The reason is, that we open the logfile and than make two forks
and close some file handles.

I moved the open after the forks and do it only if nscd is running
in background, so that nscd -d works again, too.

Patch attached.

  Thorsten

-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk@suse.de
SuSE Linux AG        Maxfeldstr. 5                 D-90409 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B
-------------- next part --------------
2004-02-14  Thorsten Kukuk  <kukuk@suse.de>

	* nscd/dbg_log.c (set_logfile): Only save name of logfile,
	don't open it.
	(init_logfile): New function, open logfile if requested.
	* nscd/dbg_log.h: Adjust protoype for set_logfile, add init_logfile.
	* nscd/nscd.c (main): Call init_logfile after forking in background.
	* nscd/nscd_conf.c (nscd_parse_file): Adjust for new set_logfile.

--- nscd/dbg_log.c	6 Jul 2001 04:55:37 -0000	1.5
+++ nscd/dbg_log.c	14 Feb 2004 07:03:02 -0000
@@ -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
--- nscd/dbg_log.h	6 Jul 2001 04:55:37 -0000	1.5
+++ nscd/dbg_log.h	14 Feb 2004 07:03:02 -0000
@@ -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 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
--- nscd/nscd.c	1 Jan 2004 20:42:00 -0000	1.29
+++ nscd/nscd.c	14 Feb 2004 07:03:02 -0000
@@ -223,6 +223,9 @@
       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);
--- nscd/nscd_conf.c	4 May 2003 06:58:01 -0000	1.10
+++ nscd/nscd_conf.c	14 Feb 2004 07:03:02 -0000
@@ -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.
 
@@ -166,10 +166,7 @@
 	    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);


More information about the Libc-alpha mailing list