2015-04-29 10:53 GMT-03:00 Paulo César Pereira de Andrade
<paulo.cesar.pereira.de.andr...@gmail.com>:
> This is a test case from an user:
>
> ---8<---
> $ cd /tmp/alan
> $ cat tst.ksh
> #!/bin/ksh
> D=$(date)
> echo $D > /tmp/alan/tst.dat
>
> $ rm tst.dat
>
> $ (ksh /tmp/alan/tst.ksh &)
> [1]    21468
> $ ls
> tst.ksh
> [1] +  Done                    (ksh /tmp/alan/tst.ksh &)
> ---8<---
>
> To reproduce the problem, do not "exec ksh", or run
> ksh from another shell, or from a graphics terminal.
>
> To test, have ksh as login shell, and ssh localhost,
> or login in a virtual terminal.
>
> The problem, from my understanding is that SIGHUP
> is not blocked in this condition, then it forks[1] due to
> "( )" and again, from fork[1] into fork[2] due to "&".
>
> What happens is that fork[2] receives a SIGHUP and
> exists immediately.
>
> On older ksh this problem did not happen, as older
> ksh did a single fork. A simple patch to have the same
> behavior of working ksh (ksh-20100621) for the non
> working (ksh-20120801) is:
>
> ---8<---
> diff -up ksh-20120801/src/cmd/ksh93/sh/xec.c.orig
> ksh-20120801/src/cmd/ksh93/sh/xec.c
> --- ksh-20120801/src/cmd/ksh93/sh/xec.c.orig    2015-04-28
> 16:55:25.521818636 -0300
> +++ ksh-20120801/src/cmd/ksh93/sh/xec.c    2015-04-28 16:56:34.037753565 -0300
> @@ -2059,16 +2059,20 @@ int sh_exec(register const Shnode_t *t,
>              }
>              else if(((type=t->par.partre->tre.tretyp)&FAMP) &&
> ((type&COMMSK)==TFORK))
>              {
> +#if 0
>                  pid_t    pid;
>                  sfsync(NIL(Sfio_t*));
>                  while((pid=fork())< 0)
>                      _sh_fork(shp,pid,0,0);
>                  if(pid==0)
>                  {
> +#endif
>                      sh_exec(t->par.partre,flags);
> +#if 0
>                      shp->st.trapcom[0]=0;
>                      sh_done(shp,0);
>                  }
> +#endif
>              }
>              else
>                  sh_subshell(shp,t->par.partre,flags,0);
> ---8<---
>
> But, besides making it basically identical to older
> ksh, there must be a reason for the double fork, so,
> maybe the better approach is to make sure in this
> condition, SIGHUP is blocked?



> Another issue I noticed is that, if changing the command
> from
> (ksh /tmp/alan/tst.ksh &)
> to
> (ksh /tmp/alan/tst.ksh)&
>
> it will be unstable, and crash frequently if running the
> test, that will still fail, a few times.

Please ignore the comments about "( cmd ) &" instability.
It should have been a side effect of the way I was running
the tests, and, if written this way, it works, *but* the problem
is the behavior change of "( cmd & )" that does not work
if ksh is the login shell, and there is no exec, etc, i.e.
SHLVL == 1.

Thanks,
Paulo
_______________________________________________
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to