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
2121
2222 #include "subprocess.h"
2323
24−void mp_devnull(void *ctx, char *data, size_t size)
25−{
26−}
27−
2824 const char *mp_subprocess_err_str(int num)
2925 {
3026 // Note: these are visible to the public client API
@@ -37,3 +33,17 @@ const char *mp_subprocess_err_str(int num) · 6 unmodified lines
3733 default: return "unknown";
3834 }
3935 }
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+}
osdep/subprocess.h+6−3
@@ -35,8 +35,6 @@ typedef void (*subprocess_read_cb)(void *ctx, char *data, size_t size); · 34 unmodified lines
3535 // Not filling the buffer means EOF.
3636 typedef void (*subprocess_write_cb)(void *ctx);
3737
38−void mp_devnull(void *ctx, char *data, size_t size);
39−
4038 #define MP_SUBPROCESS_MAX_FDS 10
4139
4240 struct mp_subprocess_fd {
@@ -64,7 +62,7 @@ struct mp_subprocess_opts { · 21 unmodified lines
6462 };
6563
6664 struct mp_subprocess_result {
67− int error; // one of MP_SUBPROCESS_* (>0 on error)
65+ int error; // one of MP_SUBPROCESS_* (<0 on error)
6866 // NB: if WIFEXITED applies, error==0, and this is WEXITSTATUS
6967 // on win32, this can use the full 32 bit
7068 // if started with detach==true, this is always 0
@@ -85,4 +83,9 @@ const char *mp_subprocess_err_str(int num); · 14 unmodified lines
8583 void mp_subprocess2(struct mp_subprocess_opts *opts,
8684 struct mp_subprocess_result *res);
8785
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+
8891 #endif
player/command.c+2−6
@@ -6052,11 +6052,7 @@ static void cmd_run(void *p) · 6051 unmodified lines
60526052 .detach = true,
60536053 };
60546054 struct mp_subprocess_result res;
6055− mp_subprocess2(&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− }
6055+ mp_subprocess(mpctx->log, &opts, &res);
60606056 talloc_free(args);
60616057 }
60626058
@@ -6170,7 +6166,7 @@ static void cmd_subprocess(void *p) · 107 unmodified lines
61706166 }
61716167
61726168 struct mp_subprocess_result sres;
6173− mp_subprocess2(&opts, &sres);
6169+ mp_subprocess(fdlog, &opts, &sres);
61746170 int status = sres.exit_status;
61756171 char *error = NULL;
61766172 if (sres.error < 0) {
player/lua/ytdl_hook.lua+0−2
@@ -97,8 +97,6 @@ local function platform_is_windows() · 96 unmodified lines
9797 end
9898
9999 local function exec(args)
100− msg.debug("Running: " .. table.concat(args, " "))
101−
102100 return mp.command_native({
103101 name = "subprocess",
104102 args = args,
player/scripting.c+2−8
@@ -433,7 +433,7 @@ static int load_run(struct mp_script_args *args) · 432 unmodified lines
433433 .detach = true,
434434 };
435435 struct mp_subprocess_result res;
436− mp_subprocess2(&opts, &res);
436+ mp_subprocess(args->log, &opts, &res);
437437
438438 // Closing these will (probably) make the client exit, if it really died.
439439 // They _should_ be CLOEXEC, but are not, because
@@ -443,13 +443,7 @@ static int load_run(struct mp_script_args *args) · 3 unmodified lines
443443 if (fds[1] >= 0)
444444 close(fds[1]);
445445
446− if (res.error < 0) {
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;
446+ return res.error;
453447 }
454448
455449 const 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