diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-11-15 17:22:29 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-11-15 17:22:29 +0100 |
commit | d0ede0646f231179b3eab5a7aa4ab1e399f7c5be (patch) | |
tree | cc08d877c691c36275f28af6f21b56be0d8838ce /lib/fs.c | |
parent | 6cec0d369192f43d87680a3f807054659206f713 (diff) |
fs: extend process close() function to return program exit code
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib/fs.c')
-rw-r--r-- | lib/fs.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -171,14 +171,24 @@ static struct json_object * ut_fs_pclose(struct ut_state *s, uint32_t off, struct json_object *args) { FILE **fp = (FILE **)ops->get_type(s->ctx, "fs.proc"); + int rc; if (!fp || !*fp) err_return(EBADF); - pclose(*fp); + rc = pclose(*fp); *fp = NULL; - return json_object_new_boolean(true); + if (rc == -1) + err_return(errno); + + if (WIFEXITED(rc)) + return xjs_new_int64(WEXITSTATUS(rc)); + + if (WIFSIGNALED(rc)) + return xjs_new_int64(-WTERMSIG(rc)); + + return xjs_new_int64(0); } static struct json_object * |