From d24ab95469fd5514e308fcb4926a218abe492082 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Thu, 9 Jun 2022 13:30:55 -0700 Subject: 50351: "functions -c" can set signal traps --- Src/builtin.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'Src') diff --git a/Src/builtin.c b/Src/builtin.c index 1cef7cce8..7f00d9d29 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3274,6 +3274,7 @@ bin_functions(char *name, char **argv, Options ops, int func) if (OPT_ISSET(ops,'c')) { Shfunc newsh; + char *s = argv[1]; if (!*argv || !argv[1] || argv[2]) { zwarnnam(name, "-c: requires two arguments"); return 1; @@ -3305,7 +3306,21 @@ bin_functions(char *name, char **argv, Options ops, int func) newsh->redir->nref++; if (shf->sticky) newsh->sticky = sticky_emulation_dup(sticky, 0); - shfunctab->addnode(shfunctab, ztrdup(argv[1]), &newsh->node); + /* is newsh a signal trap? (adapted from exec.c) */ + if (!strncmp(s, "TRAP", 4)) { + int signum = getsignum(s + 4); + if (signum != -1) { + if (settrap(signum, NULL, ZSIG_FUNC)) { + freeeprog(newsh->funcdef); + dircache_set(&newsh->filename, NULL); + zfree(newsh, sizeof(*newsh)); + return 1; + } + /* Remove any old node explicitly */ + removetrapnode(signum); + } + } + shfunctab->addnode(shfunctab, ztrdup(s), &newsh->node); return 0; } -- cgit 1.4.1