[PATCH] nscd: don't fork twice
Florian Weimer
fweimer@redhat.com
Mon Jan 14 14:46:00 GMT 2013
On 01/14/2013 11:53 AM, Andreas Schwab wrote:
> There is no need to fork twice when daemonizing.
>
> Andreas.
>
> * nscd/nscd.c (main): Don't fork again after closing files.
>
> diff --git a/nscd/nscd.c b/nscd/nscd.c
> index 26cf3c2..ffbc6f8 100644
> --- a/nscd/nscd.c
> +++ b/nscd/nscd.c
> @@ -252,15 +252,6 @@ main (int argc, char **argv)
> for (i = min_close_fd; i < getdtablesize (); i++)
> close (i);
>
> - if (run_mode == RUN_DAEMONIZE)
> - {
> - pid = fork ();
> - if (pid == -1)
> - error (EXIT_FAILURE, errno, _("cannot fork"));
> - if (pid != 0)
> - exit (0);
> - }
> -
> setsid ();
Could you add error checking to the setsid call? I checked and it seems
that a single fork is enough on Linux. The double-fork idiom is
supposed to be a SYSV-ism, but perhaps it's required on FreeBSD or Hurd,
too.
--
Florian Weimer / Red Hat Product Security Team
More information about the Libc-alpha
mailing list