player/{command,scripting}: log subprocess execution

Useful for debugging purposes and sanity checks.

Remove unused function while at it.
This commit is contained in:
Kacper Michajłow
2024-07-12 11:38:49 +02:00
parent 024c79a53c
commit 0aebcbcc19
5 changed files with 24 additions and 23 deletions

View File

@@ -21,10 +21,6 @@
#include "subprocess.h"
void mp_devnull(void *ctx, char *data, size_t size)
{
}
const char *mp_subprocess_err_str(int num)
{
// Note: these are visible to the public client API
@@ -37,3 +33,17 @@ const char *mp_subprocess_err_str(int num)
default: return "unknown";
}
}
void mp_subprocess(struct mp_log *log,
struct mp_subprocess_opts *opts,
struct mp_subprocess_result *res)
{
mp_verbose(log, "Starting subprocess: [%s", opts->args[0]);
char **arg = &opts->args[1];
while (*arg)
mp_verbose(log, ", %s", *arg++);
mp_verbose(log, "]\n");
mp_subprocess2(opts, res);
if (res->error < 0)
mp_err(log, "Subprocess failed: %s\n", mp_subprocess_err_str(res->error));
}

View File

@@ -35,8 +35,6 @@ typedef void (*subprocess_read_cb)(void *ctx, char *data, size_t size);
// Not filling the buffer means EOF.
typedef void (*subprocess_write_cb)(void *ctx);
void mp_devnull(void *ctx, char *data, size_t size);
#define MP_SUBPROCESS_MAX_FDS 10
struct mp_subprocess_fd {
@@ -64,7 +62,7 @@ struct mp_subprocess_opts {
};
struct mp_subprocess_result {
int error; // one of MP_SUBPROCESS_* (>0 on error)
int error; // one of MP_SUBPROCESS_* (<0 on error)
// NB: if WIFEXITED applies, error==0, and this is WEXITSTATUS
// on win32, this can use the full 32 bit
// if started with detach==true, this is always 0
@@ -85,4 +83,9 @@ const char *mp_subprocess_err_str(int num);
void mp_subprocess2(struct mp_subprocess_opts *opts,
struct mp_subprocess_result *res);
struct mp_log;
void mp_subprocess(struct mp_log *log,
struct mp_subprocess_opts *opts,
struct mp_subprocess_result *res);
#endif