use switch for fork()

save two local variables and improve readability by a bit
xkbcommon
Alessandro Mauri 4 years ago
parent 45c52ecf20
commit 922090060f
  1. 21
      macrod.c

@ -265,7 +265,6 @@ int pressBufferRemove (struct pressed_buffer *pb, unsigned short key)
return 0; return 0;
} }
} }
return 1; return 1;
} }
@ -283,14 +282,18 @@ void die (void)
void execCommand (const char *path) void execCommand (const char *path)
{ {
pid_t child_pid = fork(); switch (fork()) {
if (child_pid == -1) die(); case -1:
// TODO: communication between parent and child about process status/errors/etc fprintf(stderr, "Could not fork: %s", strerror(errno));
if (!child_pid) { break;
/* we are the child */ case 0:
int ret = 0; /* we are the child */
ret = execl(path, path, (char *) NULL); if(execl(path, path, (char *) NULL) != 0)
if (ret != 0) /* execl only returns if an error occured, so we exit
* otherwise we duplicate the process */
exit(-1); exit(-1);
/* we shouldn't be here */
break;
} }
// TODO: communication between parent and child about process status/errors/etc
} }

Loading…
Cancel
Save