From 2833b8b99ee3db8b3a43644c2d46593f944c6dcb Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 11 May 2021 12:00:14 -0500 Subject: Add $BASHPID to show current process in () and such. ($$ is top level shell) --- toys/pending/sh.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'toys') diff --git a/toys/pending/sh.c b/toys/pending/sh.c index ab2408a0..b4df9974 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -535,6 +535,7 @@ static char *getvar(char *s) else if (c == 'R') sprintf(toybuf, "%ld", random()&((1<<16)-1)); else if (c == 'L') sprintf(toybuf, "%u", TT.ff->pl->lineno); else if (c == 'G') sprintf(toybuf, "TODO: GROUPS"); + else if (c == 'B') sprintf(toybuf, "%d", getpid()); return toybuf; } @@ -3602,7 +3603,7 @@ static void subshell_setup(void) { int ii, from, pid, ppid, zpid, myppid = getppid(), len, uid = getuid(); struct passwd *pw = getpwuid(uid); - char *s, *ss, *magic[] = {"SECONDS", "RANDOM", "LINENO", "GROUPS"}, + char *s, *ss, *magic[] = {"SECONDS", "RANDOM", "LINENO", "GROUPS", "BASHPID"}, *readonly[] = {xmprintf("EUID=%d", geteuid()), xmprintf("UID=%d", uid), xmprintf("PPID=%d", myppid)}; struct stat st; @@ -3616,8 +3617,8 @@ static void subshell_setup(void) // Initialize magic and read only local variables srandom(TT.SECONDS = millitime()); - for (ii = 0; iiflags = VAR_MAGIC|(VAR_INT*('G'!=*magic[ii])); + for (ii = 0; iiflags = VAR_MAGIC+VAR_INT*('G'!=*s)+VAR_READONLY*('B'==*s); for (ii = 0; iiflags = VAR_READONLY|VAR_INT; -- cgit v1.2.3