aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c11
-rw-r--r--sway/commands/assign.c1
-rw-r--r--sway/commands/bar/font.c2
-rw-r--r--sway/commands/bar/modifier.c5
-rw-r--r--sway/commands/input/accel_profile.c1
-rw-r--r--sway/commands/input/click_method.c1
-rw-r--r--sway/commands/input/drag_lock.c1
-rw-r--r--sway/commands/input/dwt.c1
-rw-r--r--sway/commands/input/events.c1
-rw-r--r--sway/commands/input/left_handed.c1
-rw-r--r--sway/commands/input/map_from_region.c8
-rw-r--r--sway/commands/input/middle_emulation.c1
-rw-r--r--sway/commands/input/natural_scroll.c1
-rw-r--r--sway/commands/input/pointer_accel.c1
-rw-r--r--sway/commands/input/repeat_delay.c1
-rw-r--r--sway/commands/input/repeat_rate.c1
-rw-r--r--sway/commands/input/scroll_method.c1
-rw-r--r--sway/commands/input/tap.c1
-rw-r--r--sway/commands/output/background.c3
-rw-r--r--sway/commands/output/mode.c2
-rw-r--r--sway/commands/output/position.c2
-rw-r--r--sway/config.c16
-rw-r--r--sway/config/bar.c25
-rw-r--r--sway/desktop/transaction.c4
-rw-r--r--sway/ipc-server.c60
-rw-r--r--sway/main.c2
-rw-r--r--sway/tree/workspace.c16
27 files changed, 110 insertions, 60 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 5b20857a..5b67e1ec 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -428,8 +428,7 @@ struct cmd_results *config_commands_command(char *exec) {
struct cmd_handler *handler = find_handler(cmd, NULL, 0);
if (!handler && strcmp(cmd, "*") != 0) {
- char *input = cmd ? cmd : "(empty)";
- results = cmd_results_new(CMD_INVALID, input, "Unknown/invalid command");
+ results = cmd_results_new(CMD_INVALID, cmd, "Unknown/invalid command");
goto cleanup;
}
@@ -471,10 +470,12 @@ struct cmd_results *config_commands_command(char *exec) {
}
if (!policy) {
policy = alloc_command_policy(cmd);
- sway_assert(policy, "Unable to allocate security policy");
- if (policy) {
- list_add(config->command_policies, policy);
+ if (!sway_assert(policy, "Unable to allocate security policy")) {
+ results = cmd_results_new(CMD_INVALID, cmd,
+ "Unable to allocate memory");
+ goto cleanup;
}
+ list_add(config->command_policies, policy);
}
policy->context = context;
diff --git a/sway/commands/assign.c b/sway/commands/assign.c
index 9d15e166..a90498ce 100644
--- a/sway/commands/assign.c
+++ b/sway/commands/assign.c
@@ -27,6 +27,7 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
if (strncmp(*argv, "→", strlen("→")) == 0) {
if (argc < 3) {
+ free(criteria);
return cmd_results_new(CMD_INVALID, "assign", "Missing workspace");
}
++argv;
diff --git a/sway/commands/bar/font.c b/sway/commands/bar/font.c
index 80b7a593..f036cbc3 100644
--- a/sway/commands/bar/font.c
+++ b/sway/commands/bar/font.c
@@ -14,7 +14,7 @@ struct cmd_results *bar_cmd_font(int argc, char **argv) {
}
char *font = join_args(argv, argc);
free(config->current_bar->font);
- config->current_bar->font = strdup(font);
+ config->current_bar->font = font;
wlr_log(L_DEBUG, "Settings font '%s' for bar: %s",
config->current_bar->font, config->current_bar->id);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c
index 7ba4b125..02f845e6 100644
--- a/sway/commands/bar/modifier.c
+++ b/sway/commands/bar/modifier.c
@@ -22,9 +22,10 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
mod |= tmp_mod;
continue;
} else {
+ error = cmd_results_new(CMD_INVALID, "modifier",
+ "Unknown modifier '%s'", split->items[i]);
free_flat_list(split);
- return cmd_results_new(CMD_INVALID, "modifier",
- "Unknown modifier '%s'", split->items[i]);
+ return error;
}
}
free_flat_list(split);
diff --git a/sway/commands/input/accel_profile.c b/sway/commands/input/accel_profile.c
index 37d6e133..a4108ec3 100644
--- a/sway/commands/input/accel_profile.c
+++ b/sway/commands/input/accel_profile.c
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_accel_profile(int argc, char **argv) {
} else if (strcasecmp(argv[0], "flat") == 0) {
new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "accel_profile",
"Expected 'accel_profile <adaptive|flat>'");
}
diff --git a/sway/commands/input/click_method.c b/sway/commands/input/click_method.c
index 8f1f0aa7..5d0d8cc2 100644
--- a/sway/commands/input/click_method.c
+++ b/sway/commands/input/click_method.c
@@ -26,6 +26,7 @@ struct cmd_results *input_cmd_click_method(int argc, char **argv) {
} else if (strcasecmp(argv[0], "clickfinger") == 0) {
new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "click_method",
"Expected 'click_method <none|button_areas|clickfinger'");
}
diff --git a/sway/commands/input/drag_lock.c b/sway/commands/input/drag_lock.c
index 8273a7d4..9e32816f 100644
--- a/sway/commands/input/drag_lock.c
+++ b/sway/commands/input/drag_lock.c
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) {
} else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "drag_lock",
"Expected 'drag_lock <enabled|disabled>'");
}
diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c
index 995a2f47..73937507 100644
--- a/sway/commands/input/dwt.c
+++ b/sway/commands/input/dwt.c
@@ -22,6 +22,7 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) {
} else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "dwt",
"Expected 'dwt <enabled|disabled>'");
}
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c
index 2217f5ce..e2ccdc94 100644
--- a/sway/commands/input/events.c
+++ b/sway/commands/input/events.c
@@ -29,6 +29,7 @@ struct cmd_results *input_cmd_events(int argc, char **argv) {
new_config->send_events =
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "events",
"Expected 'events <enabled|disabled|disabled_on_external_mouse>'");
}
diff --git a/sway/commands/input/left_handed.c b/sway/commands/input/left_handed.c
index 94b8e03e..769ce98c 100644
--- a/sway/commands/input/left_handed.c
+++ b/sway/commands/input/left_handed.c
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_left_handed(int argc, char **argv) {
} else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->left_handed = 0;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "left_handed",
"Expected 'left_handed <enabled|disabled>'");
}
diff --git a/sway/commands/input/map_from_region.c b/sway/commands/input/map_from_region.c
index 80bb856d..40f04214 100644
--- a/sway/commands/input/map_from_region.c
+++ b/sway/commands/input/map_from_region.c
@@ -54,20 +54,28 @@ struct cmd_results *input_cmd_map_from_region(int argc, char **argv) {
bool mm1, mm2;
if (!parse_coords(argv[0], &new_config->mapped_from_region->x1,
&new_config->mapped_from_region->y1, &mm1)) {
+ free(new_config->mapped_from_region);
+ free_input_config(new_config);
return cmd_results_new(CMD_FAILURE, "map_from_region",
"Invalid top-left coordinates");
}
if (!parse_coords(argv[1], &new_config->mapped_from_region->x2,
&new_config->mapped_from_region->y2, &mm2)) {
+ free(new_config->mapped_from_region);
+ free_input_config(new_config);
return cmd_results_new(CMD_FAILURE, "map_from_region",
"Invalid bottom-right coordinates");
}
if (new_config->mapped_from_region->x1 > new_config->mapped_from_region->x2 ||
new_config->mapped_from_region->y1 > new_config->mapped_from_region->y2) {
+ free(new_config->mapped_from_region);
+ free_input_config(new_config);
return cmd_results_new(CMD_FAILURE, "map_from_region",
"Invalid rectangle");
}
if (mm1 != mm2) {
+ free(new_config->mapped_from_region);
+ free_input_config(new_config);
return cmd_results_new(CMD_FAILURE, "map_from_region",
"Both coordinates must be in the same unit");
}
diff --git a/sway/commands/input/middle_emulation.c b/sway/commands/input/middle_emulation.c
index a551fd51..7ca01629 100644
--- a/sway/commands/input/middle_emulation.c
+++ b/sway/commands/input/middle_emulation.c
@@ -24,6 +24,7 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) {
new_config->middle_emulation =
LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "middle_emulation",
"Expected 'middle_emulation <enabled|disabled>'");
}
diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c
index c4e19b78..55236790 100644
--- a/sway/commands/input/natural_scroll.c
+++ b/sway/commands/input/natural_scroll.c
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {
} else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->natural_scroll = 0;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "natural_scroll",
"Expected 'natural_scroll <enabled|disabled>'");
}
diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c
index 171063aa..8bbd0724 100644
--- a/sway/commands/input/pointer_accel.c
+++ b/sway/commands/input/pointer_accel.c
@@ -20,6 +20,7 @@ struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) {
float pointer_accel = atof(argv[0]);
if (pointer_accel < -1 || pointer_accel > 1) {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "pointer_accel",
"Input out of range [-1, 1]");
}
diff --git a/sway/commands/input/repeat_delay.c b/sway/commands/input/repeat_delay.c
index ce265841..c9ddbf0e 100644
--- a/sway/commands/input/repeat_delay.c
+++ b/sway/commands/input/repeat_delay.c
@@ -20,6 +20,7 @@ struct cmd_results *input_cmd_repeat_delay(int argc, char **argv) {
int repeat_delay = atoi(argv[0]);
if (repeat_delay < 0) {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "repeat_delay",
"Repeat delay cannot be negative");
}
diff --git a/sway/commands/input/repeat_rate.c b/sway/commands/input/repeat_rate.c
index f2ea2e69..56878176 100644
--- a/sway/commands/input/repeat_rate.c
+++ b/sway/commands/input/repeat_rate.c
@@ -20,6 +20,7 @@ struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) {
int repeat_rate = atoi(argv[0]);
if (repeat_rate < 0) {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "repeat_rate",
"Repeat rate cannot be negative");
}
diff --git a/sway/commands/input/scroll_method.c b/sway/commands/input/scroll_method.c
index 0a1c57ac..4c6ac6b6 100644
--- a/sway/commands/input/scroll_method.c
+++ b/sway/commands/input/scroll_method.c
@@ -27,6 +27,7 @@ struct cmd_results *input_cmd_scroll_method(int argc, char **argv) {
} else if (strcasecmp(argv[0], "on_button_down") == 0) {
new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "scroll_method",
"Expected 'scroll_method <none|two_finger|edge|on_button_down>'");
}
diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c
index e7f03058..7d027d5d 100644
--- a/sway/commands/input/tap.c
+++ b/sway/commands/input/tap.c
@@ -23,6 +23,7 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) {
} else if (strcasecmp(argv[0], "disabled") == 0) {
new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED;
} else {
+ free_input_config(new_config);
return cmd_results_new(CMD_INVALID, "tap",
"Expected 'tap <enabled|disabled>'");
}
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c
index 55cbdff0..65b5f902 100644
--- a/sway/commands/output/background.c
+++ b/sway/commands/output/background.c
@@ -81,8 +81,9 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
// src file is inside configuration dir
char *conf = strdup(config->current_config);
- if(!conf) {
+ if (!conf) {
wlr_log(L_ERROR, "Failed to duplicate string");
+ free(src);
return cmd_results_new(CMD_FAILURE, "output",
"Unable to allocate resources");
}
diff --git a/sway/commands/output/mode.c b/sway/commands/output/mode.c
index daec6d44..ef56ae9e 100644
--- a/sway/commands/output/mode.c
+++ b/sway/commands/output/mode.c
@@ -36,11 +36,11 @@ struct cmd_results *output_cmd_mode(int argc, char **argv) {
}
} else {
// Format is 1234 4321
+ argc--; argv++;
if (!argc) {
return cmd_results_new(CMD_INVALID, "output",
"Missing mode argument (height).");
}
- argc--; argv++;
output->height = strtol(*argv, &end, 10);
if (*end) {
return cmd_results_new(CMD_INVALID, "output",
diff --git a/sway/commands/output/position.c b/sway/commands/output/position.c
index c2aeb281..449767b1 100644
--- a/sway/commands/output/position.c
+++ b/sway/commands/output/position.c
@@ -27,11 +27,11 @@ struct cmd_results *output_cmd_position(int argc, char **argv) {
}
} else {
// Format is 1234 4321 (legacy)
+ argc--; argv++;
if (!argc) {
return cmd_results_new(CMD_INVALID, "output",
"Missing position argument (y).");
}
- argc--; argv++;
config->handler_context.output_config->y = strtol(*argv, &end, 10);
if (*end) {
return cmd_results_new(CMD_INVALID, "output",
diff --git a/sway/config.c b/sway/config.c
index 12a02163..0aae1696 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -302,6 +302,11 @@ static char *get_config_path(void) {
const char *current_config_path;
static bool load_config(const char *path, struct sway_config *config) {
+ if (path == NULL) {
+ wlr_log(L_ERROR, "Unable to find a config file!");
+ return false;
+ }
+
wlr_log(L_INFO, "Loading config from %s", path);
current_config_path = path;
@@ -310,11 +315,6 @@ static bool load_config(const char *path, struct sway_config *config) {
return false;
}
- if (path == NULL) {
- wlr_log(L_ERROR, "Unable to find a config file!");
- return false;
- }
-
FILE *f = fopen(path, "r");
if (!f) {
wlr_log(L_ERROR, "Unable to open %s for reading", path);
@@ -425,7 +425,7 @@ static bool load_include_config(const char *path, const char *parent_dir,
// save parent config
const char *parent_config = config->current_config;
- char *full_path = strdup(path);
+ char *full_path;
int len = strlen(path);
if (len >= 1 && path[0] != '/') {
len = len + strlen(parent_dir) + 2;
@@ -436,6 +436,8 @@ static bool load_include_config(const char *path, const char *parent_dir,
return false;
}
snprintf(full_path, len, "%s/%s", parent_dir, path);
+ } else {
+ full_path = strdup(path);
}
char *real_path = realpath(full_path, NULL);
@@ -583,6 +585,8 @@ bool read_config(FILE *file, struct sway_config *config) {
}
char *expanded = expand_line(block, line, brace_detected > 0);
if (!expanded) {
+ list_foreach(stack, free);
+ list_free(stack);
return false;
}
wlr_log(L_DEBUG, "Expanded line: %s", expanded);
diff --git a/sway/config/bar.c b/sway/config/bar.c
index 5a97c3cc..b97076a0 100644
--- a/sway/config/bar.c
+++ b/sway/config/bar.c
@@ -70,16 +70,12 @@ void free_bar_config(struct bar_config *bar) {
struct bar_config *default_bar_config(void) {
struct bar_config *bar = NULL;
- bar = malloc(sizeof(struct bar_config));
+ bar = calloc(1, sizeof(struct bar_config));
if (!bar) {
return NULL;
}
- if (!(bar->mode = strdup("dock"))) goto cleanup;
- if (!(bar->hidden_state = strdup("hide"))) goto cleanup;
bar->outputs = NULL;
bar->position = strdup("bottom");
- if (!(bar->bindings = create_list())) goto cleanup;
- if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup;
bar->pango_markup = false;
bar->swaybar_command = NULL;
bar->font = NULL;
@@ -91,6 +87,19 @@ struct bar_config *default_bar_config(void) {
bar->binding_mode_indicator = true;
bar->verbose = false;
bar->pid = 0;
+ if (!(bar->mode = strdup("dock"))) {
+ goto cleanup;
+ }
+ if (!(bar->hidden_state = strdup("hide"))) {
+ goto cleanup;
+ }
+ if (!(bar->bindings = create_list())) {
+ goto cleanup;
+ }
+ if (!(bar->status_command =
+ strdup("while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done"))) {
+ goto cleanup;
+ }
// set default colors
if (!(bar->colors.background = strndup("#000000ff", 9))) {
goto cleanup;
@@ -174,7 +183,7 @@ void invoke_swaybar(struct bar_config *bar) {
if (!command) {
const char msg[] = "Unable to allocate swaybar command string";
size_t msg_len = sizeof(msg);
- if (write(filedes[1], &msg_len, sizeof(int))) {};
+ if (write(filedes[1], &msg_len, sizeof(size_t))) {};
if (write(filedes[1], msg, msg_len)) {};
close(filedes[1]);
exit(1);
@@ -189,8 +198,8 @@ void invoke_swaybar(struct bar_config *bar) {
}
wlr_log(L_DEBUG, "Spawned swaybar %d", bar->pid);
close(filedes[0]);
- ssize_t len;
- if (read(filedes[1], &len, sizeof(int)) == sizeof(int)) {
+ size_t len;
+ if (read(filedes[1], &len, sizeof(size_t)) == sizeof(size_t)) {
char *buf = malloc(len);
if(!buf) {
wlr_log(L_ERROR, "Cannot allocate error string");
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index e5ceae61..7b670aec 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -187,8 +187,8 @@ static void transaction_apply(struct sway_transaction *transaction) {
(now.tv_nsec - commit->tv_nsec) / 1000000.0;
float ms_total = ms_arranging + ms_waiting;
wlr_log(L_DEBUG, "Transaction %p: %.1fms arranging, %.1fms waiting, "
- "%.1fms total (%.1f frames if 60Hz)", transaction,
- ms_arranging, ms_waiting, ms_total, ms_total / (1000 / 60));
+ "%.1fms total (%.1f frames if 60Hz)", transaction,
+ ms_arranging, ms_waiting, ms_total, ms_total / (1000.0f / 60));
}
// Apply the instruction state to the container's current state
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 241fe742..3e510c2e 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -263,7 +263,10 @@ static void ipc_send_event(const char *json_string, enum ipc_command_type event)
client->current_command = event;
if (!ipc_send_reply(client, json_string, (uint32_t) strlen(json_string))) {
wlr_log_errno(L_INFO, "Unable to send reply to IPC client");
- ipc_client_disconnect(client);
+ /* ipc_send_reply destroys client on error, which also
+ * removes it from the list, so we need to process
+ * current index again */
+ i--;
}
}
}
@@ -383,9 +386,7 @@ void ipc_client_disconnect(struct ipc_client *client) {
return;
}
- if (client->fd != -1) {
- shutdown(client->fd, SHUT_RDWR);
- }
+ shutdown(client->fd, SHUT_RDWR);
wlr_log(L_INFO, "IPC Client %d disconnected", client->fd);
wl_event_source_remove(client->event_source);
@@ -465,8 +466,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
}
buf[client->payload_length] = '\0';
- const char *error_denied = "{ \"success\": false, \"error\": \"Permission denied\" }";
-
+ bool client_valid = true;
switch (client->current_command) {
case IPC_COMMAND:
{
@@ -474,7 +474,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
const char *json = cmd_results_to_json(results);
char reply[256];
int length = snprintf(reply, sizeof(reply), "%s", json);
- ipc_send_reply(client, reply, (uint32_t) length);
+ client_valid = ipc_send_reply(client, reply, (uint32_t)length);
free_cmd_results(results);
goto exit_cleanup;
}
@@ -497,7 +497,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
}
}
const char *json_string = json_object_to_json_string(outputs);
- ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
+ client_valid =
+ ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
json_object_put(outputs); // free
goto exit_cleanup;
}
@@ -508,7 +509,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
container_for_each_descendant_dfs(&root_container,
ipc_get_workspaces_callback, workspaces);
const char *json_string = json_object_to_json_string(workspaces);
- ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
+ client_valid =
+ ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
json_object_put(workspaces); // free
goto exit_cleanup;
}
@@ -518,7 +520,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
// TODO: Check if they're permitted to use these events
struct json_object *request = json_tokener_parse(buf);
if (request == NULL) {
- ipc_send_reply(client, "{\"success\": false}", 18);
+ client_valid = ipc_send_reply(client, "{\"success\": false}", 18);
wlr_log_errno(L_INFO, "Failed to read request");
goto exit_cleanup;
}
@@ -539,7 +541,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
} else if (strcmp(event_type, "binding") == 0) {
client->subscribed_events |= event_mask(IPC_EVENT_BINDING);
} else {
- ipc_send_reply(client, "{\"success\": false}", 18);
+ client_valid =
+ ipc_send_reply(client, "{\"success\": false}", 18);
json_object_put(request);
wlr_log_errno(L_INFO, "Failed to parse request");
goto exit_cleanup;
@@ -547,7 +550,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
}
json_object_put(request);
- ipc_send_reply(client, "{\"success\": true}", 17);
+ client_valid = ipc_send_reply(client, "{\"success\": true}", 17);
goto exit_cleanup;
}
@@ -559,7 +562,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
json_object_array_add(inputs, ipc_json_describe_input(device));
}
const char *json_string = json_object_to_json_string(inputs);
- ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
+ client_valid =
+ ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
json_object_put(inputs); // free
goto exit_cleanup;
}
@@ -572,7 +576,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
json_object_array_add(seats, ipc_json_describe_seat(seat));
}
const char *json_string = json_object_to_json_string(seats);
- ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
+ client_valid =
+ ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
json_object_put(seats); // free
goto exit_cleanup;
}
@@ -582,7 +587,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
json_object *tree =
ipc_json_describe_container_recursive(&root_container);
const char *json_string = json_object_to_json_string(tree);
- ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
+ client_valid =
+ ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
json_object_put(tree);
goto exit_cleanup;
}
@@ -593,7 +599,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
container_descendants(&root_container, C_VIEW, ipc_get_marks_callback,
marks);
const char *json_string = json_object_to_json_string(marks);
- ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
+ client_valid =
+ ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
json_object_put(marks);
goto exit_cleanup;
}
@@ -602,7 +609,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
{
json_object *version = ipc_json_get_version();
const char *json_string = json_object_to_json_string(version);
- ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
+ client_valid =
+ ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
json_object_put(version); // free
goto exit_cleanup;
}
@@ -617,7 +625,9 @@ void ipc_client_handle_command(struct ipc_client *client) {
json_object_array_add(bars, json_object_new_string(bar->id));
}
const char *json_string = json_object_to_json_string(bars);
- ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
+ client_valid =
+ ipc_send_reply(client, json_string,
+ (uint32_t)strlen(json_string));
json_object_put(bars); // free
} else {
// Send particular bar's details
@@ -631,12 +641,15 @@ void ipc_client_handle_command(struct ipc_client *client) {
}
if (!bar) {
const char *error = "{ \"success\": false, \"error\": \"No bar with that ID\" }";
- ipc_send_reply(client, error, (uint32_t)strlen(error));
+ client_valid =
+ ipc_send_reply(client, error, (uint32_t)strlen(error));
goto exit_cleanup;
}
json_object *json = ipc_json_describe_bar_config(bar);
const char *json_string = json_object_to_json_string(json);
- ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
+ client_valid =
+ ipc_send_reply(client, json_string,
+ (uint32_t)strlen(json_string));
json_object_put(json); // free
}
goto exit_cleanup;
@@ -647,11 +660,10 @@ void ipc_client_handle_command(struct ipc_client *client) {
goto exit_cleanup;
}
- ipc_send_reply(client, error_denied, (uint32_t)strlen(error_denied));
- wlr_log(L_DEBUG, "Denied IPC client access to %i", client->current_command);
-
exit_cleanup:
- client->payload_length = 0;
+ if (client_valid) {
+ client->payload_length = 0;
+ }
free(buf);
return;
}
diff --git a/sway/main.c b/sway/main.c
index a325dc3a..124f9fbb 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -175,7 +175,7 @@ static void log_kernel() {
}
free(line);
}
- fclose(f);
+ pclose(f);
}
static void security_sanity_check() {
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 5eb4be0f..2db06a31 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -109,7 +109,6 @@ static bool workspace_valid_on_output(const char *output_name,
char *workspace_next_name(const char *output_name) {
wlr_log(L_DEBUG, "Workspace: Generating new workspace name for output %s",
output_name);
- int l = 1;
// Scan all workspace bindings to find the next available workspace name,
// if none are found/available then default to a number
struct sway_mode *mode = config->current_mode;
@@ -202,14 +201,9 @@ char *workspace_next_name(const char *output_name) {
// As a fall back, get the current number of active workspaces
// and return that + 1 for the next workspace's name
int ws_num = root_container.children->length;
- if (ws_num >= 10) {
- l = 2;
- } else if (ws_num >= 100) {
- l = 3;
- }
+ int l = snprintf(NULL, 0, "%d", ws_num);
char *name = malloc(l + 1);
- if (!name) {
- wlr_log(L_ERROR, "Could not allocate workspace name");
+ if (!sway_assert(name, "Cloud not allocate workspace name")) {
return NULL;
}
sprintf(name, "%d", ws_num++);
@@ -271,6 +265,9 @@ struct sway_container *workspace_by_name(const char *name) {
*/
struct sway_container *workspace_output_prev_next_impl(
struct sway_container *output, bool next) {
+ if (!output) {
+ return NULL;
+ }
if (!sway_assert(output->type == C_OUTPUT,
"Argument must be an output, is %d", output->type)) {
return NULL;
@@ -303,6 +300,9 @@ struct sway_container *workspace_output_prev_next_impl(
*/
struct sway_container *workspace_prev_next_impl(
struct sway_container *workspace, bool next) {
+ if (!workspace) {
+ return NULL;
+ }
if (!sway_assert(workspace->type == C_WORKSPACE,
"Argument must be a workspace, is %d", workspace->type)) {
return NULL;