about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.stephenson@samsung.com>2018-06-15 15:02:36 +0100
committerPeter Stephenson <p.stephenson@samsung.com>2018-06-15 15:02:36 +0100
commit9408c4825b339c43299a39b46811fc6153740e01 (patch)
treeb1f4e68fda0b1cf3a1f18da06d4377d36ce2fd6d
parentf37c181b29149c6829cc8a86f7348335a08d9670 (diff)
downloadzsh-9408c4825b339c43299a39b46811fc6153740e01.tar.gz
zsh-9408c4825b339c43299a39b46811fc6153740e01.tar.xz
zsh-9408c4825b339c43299a39b46811fc6153740e01.zip
users/23472: Add $sysparams[procsubstpid] to zsh/system
-rw-r--r--ChangeLog3
-rw-r--r--Doc/Zsh/mod_system.yo5
-rw-r--r--Src/Modules/system.c4
-rw-r--r--Src/exec.c10
-rw-r--r--Src/zsh.h1
5 files changed, 23 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 0a83ee93f..4c8ff2f41 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2018-06-15  Peter Stephenson  <p.stephenson@samsung.com>
 
+	* users/23472: 	Doc/Zsh/mod_system.yo, Src/Modules/system.c,
+	Src/exec.c, Src/zsh.h: Add $sysparams[procsubstpid].
+
 	* 43008: Src/otpions.c: combine suggestion from Sebastain to
 	silence warnings for double setgid/setuid with suggestion
 	from Eitan to put setgid first.
diff --git a/Doc/Zsh/mod_system.yo b/Doc/Zsh/mod_system.yo
index 7f2009b43..a27bab47f 100644
--- a/Doc/Zsh/mod_system.yo
+++ b/Doc/Zsh/mod_system.yo
@@ -255,6 +255,11 @@ Returns the process ID of the parent of the current process, even in
 subshells.  Compare tt($PPID), which returns the process ID of the parent
 of the main shell process.
 )
+item(tt(procsubstpid))(
+Returns the process ID of the last process started for process
+substitution, i.e. the tt(<LPAR())var(...)tt(RPAR()) and
+tt(>LPAR())var(...)tt(RPAR()) expansions.
+)
 enditem()
 )
 enditem()
diff --git a/Src/Modules/system.c b/Src/Modules/system.c
index 9fd4d2583..7a4f4ee13 100644
--- a/Src/Modules/system.c
+++ b/Src/Modules/system.c
@@ -772,6 +772,8 @@ fillpmsysparams(Param pm, const char *name)
 	num = (int)getpid();
     } else if (!strcmp(name, "ppid")) {
 	num = (int)getppid();
+    } else if (!strcmp(name, "procsubstpid")) {
+	num = (int)procsubstpid;
     } else {
 	pm->u.str = dupstring("");
 	pm->node.flags |= PM_UNSET;
@@ -805,6 +807,8 @@ scanpmsysparams(UNUSED(HashTable ht), ScanFunc func, int flags)
     func(&spm.node, flags);
     fillpmsysparams(&spm, "ppid");
     func(&spm.node, flags);
+    fillpmsysparams(&spm, "procsubstpid");
+    func(&spm.node, flags);
 }
 
 static struct mathfunc mftab[] = {
diff --git a/Src/exec.c b/Src/exec.c
index 963b0a5c3..d44527841 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -174,6 +174,11 @@ mod_export int zleactive;
 /**/
 pid_t cmdoutpid;
 
+/* pid of last process started by <(...),  >(...) */
+
+/**/
+mod_export pid_t procsubstpid;
+
 /* exit status of process undergoing 'process substitution' */
 
 /**/
@@ -4850,6 +4855,7 @@ getproc(char *cmd, char **eptr)
 	    return NULL;
 	if (!out)
 	    addproc(pid, NULL, 1, &bgtime);
+	procsubstpid = pid;
 	return pnam;
     }
     closem(FDT_UNUSED, 0);
@@ -4887,6 +4893,7 @@ getproc(char *cmd, char **eptr)
 	{
 	    addproc(pid, NULL, 1, &bgtime);
 	}
+	procsubstpid = pid;
 	return pnam;
     }
     entersubsh(ESUB_ASYNC|ESUB_PGRP);
@@ -4937,6 +4944,7 @@ getpipe(char *cmd, int nullexec)
 	}
 	if (!nullexec)
 	    addproc(pid, NULL, 1, &bgtime);
+	procsubstpid = pid;
 	return pipes[!out];
     }
     entersubsh(ESUB_PGRP);
@@ -6172,6 +6180,7 @@ execsave(void)
     es->cmdoutpid = cmdoutpid;
     es->cmdoutval = cmdoutval;
     es->use_cmdoutval = use_cmdoutval;
+    es->procsubstpid = procsubstpid;
     es->trap_return = trap_return;
     es->trap_state = trap_state;
     es->trapisfunc = trapisfunc;
@@ -6207,6 +6216,7 @@ execrestore(void)
     cmdoutpid = en->cmdoutpid;
     cmdoutval = en->cmdoutval;
     use_cmdoutval = en->use_cmdoutval;
+    procsubstpid = en->procsubstpid;
     trap_return = en->trap_return;
     trap_state = en->trap_state;
     trapisfunc = en->trapisfunc;
diff --git a/Src/zsh.h b/Src/zsh.h
index 8535d48fb..8e7f20b2c 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1095,6 +1095,7 @@ struct execstack {
     pid_t cmdoutpid;
     int cmdoutval;
     int use_cmdoutval;
+    pid_t procsubstpid;
     int trap_return;
     int trap_state;
     int trapisfunc;