tools: return error when there was an error

Fixes #4286
This commit is contained in:
Wim Taymans 2026-06-23 10:40:04 +02:00
parent 656add0ae8
commit 9c5ea39f4e

View file

@ -58,6 +58,8 @@ struct data {
struct pw_main_loop *loop; struct pw_main_loop *loop;
struct pw_context *context; struct pw_context *context;
int res;
struct spa_list remotes; struct spa_list remotes;
struct remote_data *current; struct remote_data *current;
@ -449,7 +451,7 @@ static int print_global(void *obj, void *data)
} }
static bool bind_global(struct remote_data *rd, struct global *global, char **error); static int bind_global(struct remote_data *rd, struct global *global, char **error);
static void registry_event_global(void *data, uint32_t id, static void registry_event_global(void *data, uint32_t id,
uint32_t permissions, const char *type, uint32_t version, uint32_t permissions, const char *type, uint32_t version,
@ -459,7 +461,7 @@ static void registry_event_global(void *data, uint32_t id,
struct global *global; struct global *global;
size_t size; size_t size;
char *error; char *error;
bool ret; int res;
global = calloc(1, sizeof(struct global)); global = calloc(1, sizeof(struct global));
if (global == NULL) { if (global == NULL) {
@ -484,10 +486,11 @@ static void registry_event_global(void *data, uint32_t id,
pw_map_insert_at(&rd->globals, id, global); pw_map_insert_at(&rd->globals, id, global);
/* immediately bind the object always */ /* immediately bind the object always */
ret = bind_global(rd, global, &error); if ((res = bind_global(rd, global, &error)) < 0) {
if (!ret) {
if (rd->data->interactive) if (rd->data->interactive)
fprintf(stderr, "Error: \"%s\"\n", error); fprintf(stderr, "Error: \"%s\"\n", error);
if (res != -ENOTSUP)
rd->data->res = res;
free(error); free(error);
} }
} }
@ -1440,7 +1443,7 @@ static const struct class *find_class(const char *type, uint32_t version)
return NULL; return NULL;
} }
static bool bind_global(struct remote_data *rd, struct global *global, char **error) static int bind_global(struct remote_data *rd, struct global *global, char **error)
{ {
const struct class *class; const struct class *class;
struct proxy_data *pd; struct proxy_data *pd;
@ -1449,7 +1452,7 @@ static bool bind_global(struct remote_data *rd, struct global *global, char **er
class = find_class(global->type, global->version); class = find_class(global->type, global->version);
if (class == NULL) { if (class == NULL) {
*error = spa_aprintf("unsupported type %s", global->type); *error = spa_aprintf("unsupported type %s", global->type);
return false; return -ENOTSUP;
} }
global->class = class; global->class = class;
@ -1471,16 +1474,17 @@ static bool bind_global(struct remote_data *rd, struct global *global, char **er
rd->prompt_pending = pw_core_sync(rd->core, 0, 0); rd->prompt_pending = pw_core_sync(rd->core, 0, 0);
return true; return 0;
} }
static bool do_global_info(struct global *global, char **error) static bool do_global_info(struct global *global, char **error)
{ {
struct remote_data *rd = global->rd; struct remote_data *rd = global->rd;
struct proxy_data *pd; struct proxy_data *pd;
int res;
if (global->proxy == NULL) { if (global->proxy == NULL) {
if (!bind_global(rd, global, error)) if ((res = bind_global(rd, global, error)) < 0)
return false; return false;
global->info_pending = true; global->info_pending = true;
} else { } else {
@ -1861,7 +1865,7 @@ static bool do_enum_params(struct data *data, const char *cmd, char *args, char
return false; return false;
} }
if (global->proxy == NULL) { if (global->proxy == NULL) {
if (!bind_global(rd, global, error)) if (bind_global(rd, global, error) < 0)
return false; return false;
} }
@ -1912,7 +1916,7 @@ static bool do_set_param(struct data *data, const char *cmd, char *args, char **
return false; return false;
} }
if (global->proxy == NULL) { if (global->proxy == NULL) {
if (!bind_global(rd, global, error)) if (bind_global(rd, global, error) < 0)
return false; return false;
} }
@ -1980,7 +1984,7 @@ static bool do_permissions(struct data *data, const char *cmd, char *args, char
return false; return false;
} }
if (global->proxy == NULL) { if (global->proxy == NULL) {
if (!bind_global(rd, global, error)) if (bind_global(rd, global, error) < 0)
return false; return false;
} }
@ -2019,7 +2023,7 @@ static bool do_get_permissions(struct data *data, const char *cmd, char *args, c
return false; return false;
} }
if (global->proxy == NULL) { if (global->proxy == NULL) {
if (!bind_global(rd, global, error)) if (bind_global(rd, global, error) < 0)
return false; return false;
} }
pw_client_get_permissions((struct pw_client*)global->proxy, pw_client_get_permissions((struct pw_client*)global->proxy,
@ -2053,7 +2057,7 @@ static bool do_send_command(struct data *data, const char *cmd, char *args, char
return false; return false;
} }
if (global->proxy == NULL) { if (global->proxy == NULL) {
if (!bind_global(rd, global, error)) if (bind_global(rd, global, error) < 0)
return false; return false;
} }
@ -2299,6 +2303,7 @@ static void input_process_line(char *line)
#endif #endif
if (!parse(d, line, &error)) { if (!parse(d, line, &error)) {
fprintf(stderr, "Error: \"%s\"\n", error); fprintf(stderr, "Error: \"%s\"\n", error);
d->res = -EINVAL;
free(error); free(error);
} }
} }
@ -2520,6 +2525,7 @@ int main(int argc, char *argv[])
if (!parse(&data, ptr, &error)) { if (!parse(&data, ptr, &error)) {
fprintf(stderr, "Error: \"%s\"\n", error); fprintf(stderr, "Error: \"%s\"\n", error);
data.res = -EINVAL;
free(error); free(error);
} }
free(ptr); free(ptr);
@ -2541,5 +2547,5 @@ int main(int argc, char *argv[])
pw_map_clear(&data.vars); pw_map_clear(&data.vars);
pw_deinit(); pw_deinit();
return 0; return data.res == 0 ? 0 : -1;
} }