diff options
author | Bryan Drewery <bryan@shatow.net> | 2021-08-21 09:37:51 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2021-08-23 01:51:53 +0300 |
commit | 2cde6f9084ceb76cac6dbb5a34eb3a1abb73f41d (patch) | |
tree | 7d3a06002a664def909cdee0b85f8a4984ad09cc /src | |
parent | 21804b256f780acdb54e01d50714cac24d557f9b (diff) |
Add getpid() builtin
Diffstat (limited to 'src')
-rw-r--r-- | src/poudriere-sh/builtins-poudriere.def | 1 | ||||
-rw-r--r-- | src/poudriere-sh/helpers.c | 9 | ||||
-rw-r--r-- | src/share/poudriere/include/util.sh | 11 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/poudriere-sh/builtins-poudriere.def b/src/poudriere-sh/builtins-poudriere.def index d7c920f0..279a2b1b 100644 --- a/src/poudriere-sh/builtins-poudriere.def +++ b/src/poudriere-sh/builtins-poudriere.def @@ -3,6 +3,7 @@ clockcmd -n clock critical_startcmd -n critical_start critical_endcmd -n critical_end diremptycmd -n dirempty +getpidcmd -n getpid getvarcmd -n getvar _gsub_var_namecmd -n _gsub_var_name _gsub_badcharscmd -n _gsub_badchars diff --git a/src/poudriere-sh/helpers.c b/src/poudriere-sh/helpers.c index d290eeda..4455c34c 100644 --- a/src/poudriere-sh/helpers.c +++ b/src/poudriere-sh/helpers.c @@ -488,3 +488,12 @@ pgetopt(int argc, char *argv[], const char *optstring) optind = argptr - argv; return (ch); } + +/* $$ is not correct in subshells. */ +int +getpidcmd(int argc, char **argv) +{ + + fprintf(stdout, "%ld\n", (long)getpid()); + return (0); +} diff --git a/src/share/poudriere/include/util.sh b/src/share/poudriere/include/util.sh index 491d7ccd..bbeda94e 100644 --- a/src/share/poudriere/include/util.sh +++ b/src/share/poudriere/include/util.sh @@ -357,11 +357,11 @@ critical_end() { # Send the signal to our real PID, not the rootshell. if [ ${_crit_caught_int} -eq 1 -a ${_CRITSNEST} -eq 0 ]; then _crit_caught_int=0 - kill -INT $(sh -c 'echo ${PPID}') + kill -INT $(getpid) fi if [ ${_crit_caught_term} -eq 1 -a ${_CRITSNEST} -eq 0 ]; then _crit_caught_term=0 - kill -TERM $(sh -c 'echo ${PPID}') + kill -TERM $(getpid) fi } fi @@ -1143,3 +1143,10 @@ required_env() { exit ${EX_SOFTWARE} fi } + +if ! type getpid >/dev/null 2>&1; then +# $$ is not correct in subshells. +getpid() { + sh -c 'echo $PPID' +} +fi |