summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-05 20:11:01 +0100
committerwm4 <wm4@nowhere>2014-01-05 20:11:01 +0100
commit2123ca52c9c032f5f77923bc2bb3057cbe6ab4b9 (patch)
treeff80757c731c890ac3d26f374ac031cef6083bce
parent2da916f6df71bc4a9cff3d3f8ca940a7b4ec5183 (diff)
downloadmpv-2123ca52c9c032f5f77923bc2bb3057cbe6ab4b9.tar.bz2
mpv-2123ca52c9c032f5f77923bc2bb3057cbe6ab4b9.tar.xz
player: print an error message if run command fails
Note that we can't use mp_msg, because it's not async-signal safe (we might be running other threads while forking, so only functions specified to be async-signal safe can be called, and this doesn't include stdio; mp_msg acquires a mutex too). Also, always print a \n before running the program to flush the status line. The effect is that a program running successfully as well as the error message will effectively start on a new line.
-rw-r--r--player/command.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/player/command.c b/player/command.c
index e59a2d50e8..0275babee6 100644
--- a/player/command.c
+++ b/player/command.c
@@ -3052,6 +3052,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
case MP_CMD_RUN: {
#ifndef __MINGW32__
+ mp_msg(mpctx->statusline, MSGL_STATUS, "\n");
char *args[MP_CMD_MAX_ARGS + 1] = {0};
for (int n = 0; n < cmd->nargs; n++)
args[n] = cmd->args[n].v.s;
@@ -3062,7 +3063,10 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
// about having to wait for the second process to terminate.
if (fork() == 0) {
execvp(args[0], args);
- _exit(0);
+ // mp_msg() is not safe to be called from a forked process.
+ char s[] = "Executing program failed.\n";
+ write(2, s, sizeof(s) - 1);
+ _exit(1);
}
_exit(0);
}