diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-12-15 17:39:09 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-12-15 19:01:40 -0500 |
commit | 248df18c24d2a849de984b477ca3913ce7c72441 (patch) | |
tree | 35beb85ecfcc54574d3b5e82c8445eb8c1219689 /sway/commands/exec_always.c | |
parent | Handle border-related malloc failures (diff) | |
download | sway-248df18c24d2a849de984b477ca3913ce7c72441.tar.gz sway-248df18c24d2a849de984b477ca3913ce7c72441.tar.zst sway-248df18c24d2a849de984b477ca3913ce7c72441.zip |
Handle allocation failure in commands
Diffstat (limited to 'sway/commands/exec_always.c')
-rw-r--r-- | sway/commands/exec_always.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index 157d4872..1d7cd494 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c | |||
@@ -39,6 +39,9 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
39 | 39 | ||
40 | pid_t pid; | 40 | pid_t pid; |
41 | pid_t *child = malloc(sizeof(pid_t)); // malloc'd so that Linux can avoid copying the process space | 41 | pid_t *child = malloc(sizeof(pid_t)); // malloc'd so that Linux can avoid copying the process space |
42 | if (!child) { | ||
43 | return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate child pid"); | ||
44 | } | ||
42 | // Fork process | 45 | // Fork process |
43 | if ((pid = fork()) == 0) { | 46 | if ((pid = fork()) == 0) { |
44 | // Fork child process again | 47 | // Fork child process again |
@@ -56,7 +59,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
56 | _exit(0); // Close child process | 59 | _exit(0); // Close child process |
57 | } else if (pid < 0) { | 60 | } else if (pid < 0) { |
58 | free(child); | 61 | free(child); |
59 | return cmd_results_new(CMD_FAILURE, "exec_always", "Command failed (sway could not fork)."); | 62 | return cmd_results_new(CMD_FAILURE, "exec_always", "fork() failed"); |
60 | } | 63 | } |
61 | close(fd[1]); // close write | 64 | close(fd[1]); // close write |
62 | ssize_t s = 0; | 65 | ssize_t s = 0; |
@@ -73,8 +76,6 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
73 | pw->pid = child; | 76 | pw->pid = child; |
74 | pw->workspace = strdup(ws->name); | 77 | pw->workspace = strdup(ws->name); |
75 | pid_workspace_add(pw); | 78 | pid_workspace_add(pw); |
76 | // TODO: keep track of this pid and open the corresponding view on the current workspace | ||
77 | // blocked pending feature in wlc | ||
78 | } else { | 79 | } else { |
79 | free(child); | 80 | free(child); |
80 | } | 81 | } |