On Thu, Nov 22, 2007 at 02:59:34PM +0100, Dr. Werner Fink wrote:
>
> It looks like the ksh has a problem within signal handling
> of SIGTTIN, SIGTTOU, and SIGTSTP:
>
> /suse/werner> PATH=/usr/local/bin:/usr/bin:/bin:. ksh
> [EMAIL PROTECTED]:/suse/werner> echo | les
> ksh: les: not found [No such file or directory]
> [1]+ Stopped PATH=/usr/local/bin:/usr/bin:/bin:. ksh
>
Just a patch I suggest. With this one the signal handler for
SIGTTIN, SIGTTOU, and SIGTSTP will be set back in case of
a failed or not found command.
Remaining problem I've found
/suse/werner> ksh
[EMAIL PROTECTED]:/suse/werner> echo | less
[EMAIL PROTECTED]:/suse/werner> ^Z
[EMAIL PROTECTED]:/suse/werner> ^D
[1] + 14722 Suspended ksh
in other words there is an other place where SIGTSTP
will be currently overwritten with SIG_DFL.
The second attachment change the behavior for SIGINT of an
non-interactive shell to avoid exiting ksh waiting on the
execution of a command as already mentione, see subject
`SIGINT not ignored during running job'.
Btw: https://mailman.research.att.com/mailman/listinfo/ast-developers/
is not reachable.
Some comments or feedback?
Werner
--
Dr. Werner Fink <[EMAIL PROTECTED]>
SuSE LINUX Products GmbH, Maxfeldstrasse 5, Nuernberg, Germany
GF: Markus Rex, HRB 16746 (AG Nuernberg)
phone: +49-911-740-53-0, fax: +49-911-3206727, www.opensuse.org
------------------------------------------------------------------
"Having a smoking section in a restaurant is like having
a peeing section in a swimming pool." -- Edward Burr
--- src/cmd/ksh93/sh/jobs.c
+++ src/cmd/ksh93/sh/jobs.c 2007-11-22 14:28:03.000000000 +0000
@@ -229,7 +229,7 @@ int job_reap(register int sig)
flags |= WNOHANG;
}
pid = waitpid((pid_t)-1,&wstat,flags);
-
+#ifdef WCONTINUED
/*
* some systems (linux 2.6) may return EINVAL
* when there are no continued children
@@ -237,6 +237,7 @@ int job_reap(register int sig)
if (pid<0 && errno==EINVAL && (flags&WCONTINUED))
pid = waitpid((pid_t)-1,&wstat,flags&=~WCONTINUED);
+#endif
sh_sigcheck();
if(sig && pid<0 && errno==EINTR)
continue;
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2007-11-22 14:33:05.000000000 +0000
@@ -2755,6 +2755,7 @@ static pid_t sh_ntfork(const Shnode_t *t
{
signal(SIGTTIN,SIG_DFL);
signal(SIGTTOU,SIG_DFL);
+ signal(SIGTSTP,SIG_DFL);
}
#endif /* SIGTSTP */
#ifdef JOBS
@@ -2792,6 +2793,10 @@ static pid_t sh_ntfork(const Shnode_t *t
{
signal(SIGTTIN,SIG_IGN);
signal(SIGTTOU,SIG_IGN);
+ if(sh_isstate(SH_INTERACTIVE))
+ signal(SIGTSTP, SIG_IGN);
+ else
+ signal(SIGTSTP, sh_fault);
}
#endif /* SIGTSTP */
if(spawnpid>0)
@@ -2876,6 +2881,7 @@ static pid_t sh_ntfork(const Shnode_t *t
{
signal(SIGTTIN,SIG_DFL);
signal(SIGTTOU,SIG_DFL);
+ signal(SIGTSTP,SIG_DFL);
jobwasset++;
}
#endif /* SIGTSTP */
@@ -2916,12 +2922,24 @@ static pid_t sh_ntfork(const Shnode_t *t
argv[0] = argv[-1];
}
fail:
- if(spawnpid < 0) switch(errno=shp->path_err)
+ if(spawnpid < 0)
{
- case ENOENT:
- errormsg(SH_DICT,ERROR_system(ERROR_NOENT),e_found+4);
- default:
- errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec+4);
+ if(jobwasset)
+ {
+ signal(SIGTTIN,SIG_IGN);
+ signal(SIGTTOU,SIG_IGN);
+ if(sh_isstate(SH_INTERACTIVE))
+ signal(SIGTSTP, SIG_IGN);
+ else
+ signal(SIGTSTP, sh_fault);
+ }
+ switch(errno=shp->path_err)
+ {
+ case ENOENT:
+
errormsg(SH_DICT,ERROR_system(ERROR_NOENT),e_found+4);
+ default:
+
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec+4);
+ }
}
}
else
@@ -2934,6 +2952,10 @@ static pid_t sh_ntfork(const Shnode_t *t
{
signal(SIGTTIN,SIG_IGN);
signal(SIGTTOU,SIG_IGN);
+ if(sh_isstate(SH_INTERACTIVE))
+ signal(SIGTSTP, SIG_IGN);
+ else
+ signal(SIGTSTP, sh_fault);
}
#endif /* SIGTSTP */
if(sigwasset)
--- src/cmd/ksh93/edit/edit.c
+++ src/cmd/ksh93/edit/edit.c 2007-11-22 14:26:34.000000000 +0000
@@ -216,7 +216,7 @@ int tty_set(int fd, int action, struct t
if(fd >=0)
{
#ifdef future
- if(ep->e_savefd>=0 && compare(&ep->e_savetty,tty,sizeof(struct
termios)))
+ if(ep->e_savefd>=0 && memcmp(&ep->e_savetty,tty,sizeof(struct
termios)))
return(0);
#endif
while(tcsetattr(fd, action, tty) == SYSERR)
--- src/cmd/ksh93/sh/main.c
+++ src/cmd/ksh93/sh/main.c 2007-11-13 13:07:40.000000000 +0000
@@ -418,6 +418,7 @@ static void exfile(register Shell_t *shp
sh_onoption(SH_TRACKALL);
sh_offoption(SH_MONITOR);
}
+ sh_sigdone();
sh_offstate(SH_INTERACTIVE);
sh_offstate(SH_MONITOR);
sh_offstate(SH_HISTORY);
--- src/cmd/ksh93/sh/fault.c
+++ src/cmd/ksh93/sh/fault.c 2007-11-13 13:53:15.000000000 +0000
@@ -98,12 +98,27 @@ void sh_fault(register int sig)
if(flag&SH_SIGDONE)
{
void *ptr=0;
- if((flag&SH_SIGINTERACTIVE) &&
sh_isstate(SH_INTERACTIVE) && !sh_isstate(SH_FORKED) && ! shp->subshell)
+ switch (sig)
{
- /* check for TERM signal between fork/exec */
- if(sig==SIGTERM && job.in_critical)
- shp->trapnote |= SH_SIGTERM;
- return;
+ case SIGINT:
+ if(sh_isstate(SH_FORKED) ||
shp->subshell)
+ goto out;
+ if(!job.in_critical)
+ goto out;
+ return;
+ case SIGTERM:
+ if(sh_isstate(SH_FORKED) ||
shp->subshell)
+ break;
+ /* check for TERM signal between
fork/exec */
+ if(job.in_critical)
+ shp->trapnote |= SH_SIGTERM;
+ if((flag&SH_SIGINTERACTIVE) &&
sh_isstate(SH_INTERACTIVE))
+ return;
+ break;
+ case SIGQUIT:
+ return;
+ default:
+ break;
}
shp->lastsig = sig;
sigrelease(sig);
@@ -136,6 +151,7 @@ void sh_fault(register int sig)
return;
}
}
+out:
errno = 0;
if(pp->mode==SH_JMPCMD)
shp->lastsig = sig;
--- src/cmd/ksh93/data/signals.c
+++ src/cmd/ksh93/data/signals.c 2007-11-13 13:55:49.000000000 +0000
@@ -20,6 +20,7 @@
#include <ast.h>
#include "shtable.h"
#include "fault.h"
+#include "jobs.h"
#if defined(SIGCLD) && !defined(SIGCHLD)
# define SIGCHLD SIGCLD
@@ -95,9 +96,9 @@ const struct shtable2 shtab_signals[] =
"HUP", VAL(SIGHUP,SH_SIGDONE), S("Hangup"),
"ILL", VAL(SIGILL,SH_SIGDONE), S("Illegal
instruction"),
#ifdef JOBS
- "INT", VAL(SIGINT,SH_SIGINTERACTIVE), S("Interrupt"),
+ "INT", VAL(SIGINT,SH_SIGDONE|SH_SIGINTERACTIVE),
S("Interrupt"),
#else
- "INT", VAL(SIGINT,SH_SIGINTERACTIVE), "",
+ "INT", VAL(SIGINT,SH_SIGDONE|SH_SIGINTERACTIVE), "",
#endif /* JOBS */
#ifdef SIGIO
"IO", VAL(SIGIO,SH_SIGIGNORE), S("IO signal"),
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers