zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: "functions -c" and TRAPxxx
Date: Wed, 8 Jun 2022 20:24:15 -0700	[thread overview]
Message-ID: <CAH+w=7ZJJv4KEXdW=2Pgqk+1YxjrmwX-HA5EBo00ZPgfM6N=gg@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7asDd+fxxcqg9c=DcKfo1gKSnuyL3PskX7Fdf192Hfwdg@mail.gmail.com>

On Tue, Jun 7, 2022 at 7:57 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> I know most of what's going on there, but "functions -c" is creatin
> an alternate name, and there is also the failure case of settrap()
> returning nonzero to handle.

The following works for the case of settrap() succeeding, but I'm not
sure how to force settrap() to fail.

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;
     }


  reply	other threads:[~2022-06-09  3:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07  1:59 Bart Schaefer
2022-06-07  9:57 ` Peter Stephenson
2022-06-07 14:57   ` Bart Schaefer
2022-06-09  3:24     ` Bart Schaefer [this message]
2022-06-09  8:55       ` Peter Stephenson
2022-06-09 15:19         ` Bart Schaefer
2022-06-09 20:51           ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7ZJJv4KEXdW=2Pgqk+1YxjrmwX-HA5EBo00ZPgfM6N=gg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).