summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-06-01 02:14:48 +0000
committertjr <tjr@FreeBSD.org>2002-06-01 02:14:48 +0000
commitd3a1f7d9120d0d3374a03d33ab9fd3639588b95a (patch)
tree6f9f6a02deb0b4b48ec74ae2dd4e3547dde24eca /bin/sh
parentfff7a365669b964928b679402547a2c0dd3428d3 (diff)
downloadFreeBSD-src-d3a1f7d9120d0d3374a03d33ab9fd3639588b95a.zip
FreeBSD-src-d3a1f7d9120d0d3374a03d33ab9fd3639588b95a.tar.gz
Implement $PPID, the parent process ID of the shell.
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/var.c8
-rw-r--r--bin/sh/var.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/bin/sh/var.c b/bin/sh/var.c
index 297b82b..42c240c 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -91,6 +91,7 @@ struct var vifs;
struct var vmail;
struct var vmpath;
struct var vpath;
+struct var vppid;
struct var vps1;
struct var vps2;
struct var vvers;
@@ -116,6 +117,8 @@ const struct varinit varinit[] = {
NULL },
{ &vpath, VSTRFIXED|VTEXTFIXED, "PATH=/bin:/usr/bin",
changepath },
+ { &vppid, VSTRFIXED|VTEXTFIXED|VUNSET, "PPID=",
+ NULL },
/*
* vps1 depends on uid
*/
@@ -165,6 +168,7 @@ INIT {
void
initvar(void)
{
+ char ppid[20];
const struct varinit *ip;
struct var *vp;
struct var **vpp;
@@ -189,6 +193,10 @@ initvar(void)
vps1.text = geteuid() ? "PS1=$ " : "PS1=# ";
vps1.flags = VSTRFIXED|VTEXTFIXED;
}
+ if ((vppid.flags & VEXPORT) == 0) {
+ fmtstr(ppid, sizeof(ppid), "%d", (int)getppid());
+ setvarsafe("PPID", ppid, 0);
+ }
}
/*
diff --git a/bin/sh/var.h b/bin/sh/var.h
index 0718a25..4177599 100644
--- a/bin/sh/var.h
+++ b/bin/sh/var.h
@@ -78,6 +78,7 @@ extern struct var vifs;
extern struct var vmail;
extern struct var vmpath;
extern struct var vpath;
+extern struct var vppid;
extern struct var vps1;
extern struct var vps2;
#if ATTY
OpenPOWER on IntegriCloud