zsh-workers
 help / color / mirror / code / Atom feed
* GNU nohup oddness
@ 2002-12-06  0:30 Clint Adams
  2002-12-06 10:14 ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Clint Adams @ 2002-12-06  0:30 UTC (permalink / raw)
  To: zsh-workers; +Cc: phil

It seems that GNU nohup fails to work if one does the following from
zsh (assuming standard options)

nohup ./zshscript &
<Ctrl-D>
<Ctrl-D>

This happens both with and without Philippe Troin's patches, but does
not happen if either the login shell or the #! shell is not zsh.

Does anyone know what's going on here?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GNU nohup oddness
  2002-12-06  0:30 GNU nohup oddness Clint Adams
@ 2002-12-06 10:14 ` Bart Schaefer
  2002-12-07 15:24   ` Clint Adams
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2002-12-06 10:14 UTC (permalink / raw)
  To: Clint Adams, zsh-workers; +Cc: phil

On Dec 5,  7:30pm, Clint Adams wrote:
}
} nohup ./zshscript &
} <Ctrl-D>
} <Ctrl-D>
} 
} Does anyone know what's going on here?

The problem seems to be a combination of three things:

(1) The HUP option is set by default.
(2) When HUP is set, zsh _explicitly_ sends SIGHUP to process group
    in its job table on exit, rather than rely on the tty driver to
    do it when the tty is hung up.
(3) In Src/init.c:init_signals(), zsh explicitly installs a SIGHUP
    handler, even in non-interactive shells.  It has done so for a
    very long time -- as far back as recorded in my CVS of 3.0.x,
    which means prior to 27-Jun-97.

That last one is the real culprit, because it means that jobs started
as part of the script inherit the SIG_DFL handler from the #! zsh,
rather than inheriting SIG_IGN from the nohup great-grandparent (it's
"great-" because `nohup' runs `nice' as the grandparent).  So even if
the script does `setopt nohup', the top-level shell's process-group
kill will hit all the children of the script.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GNU nohup oddness
  2002-12-06 10:14 ` Bart Schaefer
@ 2002-12-07 15:24   ` Clint Adams
  2002-12-07 17:43     ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Clint Adams @ 2002-12-07 15:24 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers, phil, 171716

> (3) In Src/init.c:init_signals(), zsh explicitly installs a SIGHUP
>     handler, even in non-interactive shells.  It has done so for a
>     very long time -- as far back as recorded in my CVS of 3.0.x,
>     which means prior to 27-Jun-97.

So is this the right thing to do?

Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.29
diff -u -r1.29 init.c
--- Src/init.c	13 Nov 2002 10:24:24 -0000	1.29
+++ Src/init.c	7 Dec 2002 15:22:23 -0000
@@ -897,13 +897,13 @@
     signal_ignore(SIGQUIT);
 #endif
 
-    install_handler(SIGHUP);
     install_handler(SIGCHLD);
 #ifdef SIGWINCH
     install_handler(SIGWINCH);
 #endif
     if (interact) {
 	install_handler(SIGALRM);
+	install_handler(SIGHUP);
 	signal_ignore(SIGTERM);
     }
     if (jobbing) {


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GNU nohup oddness
  2002-12-07 15:24   ` Clint Adams
@ 2002-12-07 17:43     ` Bart Schaefer
  2002-12-09 18:00       ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2002-12-07 17:43 UTC (permalink / raw)
  To: zsh-workers; +Cc: 171716, phil

On Dec 7, 10:24am, Clint Adams wrote:
} Subject: Re: GNU nohup oddness
}
} > (3) In Src/init.c:init_signals(), zsh explicitly installs a SIGHUP
} >     handler, even in non-interactive shells.  It has done so for a
} >     very long time -- as far back as recorded in my CVS of 3.0.x,
} >     which means prior to 27-Jun-97.
} 
} So is this the right thing to do?

[Patch moves install_handler(SIGHUP) call to `if (interact)' block]

I'm not certain.  Probably more correct would be something like:

@@ -870,7 +897,8 @@
     signal_ignore(SIGQUIT);
 #endif
 
-    install_handler(SIGHUP);
+    if (signal_ignore(SIGHUP) != SIG_IGN)
+	install_handler(SIGHUP);
     install_handler(SIGCHLD);
 #ifdef SIGWINCH
     install_handler(SIGWINCH);


Or maybe even:

@@ -870,7 +897,10 @@
     signal_ignore(SIGQUIT);
 #endif
 
-    install_handler(SIGHUP);
+    if (signal_ignore(SIGHUP) == SIG_IGN)
+	opts[HUP] = 0;
+    else
+	install_handler(SIGHUP);
     install_handler(SIGCHLD);
 #ifdef SIGWINCH
     install_handler(SIGWINCH);


Does anybody else have an opinion?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GNU nohup oddness
  2002-12-07 17:43     ` Bart Schaefer
@ 2002-12-09 18:00       ` Peter Stephenson
  2002-12-12  4:09         ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2002-12-09 18:00 UTC (permalink / raw)
  To: zsh-workers

"Bart Schaefer" wrote:
> @@ -870,7 +897,8 @@
>      signal_ignore(SIGQUIT);
>  #endif
>  
> -    install_handler(SIGHUP);
> +    if (signal_ignore(SIGHUP) != SIG_IGN)
> +	install_handler(SIGHUP);
>      install_handler(SIGCHLD);
>  #ifdef SIGWINCH
>      install_handler(SIGWINCH);

Seems to be logical --- follow the parent process.

Is there a place where also setting opts[HUP] to zero would change the
effect?

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GNU nohup oddness
  2002-12-09 18:00       ` Peter Stephenson
@ 2002-12-12  4:09         ` Bart Schaefer
  2002-12-12 10:39           ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2002-12-12  4:09 UTC (permalink / raw)
  To: Peter Stephenson, zsh-workers

On Dec 9,  6:00pm, Peter Stephenson wrote:
} Subject: Re: GNU nohup oddness
}
} "Bart Schaefer" wrote:
} > @@ -870,7 +897,8 @@
} >      signal_ignore(SIGQUIT);
} >  #endif
} >  
} > -    install_handler(SIGHUP);
} > +    if (signal_ignore(SIGHUP) != SIG_IGN)
} > +	install_handler(SIGHUP);
} >      install_handler(SIGCHLD);
} >  #ifdef SIGWINCH
} >      install_handler(SIGWINCH);
} 
} Seems to be logical --- follow the parent process.
} 
} Is there a place where also setting opts[HUP] to zero would change the
} effect?

