Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh INTON / INTOFF audit and cleanup.



details:   https://anonhg.NetBSD.org/src/rev/911f041b5bf0
branches:  trunk
changeset: 448783:911f041b5bf0
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Feb 09 03:35:55 2019 +0000

description:
INTON / INTOFF audit and cleanup.

No visible differences expected - there is a remote chance that
some internal lossage may no longer occur in interactive shells
that receive SIGINT (untrapped) at inopportune times, but you would
have had to have been very unlucky to have ever suffered from that.

diffstat:

 bin/sh/eval.c     |  18 ++++++++----------
 bin/sh/histedit.c |  24 +++++++++++++++++++-----
 bin/sh/input.c    |   8 +++++---
 bin/sh/jobs.c     |   7 +++----
 bin/sh/memalloc.c |  10 ++++++++--
 bin/sh/redir.c    |   5 ++---
 bin/sh/var.c      |  39 ++++++++++++++++++++++++++-------------
 7 files changed, 71 insertions(+), 40 deletions(-)

diffs (truncated from 455 to 300 lines):

diff -r e972a069a974 -r 911f041b5bf0 bin/sh/eval.c
--- a/bin/sh/eval.c     Sat Feb 09 03:33:59 2019 +0000
+++ b/bin/sh/eval.c     Sat Feb 09 03:35:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.171 2019/02/04 11:16:41 kre Exp $   */
+/*     $NetBSD: eval.c,v 1.172 2019/02/09 03:35:55 kre Exp $   */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c     8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.171 2019/02/04 11:16:41 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.172 2019/02/09 03:35:55 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -545,19 +545,19 @@
                outxc('\n');
                flushout(outx);
        }
+       INTOFF;
        if ((!backgnd && flags & EV_EXIT && !have_traps()) ||
            forkshell(jp = makejob(n, 1), n, backgnd?FORK_BG:FORK_FG) == 0) {
-               INTON;
                if (backgnd)
                        flags &=~ EV_TESTED;
                redirect(n->nredir.redirect, REDIR_KEEP);
+               INTON;
                evaltree(n->nredir.n, flags | EV_EXIT);   /* never returns */
-       } else if (!backgnd) {
-               INTOFF;
+       } else if (backgnd)
+               exitstatus = 0;
+       else
                exitstatus = waitforjob(jp);
-               INTON;
-       } else
-               exitstatus = 0;
+       INTON;
 
        if (!backgnd && xflag && n->nredir.redirect) {
                outxstr(expandstr(ps4val(), line_number));
@@ -714,11 +714,9 @@
                close(pip[1]);
        }
        if (n->npipe.backgnd == 0) {
-               INTOFF;
                exitstatus = waitforjob(jp);
                CTRACE(DBG_EVAL, ("evalpipe:  job done exit status %d\n",
                    exitstatus));
-               INTON;
        } else
                exitstatus = 0;
        INTON;
diff -r e972a069a974 -r 911f041b5bf0 bin/sh/histedit.c
--- a/bin/sh/histedit.c Sat Feb 09 03:33:59 2019 +0000
+++ b/bin/sh/histedit.c Sat Feb 09 03:35:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: histedit.c,v 1.53 2018/07/13 22:43:44 kre Exp $        */
+/*     $NetBSD: histedit.c,v 1.54 2019/02/09 03:35:55 kre Exp $        */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: histedit.c,v 1.53 2018/07/13 22:43:44 kre Exp $");
+__RCSID("$NetBSD: histedit.c,v 1.54 2019/02/09 03:35:55 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -153,6 +153,7 @@
                        INTON;
                }
                if (el) {
+                       INTOFF;
                        if (Vflag)
                                el_set(el, EL_EDITOR, "vi");
                        else if (Eflag)
@@ -160,6 +161,7 @@
                        el_set(el, EL_BIND, "^I", 
                            tabcomplete ? "rl-complete" : "ed-insert", NULL);
                        el_source(el, lookupvar("EDITRC"));
+                       INTON;
                }
        } else {
                INTOFF;
@@ -190,17 +192,21 @@
 
        mbtowc(&wc, NULL, 1);           /* state init */
 
+       INTOFF;
        if (mbtowc(&wc, lit_ch, strlen(lit_ch)) <= 0)
                el_set(el, EL_PROMPT, getprompt);
        else
                el_set(el, EL_PROMPT_ESC, getprompt, (int)wc);
+       INTON;
 }
 
 void
 set_editrc(const char *fname)
 {
+       INTOFF;
        if (iflag && editing && el)
                el_source(el, fname);
+       INTON;
 }
 
 void
@@ -213,19 +219,23 @@
                if (hs == NULL || *hs == '\0' || *hs == '-' ||
                   (histsize = number(hs)) < 0)
                        histsize = 100;
+               INTOFF;
                history(hist, &he, H_SETSIZE, histsize);
                history(hist, &he, H_SETUNIQUE, 1);
+               INTON;
        }
 }
 
 void
 setterm(const char *term)
 {
+       INTOFF;
        if (el != NULL && term != NULL)
                if (el_set(el, EL_TERMINAL, term) != 0) {
                        outfmt(out2, "sh: Can't set terminal type %s\n", term);
                        outfmt(out2, "sh: Using dumb terminal settings.\n");
                }
+       INTON;
 }
 
 int
