public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: Phillip Susi <psusi@ubuntu.com>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH] setsid: don't fork
Date: Tue, 19 Nov 2013 14:24:12 +0100	[thread overview]
Message-ID: <20131119132412.GG5572@x2.net.home> (raw)
In-Reply-To: <1384456993-3721-1-git-send-email-psusi@ubuntu.com>

On Thu, Nov 14, 2013 at 02:23:13PM -0500, Phillip Susi wrote:
> 2.24 added a switch to setsid to wait for the child to exit
> and return its exit status.  I believe this was the wrong way
> to fix the underlying bug since the behavior of the program
> still differs depending on whether it is run as the group leader
> or not, and requires a switch to get the correct behavior.

Yep, it was our goal to not change the default behaviour that exists
for years.

> Instead of this --wait switch, just make sure the parent
> process is the one that execs the new program rather than
> the child process.

>  		case 0:
>  			/* child */
> +			sleep(5);

 pause() ?

>  			break;
>  		default:
>  			/* parent */
> -			if (!status)
> -				return EXIT_SUCCESS;
> -			if (wait(&status) != pid)
> -				err(EXIT_FAILURE, "wait");
> -			if (WIFEXITED(status))
> -				return WEXITSTATUS(status);
> -			err(status, _("child %d did not exit normally"), pid);
> +			if (setpgid(pid, 0) == -1)
> +				err(EXIT_FAILURE, _("setpgid failed"));
> +			if (setpgid(0, pid) == -1)
> +				err(EXIT_FAILURE, _("setpgid failed"));
> +
>  		}
>  	}
>  	if (setsid() < 0)
>  		/* cannot happen */
>  		err(EXIT_FAILURE, _("setsid failed"));
> -
> +	if (pid)
> +		kill(pid, SIGTERM);

It does not seem too elegant :-) If you really want to change the
default behaviour than it would be better to make --wait default
and exec() in child, then you don't need setpgid(), kill() and
sleep/pause() at all.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

  reply	other threads:[~2013-11-19 13:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-14 19:23 [PATCH] setsid: don't fork Phillip Susi
2013-11-19 13:24 ` Karel Zak [this message]
2013-11-19 15:01   ` Phillip Susi
2013-11-19 18:05     ` Karel Zak
2013-11-19 19:49       ` Phillip Susi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131119132412.GG5572@x2.net.home \
    --to=kzak@redhat.com \
    --cc=psusi@ubuntu.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox