All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Karl Pickett <kjp@ci.uchicago.edu>
Cc: linux-kernel@vger.kernel.org, kay.sievers@vrfy.org,
	Lennart Poettering <lennart@poettering.net>
Subject: Re: Is prctl(PR_SET_CHILD_SUBREAPER) going to break my code which checks getppid == 1?
Date: Fri, 30 Mar 2012 14:44:26 +0200	[thread overview]
Message-ID: <20120330124426.GA13811@redhat.com> (raw)
In-Reply-To: <46799FA3-D575-4A2D-8DEB-CE5149A4110D@ci.uchicago.edu>

On 03/29, Karl Pickett wrote:
>
> Re: http://thread.gmane.org/gmane.linux.kernel/1236479
>
> I'm wondering if this is going to break code that checks getppid() == 1?
>
> I have a TCL/TK GUI app that spawns ssh.  I want the ssh to die
> immediately if the GUI process crashes, so ssh is launched with a wrapper
> c program that does:
>
>    prctl(PR_SET_PDEATHSIG, SIGHUP);
>    if (getppid() == 1) /* parent died already? */
>        return 0;

Yes, this won't work if the parent of this app does PR_SET_CHILD_SUBREAPER.

> So what is getppid() going to return for some user using this new
> 'session manager reaper'?

The new parent's pid ;)

Perhaps you can do something like

	ppid_for_child = getpid();

	if (!fork()) {
		// Child
		prctl(PR_SET_PDEATHSIG);
		if (getppid() != ppid_for_child)
			return;
		...
	}

Just in case, I do not know how PR_SET_CHILD_SUBREAPER will be really used.
I do not know if systemd will run the "normal" user applications under
PR_SET_CHILD_SUBREAPER. Probably yes, but this is the question to Kay.

Oleg.


  reply	other threads:[~2012-03-30 13:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-29 20:12 Is prctl(PR_SET_CHILD_SUBREAPER) going to break my code which checks getppid == 1? Karl Pickett
2012-03-30 12:44 ` Oleg Nesterov [this message]
2012-03-30 13:17   ` Karl Pickett
2012-03-30 13:26     ` Karl Pickett
2012-03-30 17:14     ` Oleg Nesterov

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=20120330124426.GA13811@redhat.com \
    --to=oleg@redhat.com \
    --cc=kay.sievers@vrfy.org \
    --cc=kjp@ci.uchicago.edu \
    --cc=lennart@poettering.net \
    --cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.