From 8690397f9b7a13d9d8bab471cee6bb25f855c212 Mon Sep 17 00:00:00 2001 From: cgf Date: Wed, 25 Oct 2000 03:54:50 +0000 Subject: [PATCH] * dcrt0.cc (do_exit): Don't bother looking for pgrp children to send SIGHUP if process has never created any children. * fork.cc (fork): Set flag indicating that there is another process with our process group. * spawn.cc (spawn_guts): Ditto. * pinfo.h (set_has_pgid_children): New methods for setting when process has children in its process group. * syscalls.cc (setpgid): Clear has_gid_children if pgid changes. --- winsup/cygwin/ChangeLog | 11 +++++++++++ winsup/cygwin/dcrt0.cc | 4 ++-- winsup/cygwin/fork.cc | 2 ++ winsup/cygwin/pinfo.h | 11 ++++++++++- winsup/cygwin/spawn.cc | 1 + winsup/cygwin/syscalls.cc | 2 ++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index c82f601fa1..e6e824d556 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +Tue Oct 24 23:45:09 2000 Christopher Faylor + + * dcrt0.cc (do_exit): Don't bother looking for pgrp children to send + SIGHUP if process has never created any children. + * fork.cc (fork): Set flag indicating that there is another process + with our process group. + * spawn.cc (spawn_guts): Ditto. + * pinfo.h (set_has_pgid_children): New methods for setting when process + has children in its process group. + * syscalls.cc (setpgid): Clear has_gid_children if pgid changes. + Tue Oct 24 20:38:00 2000 Corinna Vinschen * ntdll.h: New file. diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index c23f1dbc01..8e6098b0e2 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -1024,7 +1024,7 @@ do_exit (int status) set_console_title (old_title); /* Kill orphaned children on group leader exit */ - if (myself->pid == myself->pgid) + if (myself->has_pgid_children && myself->pid == myself->pgid) { system_printf ("%d == pgrp %d, send SIG{HUP,CONT} to stopped children", myself->pid, myself->pgid); @@ -1041,7 +1041,7 @@ do_exit (int status) myself->pid, myself->sid); if (tp->getsid () == myself->sid) - kill (-tp->getpgid (), SIGHUP); + kill_pgrp (tp->getpgid (), SIGHUP); } tty_terminate (); diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index a05279d9c3..c304d34b04 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -598,6 +598,8 @@ fork () void *esp; __asm ("movl %%esp,%0": "=r" (esp)); + myself->set_has_pgid_children (); + child_info_fork ch; int res = setjmp (ch.jmp); diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h index 067ef61043..e9d54cf657 100644 --- a/winsup/cygwin/pinfo.h +++ b/winsup/cygwin/pinfo.h @@ -70,6 +70,7 @@ public: pid_t sid; /* Session ID */ int ctty; /* Control tty */ mode_t umask; + bool has_pgid_children;/* True if we've forked or spawned children with our GID. */ char username[MAX_USER_NAME]; /* user's name */ /* Extendend user information. @@ -106,6 +107,14 @@ public: void exit (UINT n, bool norecord = 0) __attribute__ ((noreturn, regparm(2))); + inline void set_has_pgid_children () + { + if (pgid == pid) + has_pgid_children = 1; + } + + inline void set_has_pgid_children (bool val) {has_pgid_children = val;} + inline struct sigaction& getsig (int sig) { return thread2signal ? thread2signal->sigs[sig] : sigs[sig]; @@ -158,7 +167,7 @@ public: if (destroy && procinfo) release (); } - + _pinfo *operator -> () const {return procinfo;} int operator == (pinfo *x) const {return x->procinfo == procinfo;} int operator == (pinfo &x) const {return x.procinfo == procinfo;} diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 3afb45d38e..2e0490db7b 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -678,6 +678,7 @@ skip_arg_parsing: } else { + myself->set_has_pgid_children (); ProtectHandle (pi.hThread); pinfo child (cygpid, 1); if (!child) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index ea360a0c15..b6970ff71f 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1711,6 +1711,8 @@ setpgid (pid_t pid, pid_t pgid) if (p == myself || p->ppid == myself->pid) { p->pgid = pgid; + if (p->pid != p->pgid) + p->set_has_pgid_children (0); res = 0; } else -- 2.11.0