History

player/{command,scripting}: log subprocess execution

Useful for debugging purposes and sanity checks. Remove unused function while at it.

Kacper Michajłow committed 2 years ago

Commit 0aebcbc1 parent 024c79a5 files · +24 −23Browse files

Unified · Split

5 files
  1. osdep/subprocess.c +14 −4
  2. osdep/subprocess.h +6 −3
  3. player/command.c +2 −6
  4. player/lua/ytdl_hook.lua +0 −2
  5. player/scripting.c +2 −8
osdep/subprocess.c+14−4
@@ -21,10 +21,6 @@ · 20 unmodified lines
21 21
22#include "subprocess.h"22#include "subprocess.h"
23 23
24void mp_devnull(void *ctx, char *data, size_t size)
25{
26}
27
28const char *mp_subprocess_err_str(int num)24const char *mp_subprocess_err_str(int num)
29{25{
30 // Note: these are visible to the public client API26 // 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
37void 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}
osdep/subprocess.h+6−3
@@ -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.
36typedef void (*subprocess_write_cb)(void *ctx);36typedef void (*subprocess_write_cb)(void *ctx);
37 37
38void mp_devnull(void *ctx, char *data, size_t size);
39
40#define MP_SUBPROCESS_MAX_FDS 1038#define MP_SUBPROCESS_MAX_FDS 10
41 39
42struct mp_subprocess_fd {40struct mp_subprocess_fd {
@@ -64,7 +62,7 @@ struct mp_subprocess_opts { · 21 unmodified lines
64};62};
65 63
66struct mp_subprocess_result {64struct 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 WEXITSTATUS66 // NB: if WIFEXITED applies, error==0, and this is WEXITSTATUS
69 // on win32, this can use the full 32 bit67 // on win32, this can use the full 32 bit
70 // if started with detach==true, this is always 068 // if started with detach==true, this is always 0
@@ -85,4 +83,9 @@ const char *mp_subprocess_err_str(int num); · 14 unmodified lines
85void mp_subprocess2(struct mp_subprocess_opts *opts,83void mp_subprocess2(struct mp_subprocess_opts *opts,
86 struct mp_subprocess_result *res);84 struct mp_subprocess_result *res);
87 85
86struct mp_log;
87void mp_subprocess(struct mp_log *log,
88 struct mp_subprocess_opts *opts,
89 struct mp_subprocess_result *res);
90
88#endif91#endif
player/command.c+2−6
@@ -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) {
player/lua/ytdl_hook.lua+0−2
@@ -97,8 +97,6 @@ local function platform_is_windows() · 96 unmodified lines
97end97end
98 98
99local function exec(args)99local 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,
player/scripting.c+2−8
@@ -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, because439 // 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
455const struct mp_scripting mp_scripting_run = {449const struct mp_scripting mp_scripting_run = {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t