diff options
author | wm4 <wm4@nowhere> | 2015-01-01 20:04:38 +0100 |
---|---|---|
committer | Diogo Franco (Kovensky) <diogomfranco@gmail.com> | 2015-01-25 17:00:16 +0900 |
commit | 85f54ce5d0d5d1733bb2029ed43bcbd2bac3e22b (patch) | |
tree | 02eef286ef488e2eee469bec3ea2b132bc2eaf70 | |
parent | c473688c5f4177295d7e6f8c67148ded70b77e2e (diff) | |
download | mpv-85f54ce5d0d5d1733bb2029ed43bcbd2bac3e22b.tar.bz2 mpv-85f54ce5d0d5d1733bb2029ed43bcbd2bac3e22b.tar.xz |
subprocess: allow disabling redirection of stdout/stderr
If the stdout or stderr write callback is NULL, then don't redirect this
stream. Preparation for the next commit.
Not sure what to do on Windows; it seems STARTUPINFO doesn't allow
redirection only one of them. So just let them write nothing. For our
intended use-case (next commit), this is probably sensible.
-rw-r--r-- | osdep/subprocess-posix.c | 8 | ||||
-rw-r--r-- | osdep/subprocess-win.c | 8 |
2 files changed, 10 insertions, 6 deletions
diff --git a/osdep/subprocess-posix.c b/osdep/subprocess-posix.c index 82af7c5f50..e56e2401f7 100644 --- a/osdep/subprocess-posix.c +++ b/osdep/subprocess-posix.c @@ -66,18 +66,18 @@ int mp_subprocess(char **args, struct mp_cancel *cancel, void *ctx, int p_stderr[2] = {-1, -1}; pid_t pid = -1; - if (mp_make_cloexec_pipe(p_stdout) < 0) + if (on_stdout && mp_make_cloexec_pipe(p_stdout) < 0) goto done; - if (mp_make_cloexec_pipe(p_stderr) < 0) + if (on_stderr && mp_make_cloexec_pipe(p_stderr) < 0) goto done; if (posix_spawn_file_actions_init(&fa)) goto done; fa_destroy = true; // redirect stdout and stderr - if (posix_spawn_file_actions_adddup2(&fa, p_stdout[1], 1)) + if (p_stdout[1] >= 0 && posix_spawn_file_actions_adddup2(&fa, p_stdout[1], 1)) goto done; - if (posix_spawn_file_actions_adddup2(&fa, p_stderr[1], 2)) + if (p_stderr[1] >= 0 && posix_spawn_file_actions_adddup2(&fa, p_stderr[1], 2)) goto done; if (posix_spawnp(&pid, args[0], &fa, NULL, args, environ)) { diff --git a/osdep/subprocess-win.c b/osdep/subprocess-win.c index c793b67546..48730ef330 100644 --- a/osdep/subprocess-win.c +++ b/osdep/subprocess-win.c @@ -222,6 +222,10 @@ static int async_read(HANDLE file, void *buf, unsigned size, OVERLAPPED* ol) return 0; } +static void write_none(void *ctx, char *data, size_t size) +{ +} + int mp_subprocess(char **args, struct mp_cancel *cancel, void *ctx, subprocess_read_cb on_stdout, subprocess_read_cb on_stderr, char **error) @@ -235,8 +239,8 @@ int mp_subprocess(char **args, struct mp_cancel *cancel, void *ctx, char buf[4096]; subprocess_read_cb read_cb; } pipes[2] = { - { .read_cb = on_stdout }, - { .read_cb = on_stderr }, + { .read_cb = on_stdout ? on_stdout : write_none }, + { .read_cb = on_stderr ? on_stderr : write_none }, }; // If the function exits before CreateProcess, there was an init error |