@@ -236,11 +246,14 @@
                return 1;
        }
        if (el != NULL) {
+               INTOFF;
                if (el_source(el, argv[1])) {
+                       INTON;
                        out2str("inputrc: failed\n");
                        return 1;
-               } else
-                       return 0;
+               }
+               INTON;
+               return 0;
        } else {
                out2str("sh: inputrc ignored, not editing\n");
                return 1;
@@ -468,9 +481,10 @@
                editcmd = stalloc(cmdlen);
                snprintf(editcmd, cmdlen, "%s %s", editor, editfile);
                evalstring(editcmd, 0); /* XXX - should use no JC command */
-               INTON;
+               stunalloc(editcmd);
                readcmdfile(editfile);  /* XXX - should read back - quick tst */
                unlink(editfile);
+               INTON;
        }
 
        if (lflg == 0 && active > 0)
diff -r e972a069a974 -r 911f041b5bf0 bin/sh/input.c
--- a/bin/sh/input.c    Sat Feb 09 03:33:59 2019 +0000
+++ b/bin/sh/input.c    Sat Feb 09 03:35:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: input.c,v 1.69 2019/01/16 07:14:17 kre Exp $   */
+/*     $NetBSD: input.c,v 1.70 2019/02/09 03:35:55 kre Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c    8.3 (Berkeley) 6/9/95";
 #else
-__RCSID("$NetBSD: input.c,v 1.69 2019/01/16 07:14:17 kre Exp $");
+__RCSID("$NetBSD: input.c,v 1.70 2019/02/09 03:35:55 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -532,6 +532,7 @@
 {
        VTRACE(DBG_INPUT, ("setinputfd(%d, %spush)\n", fd, push?"":"no"));
 
+       INTOFF;
        register_sh_fd(fd, input_fd_swap);
        (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
        if (push)
@@ -543,6 +544,7 @@
                parsefile->buf = ckmalloc(BUFSIZ);
        parselleft = parsenleft = 0;
        plinno = 1;
+       INTON;
 
        CTRACE(DBG_INPUT, ("setinputfd(%d, %spush) done; plinno=1\n", fd,
            push ? "" : "no"));
@@ -563,11 +565,11 @@
        parsenextc = string;
        parselleft = parsenleft = strlen(string);
        plinno = line1;
+       INTON;
 
        CTRACE(DBG_INPUT,
            ("setinputstring(\"%.20s%s\" (%d), %spush, @ %d)\n", string,
            (parsenleft > 20 ? "..." : ""), parsenleft, push?"":"no", line1));
-       INTON;
 }
 
 
diff -r e972a069a974 -r 911f041b5bf0 bin/sh/jobs.c
--- a/bin/sh/jobs.c     Sat Feb 09 03:33:59 2019 +0000
+++ b/bin/sh/jobs.c     Sat Feb 09 03:35:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: jobs.c,v 1.103 2018/12/03 02:38:30 kre Exp $   */
+/*     $NetBSD: jobs.c,v 1.104 2019/02/09 03:35:55 kre Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)jobs.c     8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: jobs.c,v 1.103 2018/12/03 02:38:30 kre Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.104 2019/02/09 03:35:55 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -277,8 +277,8 @@
                error("Cannot set tty process group (%s) at %d",
                    strerror(errno), __LINE__);
        }
+       INTOFF;
        restartjob(jp);
-       INTOFF;
        status = waitforjob(jp);
        INTON;
        return status;
@@ -1110,7 +1110,6 @@
        case -1:
                serrno = errno;
                VTRACE(DBG_JOBS, ("Fork failed, errno=%d\n", serrno));
-               INTON;
                error("Cannot fork (%s)", strerror(serrno));
                break;
        case 0:
diff -r e972a069a974 -r 911f041b5bf0 bin/sh/memalloc.c
--- a/bin/sh/memalloc.c Sat Feb 09 03:33:59 2019 +0000
+++ b/bin/sh/memalloc.c Sat Feb 09 03:35:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: memalloc.c,v 1.32 2018/08/22 20:08:54 kre Exp $        */
+/*     $NetBSD: memalloc.c,v 1.33 2019/02/09 03:35:55 kre Exp $        */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: memalloc.c,v 1.32 2018/08/22 20:08:54 kre Exp $");
+__RCSID("$NetBSD: memalloc.c,v 1.33 2019/02/09 03:35:55 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -141,9 +141,11 @@
                stackp = sp;
                INTON;
        }
+       INTOFF;
        p = stacknxt;
        stacknxt += nbytes;
        stacknleft -= nbytes;
+       INTON;
        return p;
 }
 
@@ -176,8 +178,10 @@
 void
 popstackmark(struct stackmark *mark)
 {
+       INTOFF;
        markp = mark->marknext;         /* delete mark from the list */
        rststackmark(mark);             /* and reset stack */
+       INTON;
 }
 
 /* reset the shell stack to its state recorded in the stack mark */
@@ -260,8 +264,10 @@
 grabstackblock(int len)
 {
        len = SHELL_ALIGN(len);
+       INTOFF;
        stacknxt += len;
        stacknleft -= len;
+       INTON;
 }
 
 /*



Home | Main Index | Thread Index | Old Index