aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <ddevault@linode.com>2016-04-29 10:59:43 -0400
committerLibravatar Drew DeVault <ddevault@linode.com>2016-04-29 10:59:43 -0400
commitebdce719b4497302d373c065dd88f1071e907b5f (patch)
treef5cfaccfc2905946c6174fca539bf2b4fbd9cbc2
parentAdd -Werror to C flags (diff)
downloadsway-ebdce719b4497302d373c065dd88f1071e907b5f.tar.gz
sway-ebdce719b4497302d373c065dd88f1071e907b5f.tar.zst
sway-ebdce719b4497302d373c065dd88f1071e907b5f.zip
Fix -Wunused-result problems
-rw-r--r--sway/commands.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/sway/commands.c b/sway/commands.c
index c1390016..3092239c 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -509,7 +509,9 @@ static struct cmd_results *cmd_exec_always(int argc, char **argv) {
509 sway_log(L_DEBUG, "Executing %s", cmd); 509 sway_log(L_DEBUG, "Executing %s", cmd);
510 510
511 int fd[2]; 511 int fd[2];
512 pipe(fd); 512 if (pipe(fd) != 0) {
513 sway_log(L_ERROR, "Unable to create pipe for fork");
514 }
513 515
514 pid_t pid; 516 pid_t pid;
515 pid_t *child = malloc(sizeof(pid_t)); // malloc'd so that Linux can avoid copying the process space 517 pid_t *child = malloc(sizeof(pid_t)); // malloc'd so that Linux can avoid copying the process space
@@ -522,14 +524,20 @@ static struct cmd_results *cmd_exec_always(int argc, char **argv) {
522 /* Not reached */ 524 /* Not reached */
523 } 525 }
524 close(fd[0]); 526 close(fd[0]);
525 write(fd[1], child, sizeof(pid_t)); 527 ssize_t s = 0;
528 while ((size_t)s < sizeof(pid_t)) {
529 s += write(fd[1], ((uint8_t *)child) + s, sizeof(pid_t));
530 }
526 close(fd[1]); 531 close(fd[1]);
527 _exit(0); // Close child process 532 _exit(0); // Close child process
528 } else if (pid < 0) { 533 } else if (pid < 0) {
529 return cmd_results_new(CMD_FAILURE, "exec_always", "Command failed (sway could not fork)."); 534 return cmd_results_new(CMD_FAILURE, "exec_always", "Command failed (sway could not fork).");
530 } 535 }
531 close(fd[1]); // close write 536 close(fd[1]); // close write
532 read(fd[0], child, sizeof(pid_t)); 537 ssize_t s = 0;
538 while ((size_t)s < sizeof(pid_t)) {
539 s += read(fd[0], ((uint8_t *)child) + s, sizeof(pid_t));
540 }
533 close(fd[0]); 541 close(fd[0]);
534 // cleanup child process 542 // cleanup child process
535 wait(0); 543 wait(0);