summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-02-04 18:39:10 +0000
committerLaurent Bercot <ska@appnovation.com>2022-02-04 18:39:10 +0000
commitf5d989ee28362740157ee57e5ae3ef921a4f2e2f (patch)
tree7567ffaa006587c6af9616fe75f561ae76f77b09 /src
parent2fd253683d884d2529f112c88534396fcd2fbe45 (diff)
downloadexecline-f5d989ee28362740157ee57e5ae3ef921a4f2e2f.tar.xz
Allow getpid to get the ppid instead
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/execline/getpid.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/execline/getpid.c b/src/execline/getpid.c
index 9bd7de5..058fe1b 100644
--- a/src/execline/getpid.c
+++ b/src/execline/getpid.c
@@ -9,12 +9,13 @@
#include <execline/execline.h>
-#define USAGE "getpid [ -E | -e ] variable prog..."
+#define USAGE "getpid [ -E | -e ] [ -P | -p ] variable prog..."
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv)
{
int doimport = 0 ;
+ int doppid = 0 ;
char fmt[PID_FMT] ;
PROG = "getpid" ;
{
@@ -27,6 +28,8 @@ int main (int argc, char const *const *argv)
{
case 'E' : doimport = 1 ; break ;
case 'e' : doimport = 0 ; break ;
+ case 'P' : doppid = 1 ; break ;
+ case 'p' : doppid = 0 ; break ;
default : dieusage() ;
}
}
@@ -35,6 +38,6 @@ int main (int argc, char const *const *argv)
if (argc < 2) dieusage() ;
if (!argv[0][0] || strchr(argv[0], '=')) strerr_dief1x(100, "invalid variable name") ;
- fmt[pid_fmt(fmt, getpid())] = 0 ;
+ fmt[pid_fmt(fmt, doppid ? getppid() : getpid())] = 0 ;
el_modif_and_exec(argv + 1, argv[0], fmt, doimport) ;
}