exec: fix validation during config reload

Split cmd_exec_always into separate methods for general validation and
process creation. This fixes a potential call of join_args with 0 arguments.
This commit is contained in:
Konstantin Pospelov 2020-08-23 13:59:22 +02:00 committed by Simon Ser
parent 6991ac8c70
commit fd216b3a81
3 changed files with 27 additions and 6 deletions

View file

@ -97,6 +97,12 @@ void container_resize_tiled(struct sway_container *parent, uint32_t axis,
struct sway_container *container_find_resize_parent(struct sway_container *con, struct sway_container *container_find_resize_parent(struct sway_container *con,
uint32_t edge); uint32_t edge);
/**
* Handlers shared by exec and exec_always.
*/
sway_cmd cmd_exec_validate;
sway_cmd cmd_exec_process;
sway_cmd cmd_assign; sway_cmd cmd_assign;
sway_cmd cmd_bar; sway_cmd cmd_bar;
sway_cmd cmd_bindcode; sway_cmd cmd_bindcode;

View file

@ -5,12 +5,15 @@
#include "stringop.h" #include "stringop.h"
struct cmd_results *cmd_exec(int argc, char **argv) { struct cmd_results *cmd_exec(int argc, char **argv) {
if (!config->active) return cmd_results_new(CMD_DEFER, NULL); struct cmd_results *error = NULL;
if ((error = cmd_exec_validate(argc, argv))) {
return error;
}
if (config->reloading) { if (config->reloading) {
char *args = join_args(argv, argc); char *args = join_args(argv, argc);
sway_log(SWAY_DEBUG, "Ignoring 'exec %s' due to reload", args); sway_log(SWAY_DEBUG, "Ignoring 'exec %s' due to reload", args);
free(args); free(args);
return cmd_results_new(CMD_SUCCESS, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
return cmd_exec_always(argc, argv); return cmd_exec_process(argc, argv);
} }

View file

@ -13,15 +13,19 @@
#include "log.h" #include "log.h"
#include "stringop.h" #include "stringop.h"
struct cmd_results *cmd_exec_always(int argc, char **argv) { struct cmd_results *cmd_exec_validate(int argc, char **argv) {
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
if (!config->active || config->validating) {
return cmd_results_new(CMD_DEFER, NULL);
}
if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) { if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) {
return error; return error;
} }
if (!config->active || config->validating) {
return cmd_results_new(CMD_DEFER, NULL);
}
return error;
}
struct cmd_results *cmd_exec_process(int argc, char **argv) {
struct cmd_results *error = NULL;
char *tmp = NULL; char *tmp = NULL;
if (strcmp(argv[0], "--no-startup-id") == 0) { if (strcmp(argv[0], "--no-startup-id") == 0) {
sway_log(SWAY_INFO, "exec switch '--no-startup-id' not supported, ignored."); sway_log(SWAY_INFO, "exec switch '--no-startup-id' not supported, ignored.");
@ -92,3 +96,11 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *cmd_exec_always(int argc, char **argv) {
struct cmd_results *error;
if ((error = cmd_exec_validate(argc, argv))) {
return error;
}
return cmd_exec_process(argc, argv);
}