Source-Changes-HG archive

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

[src/trunk]: src/bin/sh When vforking ensure that the environment passed to e...



details:   https://anonhg.NetBSD.org/src/rev/74954d9c8c73
branches:  trunk
changeset: 486252:74954d9c8c73
user:      elric <elric%NetBSD.org@localhost>
date:      Wed May 17 07:37:12 2000 +0000

description:
When vforking ensure that the environment passed to exec is built before
vforking as a set of local variables which can be popped by the parent.

Addresses bin/10124.

diffstat:

 bin/sh/eval.c |  17 ++++++++++++-----
 bin/sh/var.c  |  14 +++++++-------
 bin/sh/var.h  |   4 ++--
 3 files changed, 21 insertions(+), 14 deletions(-)

diffs (134 lines):

diff -r 4e60c8ea81be -r 74954d9c8c73 bin/sh/eval.c
--- a/bin/sh/eval.c     Wed May 17 04:29:14 2000 +0000
+++ b/bin/sh/eval.c     Wed May 17 07:37:12 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.54 2000/05/15 03:42:48 elric Exp $  */
+/*     $NetBSD: eval.c,v 1.55 2000/05/17 07:37:12 elric Exp $  */
 
 /*-
  * Copyright (c) 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c     8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.54 2000/05/15 03:42:48 elric Exp $");
+__RCSID("$NetBSD: eval.c,v 1.55 2000/05/17 07:37:12 elric Exp $");
 #endif
 #endif /* not lint */
 
@@ -754,6 +754,10 @@
                        pid_t   pid;
 
                        INTOFF;
+                       savelocalvars = localvars;
+                       localvars = NULL;
+                       for (sp = varlist.list ; sp ; sp = sp->next)
+                               mklocal(sp->text, VEXPORT);
                        vforked = 1;
                        switch (pid = vfork()) {
                        case -1:
@@ -783,6 +787,8 @@
                                break;
                        default:
                                handler = savehandler;  /* restore from vfork(2) */
+                               poplocalvars();
+                               localvars = savelocalvars;
                                if (vforked == 2) {
                                        vforked = 0;
                                        waitpid(pid, NULL, 0);
@@ -848,7 +854,7 @@
                savehandler = handler;
                handler = &jmploc;
                for (sp = varlist.list ; sp ; sp = sp->next)
-                       mklocal(sp->text);
+                       mklocal(sp->text, 0);
                funcnest++;
                evaltree(cmdentry.u.func, flags & EV_TESTED);
                funcnest--;
@@ -929,8 +935,9 @@
 #endif
                clearredir(vforked?REDIR_VFORK:0);
                redirect(cmd->ncmd.redirect, vforked?REDIR_VFORK:0);
-               for (sp = varlist.list ; sp ; sp = sp->next)
-                       setvareq(sp->text, VEXPORT|VSTACK);
+               if (!vforked)
+                       for (sp = varlist.list ; sp ; sp = sp->next)
+                               setvareq(sp->text, VEXPORT|VSTACK);
                envp = environment();
                shellexec(argv, envp, pathval(), cmdentry.u.index, vforked);
        }
diff -r 4e60c8ea81be -r 74954d9c8c73 bin/sh/var.c
--- a/bin/sh/var.c      Wed May 17 04:29:14 2000 +0000
+++ b/bin/sh/var.c      Wed May 17 07:37:12 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.23 1999/07/09 03:05:50 christos Exp $        */
+/*     $NetBSD: var.c,v 1.24 2000/05/17 07:37:12 elric Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: var.c,v 1.23 1999/07/09 03:05:50 christos Exp $");
+__RCSID("$NetBSD: var.c,v 1.24 2000/05/17 07:37:12 elric Exp $");
 #endif
 #endif /* not lint */
 
@@ -557,7 +557,7 @@
        if (! in_function())
                error("Not in a function");
        while ((name = *argptr++) != NULL) {
-               mklocal(name);
+               mklocal(name, 0);
        }
        return 0;
 }
@@ -571,7 +571,7 @@
  */
 
 void
-mklocal(name)
+mklocal(name, flags)
        char *name;
        {
        struct localvar *lvp;
@@ -590,9 +590,9 @@
                for (vp = *vpp ; vp && ! varequal(vp->text, name) ; vp = vp->next);
                if (vp == NULL) {
                        if (strchr(name, '='))
-                               setvareq(savestr(name), VSTRFIXED);
+                               setvareq(savestr(name), VSTRFIXED|flags);
                        else
-                               setvar(name, NULL, VSTRFIXED);
+                               setvar(name, NULL, VSTRFIXED|flags);
                        vp = *vpp;      /* the new variable */
                        lvp->text = NULL;
                        lvp->flags = VUNSET;
@@ -601,7 +601,7 @@
                        lvp->flags = vp->flags;
                        vp->flags |= VSTRFIXED|VTEXTFIXED;
                        if (strchr(name, '='))
-                               setvareq(savestr(name), 0);
+                               setvareq(savestr(name), flags);
                }
        }
        lvp->vp = vp;
diff -r 4e60c8ea81be -r 74954d9c8c73 bin/sh/var.h
--- a/bin/sh/var.h      Wed May 17 04:29:14 2000 +0000
+++ b/bin/sh/var.h      Wed May 17 07:37:12 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.h,v 1.16 1999/07/09 03:05:50 christos Exp $        */
+/*     $NetBSD: var.h,v 1.17 2000/05/17 07:37:12 elric Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -123,7 +123,7 @@
 int showvarscmd __P((int, char **));
 int exportcmd __P((int, char **));
 int localcmd __P((int, char **));
-void mklocal __P((char *));
+void mklocal __P((char *, int));
 void poplocalvars __P((void));
 int setvarcmd __P((int, char **));
 int unsetcmd __P((int, char **));



Home | Main Index | Thread Index | Old Index