With signal_ignore(SIGHUP) any jobs started by that zsh _probably_ will
also ignore HUP -- but without opts[HUP] = 0, zsh still kill()s all jobs
at exit.  So with the patch above, background jobs _may_ die when the
script exits, even if the nohup wrapper was used to start the script.

Conversely, if opts[HUP] = 0, then zsh won't kill() even if the script
later un-ignores HUP by installing a trap handler, so background jobs
started by the script will survive even if the script itself is HUP'd.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GNU nohup oddness
  2002-12-12  4:09         ` Bart Schaefer
@ 2002-12-12 10:39           ` Peter Stephenson
  2002-12-12 15:33             ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2002-12-12 10:39 UTC (permalink / raw)
  To: Zsh hackers list

"Bart Schaefer" wrote:
> With signal_ignore(SIGHUP) any jobs started by that zsh _probably_ will
> also ignore HUP -- but without opts[HUP] = 0, zsh still kill()s all jobs
> at exit.  So with the patch above, background jobs _may_ die when the
> script exits, even if the nohup wrapper was used to start the script.

But only if they explicitly arrange to handle HUP, right?  I would have
said this was marginally preferable, but I'm really just sticking my
finger in the air.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GNU nohup oddness
  2002-12-12 10:39           ` Peter Stephenson
@ 2002-12-12 15:33             ` Bart Schaefer
  0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2002-12-12 15:33 UTC (permalink / raw)
  To: Peter Stephenson, Zsh hackers list

On Dec 12, 10:39am, Peter Stephenson wrote:
} Subject: Re: GNU nohup oddness
}
} "Bart Schaefer" wrote:
} > With signal_ignore(SIGHUP) any jobs started by that zsh _probably_ will
} > also ignore HUP -- but without opts[HUP] = 0, zsh still kill()s all jobs
} > at exit.  So with the patch above, background jobs _may_ die when the
} > script exits, even if the nohup wrapper was used to start the script.
} 
} But only if they explicitly arrange to handle HUP, right?

Yes.  It also just occurred to me that they'll definitely die if the zsh
script explicitly installs a HUP trap (unless the job arranges to ignore).

} I would have said this was marginally preferable, but I'm really just
} sticking my finger in the air.

Me, too; I'm comfortable with making the minimal change to follow zsh's
parent, but as we're changing a behavior of many years' standing, it'd
be nice if we only had to change it once.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-12-12 15:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-06  0:30 GNU nohup oddness Clint Adams
2002-12-06 10:14 ` Bart Schaefer
2002-12-07 15:24   ` Clint Adams
2002-12-07 17:43     ` Bart Schaefer
2002-12-09 18:00       ` Peter Stephenson
2002-12-12  4:09         ` Bart Schaefer
2002-12-12 10:39           ` Peter Stephenson
2002-12-12 15:33             ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).