summaryrefslogtreecommitdiffstats
path: root/osdep/subprocess-posix.c
diff options
context:
space:
mode:
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;