diff options
Diffstat (limited to 'extension/fork.c')
-rw-r--r-- | extension/fork.c | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/extension/fork.c b/extension/fork.c index aff9b568..3c288c04 100644 --- a/extension/fork.c +++ b/extension/fork.c @@ -38,22 +38,24 @@ do_fork(int nargs) NODE **aptr; NODE *tmp; - if (do_lint && get_curfunc_arg_count() > 0) + if (do_lint && nargs > 0) lintwarn("fork: called with too many arguments"); ret = fork(); if (ret < 0) - update_ERRNO(); - else if (ret == 0) { + update_ERRNO_int(errno); + else if (ret == 0 && PROCINFO_node != NULL) { /* update PROCINFO in the child */ - aptr = assoc_lookup(PROCINFO_node, tmp = make_string("pid", 3), FALSE); - (*aptr)->numbr = (AWKNUM) getpid(); + aptr = assoc_lookup(PROCINFO_node, tmp = make_string("pid", 3)); + unref(*aptr); + *aptr = make_number((AWKNUM) getpid()); unref(tmp); - aptr = assoc_lookup(PROCINFO_node, tmp = make_string("ppid", 4), FALSE); - (*aptr)->numbr = (AWKNUM) getppid(); + aptr = assoc_lookup(PROCINFO_node, tmp = make_string("ppid", 4)); + unref(*aptr); + *aptr = make_number((AWKNUM) getppid()); unref(tmp); } @@ -73,17 +75,17 @@ do_waitpid(int nargs) pid_t pid; int options = 0; - if (do_lint && get_curfunc_arg_count() > 1) + if (do_lint && nargs > 1) lintwarn("waitpid: called with too many arguments"); - pidnode = get_scalar_argument(0, FALSE); + pidnode = get_scalar_argument(0, false); if (pidnode != NULL) { - pidval = force_number(pidnode); + pidval = get_number_d(pidnode); pid = (int) pidval; options = WNOHANG|WUNTRACED; ret = waitpid(pid, NULL, options); if (ret < 0) - update_ERRNO(); + update_ERRNO_int(errno); } else if (do_lint) lintwarn("wait: called with no arguments"); @@ -91,6 +93,25 @@ do_waitpid(int nargs) return make_number((AWKNUM) ret); } + +/* do_wait --- provide dynamically loaded wait() builtin for gawk */ + +static NODE * +do_wait(int nargs) +{ + int ret; + + if (do_lint && nargs > 0) + lintwarn("wait: called with too many arguments"); + + ret = wait(NULL); + if (ret < 0) + update_ERRNO_int(errno); + + /* Set the return value */ + return make_number((AWKNUM) ret); +} + /* dlload --- load new builtins in this library */ NODE * @@ -100,5 +121,6 @@ void *dl; { make_builtin("fork", do_fork, 0); make_builtin("waitpid", do_waitpid, 1); + make_builtin("wait", do_wait, 0); return make_number((AWKNUM) 0); } |