mirror of
https://github.com/swaywm/sway.git
synced 2024-11-10 20:44:01 +01:00
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:
parent
6991ac8c70
commit
fd216b3a81
@ -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,
|
||||
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_bar;
|
||||
sway_cmd cmd_bindcode;
|
||||
|
@ -5,12 +5,15 @@
|
||||
#include "stringop.h"
|
||||
|
||||
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) {
|
||||
char *args = join_args(argv, argc);
|
||||
sway_log(SWAY_DEBUG, "Ignoring 'exec %s' due to reload", args);
|
||||
free(args);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||
}
|
||||
return cmd_exec_always(argc, argv);
|
||||
return cmd_exec_process(argc, argv);
|
||||
}
|
||||
|
@ -13,15 +13,19 @@
|
||||
#include "log.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;
|
||||
if (!config->active || config->validating) {
|
||||
return cmd_results_new(CMD_DEFER, NULL);
|
||||
}
|
||||
if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) {
|
||||
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;
|
||||
if (strcmp(argv[0], "--no-startup-id") == 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user