mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Petr Vandrovec <vandrove@vc.cvut.cz>
To: linux-kernel@vger.kernel.org
Subject: NPTL: Parent thread receives SIGHUP when child thread terminates?
Date: Thu, 21 Oct 2004 12:13:13 +0200	[thread overview]
Message-ID: <20041021101313.GA19246@vana.vc.cvut.cz> (raw)

Hello,
  one friend noticed that multithreaded programs (VMware...) behave erraticaly 
when started from rxvt or xterm with -e option.  We've traced it down to some 
strange SIGHUP delivery.

  When process is session leader, is it supposed to receive SIGHUP when child
thread terminates?  It did not receive SIGHUP under non-NPTL library, and IMHO
it was correct behavior.  Now all exiting threads cause SIGHUP to be delivered
to the parent, and parent (I'd say correctly) assumes that connection to the
program was broken and terminates.

  Probably disassociate_ctty(1) in do_exit() should not be invoked for all
tsk->signal->leader, but only for those with thread_group_empty() == 1, i.e.
when this process is really going away ?  Or only for thread group leader?

					Thanks,
						Petr Vandrovec




/* Build with:
gcc -W -Wall -O2 -o testhup testhup.c -lpthread -lutil

vana:~# ./testhup
Got SIGHUP!
vana:~# LD_ASSUME_KERNEL=2.4.1 ./testhup
vana:~#

*/

#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <fcntl.h>
#include <pty.h>
#include <stdlib.h>
#include <sys/wait.h>

static void sighup(int sig) {
	printf("Got SIGHUP!\n");
}

static void* child(void* arg) {
	return arg;
}

int main(void) {
	int master, slave;
	char name[100];

	openpty(&master, &slave, name, NULL, NULL);
	if (fork() == 0) {
		pthread_t pth;

		signal(SIGHUP, sighup);

		/* Become session leader. */
		if (setsid() == -1) {
			perror("SetSID");
			exit(1);
		}
		/* Assign controlling terminal. */
		if (open(name, O_RDWR) == -1) {
			perror("Open PTY");
			exit(2);
		}

		/* In reality code above is xterm/rxvt, code below is an
                 * innocent MT application execed by xterm/rxvt */

		/* Die with SIGHUP after child thread terminates. */
		pthread_create(&pth, NULL, child, NULL);
		pthread_join(pth, NULL);
		exit(3);
	} else {
		wait(NULL);
	}
	return 0;
}


             reply	other threads:[~2004-10-21 10:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-21 10:13 Petr Vandrovec [this message]
2004-10-21 23:10 ` Ulrich Drepper
2004-10-22 11:01 ` Roland McGrath

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=20041021101313.GA19246@vana.vc.cvut.cz \
    --to=vandrove@vc.cvut.cz \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®