This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] nscd: don't fork twice


Florian Weimer <fweimer@redhat.com> writes:

> Could you add error checking to the setsid call?

Which failure modes are possible, apart from the fact that it will
always fail in foreground mode?

Andreas.

	* nscd/nscd.c (main): Don't fork again after closing files.  Don't
	call setsid in foreground mode.

diff --git a/nscd/nscd.c b/nscd/nscd.c
index 26cf3c2..4e527ff 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -252,16 +252,10 @@ main (int argc, char **argv)
 	for (i = min_close_fd; i < getdtablesize (); i++)
 	  close (i);
 
+      /* In foreground mode this would always fail, we assume our caller
+	 has already established a new session.  */
       if (run_mode == RUN_DAEMONIZE)
-	{
-	  pid = fork ();
-	  if (pid == -1)
-	    error (EXIT_FAILURE, errno, _("cannot fork"));
-	  if (pid != 0)
-	    exit (0);
-	}
-
-      setsid ();
+	setsid ();
 
       if (chdir ("/") != 0)
 	error (EXIT_FAILURE, errno,
-- 
1.8.1

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]