From 248df18c24d2a849de984b477ca3913ce7c72441 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 15 Dec 2016 17:39:09 -0500 Subject: Handle allocation failure in commands --- sway/commands/exec_always.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'sway/commands/exec_always.c') 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) { pid_t pid; pid_t *child = malloc(sizeof(pid_t)); // malloc'd so that Linux can avoid copying the process space + if (!child) { + return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate child pid"); + } // Fork process if ((pid = fork()) == 0) { // Fork child process again @@ -56,7 +59,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { _exit(0); // Close child process } else if (pid < 0) { free(child); - return cmd_results_new(CMD_FAILURE, "exec_always", "Command failed (sway could not fork)."); + return cmd_results_new(CMD_FAILURE, "exec_always", "fork() failed"); } close(fd[1]); // close write ssize_t s = 0; @@ -73,8 +76,6 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { pw->pid = child; pw->workspace = strdup(ws->name); pid_workspace_add(pw); - // TODO: keep track of this pid and open the corresponding view on the current workspace - // blocked pending feature in wlc } else { free(child); } -- cgit v1.2.3