From 435bc124ef9f027b005d7d77067fd0445120e9e7 Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 20 Nov 2012 17:42:32 +0000 Subject: [PATCH] introduce $BASHPID for ormaaj from #ksh --- main.c | 4 +++- mksh.1 | 6 ++++-- var.c | 9 ++++++--- var_spec.h | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 138cf72..5c164ab 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.238 2012/11/12 18:28:39 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.239 2012/11/20 17:42:29 tg Exp $"); extern char **environ; @@ -383,6 +383,8 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp) (!ksheuid && !strchr(str_val(vp), '#'))) /* setstr can't fail here */ setstr(vp, safe_prompt, KSH_RETURN_ERROR); + setint_n((vp = global("BASHPID")), 0, 10); + vp->flag |= INT_U; setint_n((vp = global("PGRP")), (mksh_uari_t)kshpgrp, 10); vp->flag |= INT_U; setint_n((vp = global("PPID")), (mksh_uari_t)kshppid, 10); diff --git a/mksh.1 b/mksh.1 index 2537e52..8fe33bc 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.296 2012/10/22 20:19:14 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.297 2012/11/20 17:42:30 tg Exp $ .\" $OpenBSD: ksh.1,v 1.144 2012/07/08 08:13:20 guenther Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, @@ -74,7 +74,7 @@ .\" with -mandoc, it might implement .Mx itself, but we want to .\" use our own definition. And .Dd must come *first*, always. .\" -.Dd $Mdocdate: October 22 2012 $ +.Dd $Mdocdate: November 20 2012 $ .\" .\" Check which macro package we use, and do other -mdoc setup. .\" @@ -1741,6 +1741,8 @@ When an external command is executed by the shell, this parameter is set in the environment of the new process to the path of the executed command. In interactive use, this parameter is also set in the parent shell to the last word of the previous command. +.It Ev BASHPID +The PID of the shell or subshell. .It Ev CDPATH Search path for the .Ic cd diff --git a/var.c b/var.c index 9111f6e..2a3699a 100644 --- a/var.c +++ b/var.c @@ -27,7 +27,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.155 2012/11/20 17:34:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.156 2012/11/20 17:42:32 tg Exp $"); /*- * Variables @@ -130,8 +130,8 @@ initvar(void) struct tbl *tp; ktinit(APERM, &specials, - /* currently 12 specials: 75% of 16 = 2^4 */ - 4); + /* currently 13 specials: 75% of 32 = 2^5 */ + 5); while (i < V_MAX - 1) { tp = ktenter(&specials, initvar_names[i], hash(initvar_names[i])); @@ -1086,6 +1086,9 @@ getspec(struct tbl *vp) int st; switch ((st = special(vp->name))) { + case V_BASHPID: + i = (mksh_ari_t)procpid; + break; case V_COLUMNS: /* * Do NOT export COLUMNS/LINES. Many applications diff --git a/var_spec.h b/var_spec.h index b3bef4b..3444c25 100644 --- a/var_spec.h +++ b/var_spec.h @@ -1,5 +1,5 @@ #if defined(VARSPEC_DEFNS) -__RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.2 2011/06/05 19:58:21 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.3 2012/11/20 17:42:32 tg Exp $"); #define FN(name) /* nothing */ #elif defined(VARSPEC_ENUMS) #define FN(name) V_##name, @@ -19,6 +19,7 @@ __RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.2 2011/06/05 19:58:21 tg Exp $"); F0(NONE) /* 1 and up are special variables */ +FN(BASHPID) FN(COLUMNS) #if HAVE_PERSISTENT_HISTORY FN(HISTFILE)