diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/sway/commands.c b/sway/commands.c index bbf0bde2..f2ee0184 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -179,7 +179,7 @@ static enum cmd_status cmd_bindsym(int argc, char **argv) { | |||
179 | } | 179 | } |
180 | 180 | ||
181 | static enum cmd_status cmd_exec_always(int argc, char **argv) { | 181 | static enum cmd_status cmd_exec_always(int argc, char **argv) { |
182 | if (!config->active) return CMD_DEFER;; | 182 | if (!config->active) return CMD_DEFER; |
183 | if (!checkarg(argc, "exec_always", EXPECTED_MORE_THAN, 0)) { | 183 | if (!checkarg(argc, "exec_always", EXPECTED_MORE_THAN, 0)) { |
184 | return CMD_FAILURE; | 184 | return CMD_FAILURE; |
185 | } | 185 | } |
@@ -190,27 +190,21 @@ static enum cmd_status cmd_exec_always(int argc, char **argv) { | |||
190 | free(tmp); | 190 | free(tmp); |
191 | 191 | ||
192 | char *args[] = {"sh", "-c", cmd, 0 }; | 192 | char *args[] = {"sh", "-c", cmd, 0 }; |
193 | sway_log(L_DEBUG, "Executing %s", cmd); | ||
193 | 194 | ||
194 | pid_t pid = vfork(); | 195 | pid_t pid; |
195 | /* Failed to fork */ | 196 | if ((pid = vfork()) == 0) { |
196 | if (pid < 0) { | ||
197 | sway_log(L_ERROR, "exec command failed, sway did not fork"); | ||
198 | return CMD_FAILURE; | ||
199 | } | ||
200 | /* Child process */ | ||
201 | if (pid == 0) { | ||
202 | sway_log(L_DEBUG, "Executing %s", cmd); | ||
203 | execv("/bin/sh", args); | 197 | execv("/bin/sh", args); |
204 | /* Execv doesnt return unless failure */ | ||
205 | sway_log(L_ERROR, "execv failde to return"); | ||
206 | _exit(-1); | 198 | _exit(-1); |
199 | } else if (pid < 0) { | ||
200 | sway_log(L_ERROR, "exec command failed, sway could not fork"); | ||
201 | return CMD_FAILURE; | ||
207 | } | 202 | } |
208 | /* Parent */ | ||
209 | return CMD_SUCCESS; | 203 | return CMD_SUCCESS; |
210 | } | 204 | } |
211 | 205 | ||
212 | static enum cmd_status cmd_exec(int argc, char **argv) { | 206 | static enum cmd_status cmd_exec(int argc, char **argv) { |
213 | if (!config->active) return CMD_DEFER;; | 207 | if (!config->active) return CMD_DEFER; |
214 | 208 | ||
215 | if (config->reloading) { | 209 | if (config->reloading) { |
216 | char *args = join_args(argv, argc); | 210 | char *args = join_args(argv, argc); |
@@ -228,8 +222,8 @@ static void kill_views(swayc_t *container, void *data) { | |||
228 | } | 222 | } |
229 | 223 | ||
230 | static enum cmd_status cmd_exit(int argc, char **argv) { | 224 | static enum cmd_status cmd_exit(int argc, char **argv) { |
231 | if (!checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0) | 225 | if (config->reading) return CMD_INVALID; |
232 | || config->reading || !config->active) { | 226 | if (!checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0)) { |
233 | return CMD_FAILURE; | 227 | return CMD_FAILURE; |
234 | } | 228 | } |
235 | // Close all views | 229 | // Close all views |
@@ -239,8 +233,8 @@ static enum cmd_status cmd_exit(int argc, char **argv) { | |||
239 | } | 233 | } |
240 | 234 | ||
241 | static enum cmd_status cmd_floating(int argc, char **argv) { | 235 | static enum cmd_status cmd_floating(int argc, char **argv) { |
242 | if (!checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1) | 236 | if (config->reading) return CMD_INVALID; |
243 | || config->reading || !config->active) { | 237 | if (!checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1)) { |
244 | return CMD_FAILURE; | 238 | return CMD_FAILURE; |
245 | } | 239 | } |
246 | 240 | ||
@@ -301,8 +295,8 @@ static enum cmd_status cmd_floating(int argc, char **argv) { | |||
301 | } | 295 | } |
302 | 296 | ||
303 | static enum cmd_status cmd_floating_mod(int argc, char **argv) { | 297 | static enum cmd_status cmd_floating_mod(int argc, char **argv) { |
304 | if (!checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1) | 298 | if (!config->reading) return CMD_INVALID; |
305 | || !config->reading) { | 299 | if (!checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1)) { |
306 | return CMD_FAILURE; | 300 | return CMD_FAILURE; |
307 | } | 301 | } |
308 | int i, j; | 302 | int i, j; |
@@ -326,10 +320,10 @@ static enum cmd_status cmd_floating_mod(int argc, char **argv) { | |||
326 | } | 320 | } |
327 | 321 | ||
328 | static enum cmd_status cmd_focus(int argc, char **argv) { | 322 | static enum cmd_status cmd_focus(int argc, char **argv) { |
323 | if (config->reading) return CMD_INVALID; | ||
329 | static int floating_toggled_index = 0; | 324 | static int floating_toggled_index = 0; |
330 | static int tiled_toggled_index = 0; | 325 | static int tiled_toggled_index = 0; |
331 | if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1) | 326 | if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { |
332 | || config->reading || !config->active) { | ||
333 | return CMD_FAILURE; | 327 | return CMD_FAILURE; |
334 | } | 328 | } |
335 | if (strcasecmp(argv[0], "left") == 0) { | 329 | if (strcasecmp(argv[0], "left") == 0) { |
@@ -384,6 +378,7 @@ static enum cmd_status cmd_focus(int argc, char **argv) { | |||
384 | } | 378 | } |
385 | 379 | ||
386 | static enum cmd_status cmd_focus_follows_mouse(int argc, char **argv) { | 380 | static enum cmd_status cmd_focus_follows_mouse(int argc, char **argv) { |
381 | if (!config->reading) return CMD_INVALID; | ||
387 | if (!checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1)) { | 382 | if (!checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1)) { |
388 | return CMD_FAILURE; | 383 | return CMD_FAILURE; |
389 | } | 384 | } |
@@ -393,7 +388,7 @@ static enum cmd_status cmd_focus_follows_mouse(int argc, char **argv) { | |||
393 | } | 388 | } |
394 | 389 | ||
395 | static void hide_view_in_scratchpad(swayc_t *sp_view) { | 390 | static void hide_view_in_scratchpad(swayc_t *sp_view) { |
396 | if(sp_view == NULL) { | 391 | if (sp_view == NULL) { |
397 | return; | 392 | return; |
398 | } | 393 | } |
399 | 394 | ||
@@ -416,7 +411,7 @@ static enum cmd_status cmd_mode(int argc, char **argv) { | |||
416 | int mode_len = strlen(mode_name); | 411 | int mode_len = strlen(mode_name); |
417 | bool mode_make = mode_name[mode_len-1] == '{'; | 412 | bool mode_make = mode_name[mode_len-1] == '{'; |
418 | if (mode_make) { | 413 | if (mode_make) { |
419 | if (!config->reading) return CMD_FAILURE;; | 414 | if (!config->reading) return CMD_INVALID; |
420 | // Trim trailing spaces | 415 | // Trim trailing spaces |
421 | do { | 416 | do { |
422 | mode_name[--mode_len] = 0; | 417 | mode_name[--mode_len] = 0; |
@@ -454,7 +449,7 @@ static enum cmd_status cmd_mode(int argc, char **argv) { | |||
454 | } | 449 | } |
455 | 450 | ||
456 | static enum cmd_status cmd_move(int argc, char **argv) { | 451 | static enum cmd_status cmd_move(int argc, char **argv) { |
457 | if (config->reading) return CMD_FAILURE;; | 452 | if (config->reading) return CMD_FAILURE; |
458 | if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) { | 453 | if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) { |
459 | return CMD_FAILURE; | 454 | return CMD_FAILURE; |
460 | } | 455 | } |
@@ -525,7 +520,7 @@ static enum cmd_status cmd_move(int argc, char **argv) { | |||
525 | } | 520 | } |
526 | 521 | ||
527 | static enum cmd_status cmd_orientation(int argc, char **argv) { | 522 | static enum cmd_status cmd_orientation(int argc, char **argv) { |
528 | if (!config->reading) return CMD_FAILURE;; | 523 | if (!config->reading) return CMD_FAILURE; |
529 | if (!checkarg(argc, "orientation", EXPECTED_EQUAL_TO, 1)) { | 524 | if (!checkarg(argc, "orientation", EXPECTED_EQUAL_TO, 1)) { |
530 | return CMD_FAILURE; | 525 | return CMD_FAILURE; |
531 | } | 526 | } |
@@ -543,7 +538,7 @@ static enum cmd_status cmd_orientation(int argc, char **argv) { | |||
543 | } | 538 | } |
544 | 539 | ||
545 | static enum cmd_status cmd_output(int argc, char **argv) { | 540 | static enum cmd_status cmd_output(int argc, char **argv) { |
546 | if (!config->reading) return CMD_FAILURE;; | 541 | if (!config->reading) return CMD_FAILURE; |
547 | if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) { | 542 | if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) { |
548 | return CMD_FAILURE; | 543 | return CMD_FAILURE; |
549 | } | 544 | } |
@@ -994,7 +989,7 @@ static enum cmd_status cmd_log_colors(int argc, char **argv) { | |||
994 | } | 989 | } |
995 | if (strcasecmp(argv[0], "no") == 0) { | 990 | if (strcasecmp(argv[0], "no") == 0) { |
996 | sway_log_colors(0); | 991 | sway_log_colors(0); |
997 | } else if(strcasecmp(argv[0], "yes") == 0) { | 992 | } else if (strcasecmp(argv[0], "yes") == 0) { |
998 | sway_log_colors(1); | 993 | sway_log_colors(1); |
999 | } else { | 994 | } else { |
1000 | sway_log(L_ERROR, "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); | 995 | sway_log(L_ERROR, "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); |