[SSSD] [PATCH] exit original process after sssd is initialized
Simo Sorce
simo at redhat.com
Fri Nov 2 18:30:30 UTC 2012
On Thu, 2012-11-01 at 17:36 +0100, Pavel Březina wrote:
> +void become_daemon(bool Fork, pid_t *ppid)
> {
> - int ret;
> + pid_t pid;
> + int status;
> + int ret;
>
> - if (Fork) {
> - if (fork()) {
> - _exit(0);
> - }
> - }
> + if (Fork) {
> + pid = fork();
> + if (pid != 0) {
> + *ppid = 0;
Why care about ppid at all here? you never return from this branch as
you call _exit();
> + /* Terminate parent process on demand so we can hold
> systemd
> + * or initd from starting next service until sssd in
> initialized.
> + * We use signals directly here because we don't have a
> tevent
> + * context yet. */
> + CatchSignal(SIGTERM, deamon_parent_sigterm);
> +
> + /* or exit when sssd monitor is terminated */
> + waitpid(pid, &status, 0);
> +
> + /* return error if we didn't exited normally */
> + ret = 1;
> +
> + if (WIFEXITED(status)) {
> + /* but return our exit code otherwise */
> + ret = WEXITSTATUS(status);
> + }
> +
> + _exit(ret);
> + }
> + }
> +
> + *ppid = getppid();
What's the point of making become_daemon() return a ppid if you assign
it unconditionally after the fork() ?
Isn't it the same than calling getppid() in the caller function ?
What am I missing ?
> /* detach from the terminal */
> - setsid();
> + setsid();
>
> /* chdir to / to be sure we're not on a remote filesystem */
> errno = 0;
> @@ -93,8 +123,8 @@ void become_daemon(bool Fork)
> return;
> }
This ^^ remains indented odly.
> - /* Close fd's 0,1,2. Needed if started by rsh */
> - close_low_fds();
> + /* Close fd's 0,1,2. Needed if started by rsh */
> + close_low_fds();
> }
Simo.
--
Simo Sorce * Red Hat, Inc * New York
More information about the sssd-devel
mailing list