summaryrefslogtreecommitdiffstats
path: root/osdep/subprocess-posix.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-06-27 21:08:55 +0200
committerwm4 <wm4@nowhere>2015-06-27 21:08:55 +0200
commit03c70a8d81f14ce46bc3410b08f5956d6af34d82 (patch)
tree39f71e3672e99990eaa665a58a6f3a174c025a54 /osdep/subprocess-posix.c
parent6ffb1e2b661464bc31e2cfffd1d77727f27e1561 (diff)
downloadmpv-03c70a8d81f14ce46bc3410b08f5956d6af34d82.tar.bz2
mpv-03c70a8d81f14ce46bc3410b08f5956d6af34d82.tar.xz
subprocess, lua: export whether the process was killed by us
We want to distinguish actual errors, and just aborting the program intentionally. Also be a bit more careful with handling the wait() exit status: do not called WEXITSTATUS() without checking WIFEXITED() first.
Diffstat (limited to 'osdep/subprocess-posix.c')
-rw-r--r--osdep/subprocess-posix.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/osdep/subprocess-posix.c b/osdep/subprocess-posix.c
index b0b4b3663e..16f9735fe7 100644
--- a/osdep/subprocess-posix.c
+++ b/osdep/subprocess-posix.c
@@ -64,6 +64,8 @@ int mp_subprocess(char **args, struct mp_cancel *cancel, void *ctx,
int p_stderr[2] = {-1, -1};
int devnull = -1;
pid_t pid = -1;
+ bool spawned = false;
+ bool killed_by_us = false;
if (on_stdout && mp_make_cloexec_pipe(p_stdout) < 0)
goto done;
@@ -89,6 +91,7 @@ int mp_subprocess(char **args, struct mp_cancel *cancel, void *ctx,
pid = -1;
goto done;
}
+ spawned = true;
close(p_stdout[1]);
p_stdout[1] = -1;
@@ -124,6 +127,7 @@ int mp_subprocess(char **args, struct mp_cancel *cancel, void *ctx,
}
if (fds[2].revents) {
kill(pid, SIGKILL);
+ killed_by_us = true;
break;
}
}
@@ -143,12 +147,15 @@ done:
close(p_stderr[1]);
close(devnull);
- if (WIFEXITED(status) && WEXITSTATUS(status) != 127) {
+ if (!spawned || (WIFEXITED(status) && WEXITSTATUS(status) == 127)) {
+ *error = "init";
+ status = -1;
+ } else if (WIFEXITED(status)) {
*error = NULL;
status = WEXITSTATUS(status);
} else {
- *error = WEXITSTATUS(status) == 127 ? "init" : "killed";
- status = -1;
+ *error = "killed";
+ status = killed_by_us ? MP_SUBPROCESS_EKILLED_BY_US : -1;
}
return status;