introduce $BASHPID for ormaaj from #ksh

This commit is contained in:
tg 2012-11-20 17:42:32 +00:00
parent bfda9858f1
commit 435bc124ef
4 changed files with 15 additions and 7 deletions

4
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#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);

6
mksh.1
View File

@ -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

9
var.c
View File

@ -27,7 +27,7 @@
#include <sys/sysctl.h>
#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

View File

@ -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)