Useful for debugging purposes and sanity checks. Remove unused function while at it.
Unified · Split
| @@ -21,10 +21,6 @@ · 20 unmodified lines | |||
| 21 | 21 | ||
| 22 | #include "subprocess.h" | 22 | #include "subprocess.h" |
| 23 | 23 | ||
| 24 | void mp_devnull(void *ctx, char *data, size_t size) | ||
| 25 | { | ||
| 26 | } | ||
| 27 | |||
| 28 | const char *mp_subprocess_err_str(int num) | 24 | const char *mp_subprocess_err_str(int num) |
| 29 | { | 25 | { |
| 30 | // Note: these are visible to the public client API | 26 | // Note: these are visible to the public client API |
| @@ -37,3 +33,17 @@ const char *mp_subprocess_err_str(int num) · 6 unmodified lines | |||
| 37 | default: return "unknown"; | 33 | default: return "unknown"; |
| 38 | } | 34 | } |
| 39 | } | 35 | } |
| 36 | |||
| 37 | void mp_subprocess(struct mp_log *log, | ||
| 38 | struct mp_subprocess_opts *opts, | ||
| 39 | struct mp_subprocess_result *res) | ||
| 40 | { | ||
| 41 | mp_verbose(log, "Starting subprocess: [%s", opts->args[0]); | ||
| 42 | char **arg = &opts->args[1]; | ||
| 43 | while (*arg) | ||
| 44 | mp_verbose(log, ", %s", *arg++); | ||
| 45 | mp_verbose(log, "]\n"); | ||
| 46 | mp_subprocess2(opts, res); | ||
| 47 | if (res->error < 0) | ||
| 48 | mp_err(log, "Subprocess failed: %s\n", mp_subprocess_err_str(res->error)); | ||
| 49 | } | ||
| @@ -35,8 +35,6 @@ typedef void (*subprocess_read_cb)(void *ctx, char *data, size_t size); · 34 unmodified lines | |||
| 35 | // Not filling the buffer means EOF. | 35 | // Not filling the buffer means EOF. |
| 36 | typedef void (*subprocess_write_cb)(void *ctx); | 36 | typedef void (*subprocess_write_cb)(void *ctx); |
| 37 | 37 | ||
| 38 | void mp_devnull(void *ctx, char *data, size_t size); | ||
| 39 | |||
| 40 | #define MP_SUBPROCESS_MAX_FDS 10 | 38 | #define MP_SUBPROCESS_MAX_FDS 10 |
| 41 | 39 | ||
| 42 | struct mp_subprocess_fd { | 40 | struct mp_subprocess_fd { |
| @@ -64,7 +62,7 @@ struct mp_subprocess_opts { · 21 unmodified lines | |||
| 64 | }; | 62 | }; |
| 65 | 63 | ||
| 66 | struct mp_subprocess_result { | 64 | struct mp_subprocess_result { |
| 67 | int error; // one of MP_SUBPROCESS_* (>0 on error) | 65 | int error; // one of MP_SUBPROCESS_* (<0 on error) |
| 68 | // NB: if WIFEXITED applies, error==0, and this is WEXITSTATUS | 66 | // NB: if WIFEXITED applies, error==0, and this is WEXITSTATUS |
| 69 | // on win32, this can use the full 32 bit | 67 | // on win32, this can use the full 32 bit |
| 70 | // if started with detach==true, this is always 0 | 68 | // if started with detach==true, this is always 0 |
| @@ -85,4 +83,9 @@ const char *mp_subprocess_err_str(int num); · 14 unmodified lines | |||
| 85 | void mp_subprocess2(struct mp_subprocess_opts *opts, | 83 | void mp_subprocess2(struct mp_subprocess_opts *opts, |
| 86 | struct mp_subprocess_result *res); | 84 | struct mp_subprocess_result *res); |
| 87 | 85 | ||
| 86 | struct mp_log; | ||
| 87 | void mp_subprocess(struct mp_log *log, | ||
| 88 | struct mp_subprocess_opts *opts, | ||
| 89 | struct mp_subprocess_result *res); | ||
| 90 | |||
| 88 | #endif | 91 | #endif |
| @@ -6052,11 +6052,7 @@ static void cmd_run(void *p) · 6051 unmodified lines | |||
| 6052 | .detach = true, | 6052 | .detach = true, |
| 6053 | }; | 6053 | }; |
| 6054 | struct mp_subprocess_result res; | 6054 | struct mp_subprocess_result res; |
| 6055 | mp_subprocess2(&opts, &res); | 6055 | mp_subprocess(mpctx->log, &opts, &res); |
| 6056 | if (res.error < 0) { | ||
| 6057 | mp_err(mpctx->log, "Starting subprocess failed: %s\n", | ||
| 6058 | mp_subprocess_err_str(res.error)); | ||
| 6059 | } | ||
| 6060 | talloc_free(args); | 6056 | talloc_free(args); |
| 6061 | } | 6057 | } |
| 6062 | 6058 | ||
| @@ -6170,7 +6166,7 @@ static void cmd_subprocess(void *p) · 107 unmodified lines | |||
| 6170 | } | 6166 | } |
| 6171 | 6167 | ||
| 6172 | struct mp_subprocess_result sres; | 6168 | struct mp_subprocess_result sres; |
| 6173 | mp_subprocess2(&opts, &sres); | 6169 | mp_subprocess(fdlog, &opts, &sres); |
| 6174 | int status = sres.exit_status; | 6170 | int status = sres.exit_status; |
| 6175 | char *error = NULL; | 6171 | char *error = NULL; |
| 6176 | if (sres.error < 0) { | 6172 | if (sres.error < 0) { |
| @@ -97,8 +97,6 @@ local function platform_is_windows() · 96 unmodified lines | |||
| 97 | end | 97 | end |
| 98 | 98 | ||
| 99 | local function exec(args) | 99 | local function exec(args) |
| 100 | msg.debug("Running: " .. table.concat(args, " ")) | ||
| 101 | |||
| 102 | return mp.command_native({ | 100 | return mp.command_native({ |
| 103 | name = "subprocess", | 101 | name = "subprocess", |
| 104 | args = args, | 102 | args = args, |
| @@ -433,7 +433,7 @@ static int load_run(struct mp_script_args *args) · 432 unmodified lines | |||
| 433 | .detach = true, | 433 | .detach = true, |
| 434 | }; | 434 | }; |
| 435 | struct mp_subprocess_result res; | 435 | struct mp_subprocess_result res; |
| 436 | mp_subprocess2(&opts, &res); | 436 | mp_subprocess(args->log, &opts, &res); |
| 437 | 437 | ||
| 438 | // Closing these will (probably) make the client exit, if it really died. | 438 | // Closing these will (probably) make the client exit, if it really died. |
| 439 | // They _should_ be CLOEXEC, but are not, because | 439 | // They _should_ be CLOEXEC, but are not, because |
| @@ -443,13 +443,7 @@ static int load_run(struct mp_script_args *args) · 3 unmodified lines | |||
| 443 | if (fds[1] >= 0) | 443 | if (fds[1] >= 0) |
| 444 | close(fds[1]); | 444 | close(fds[1]); |
| 445 | 445 | ||
| 446 | if (res.error < 0) { | 446 | return res.error; |
| 447 | MP_ERR(args, "Starting '%s' failed: %s\n", args->filename, | ||
| 448 | mp_subprocess_err_str(res.error)); | ||
| 449 | return -1; | ||
| 450 | } | ||
| 451 | |||
| 452 | return 0; | ||
| 453 | } | 447 | } |
| 454 | 448 | ||
| 455 | const struct mp_scripting mp_scripting_run = { | 449 | const struct mp_scripting mp_scripting_run = { |