Skip to content

Commit

Permalink
Prevent killing unexpected process
Browse files Browse the repository at this point in the history
A missing initialization (fixed by the previous commit) leaded to kill
unexpected process.

In order to prevent consequences of similar errors in the future, never
call kill() with a non-positive PID.

See <#182>.
  • Loading branch information
rom1v committed Jun 22, 2018
1 parent 1a01393 commit 1846d2f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/src/sys/unix/command.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "command.h"

#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "log.h"

pid_t cmd_execute(const char *path, const char *const argv[]) {
pid_t pid = fork();
Expand All @@ -20,6 +22,10 @@ pid_t cmd_execute(const char *path, const char *const argv[]) {
}

SDL_bool cmd_terminate(pid_t pid) {
if (pid <= 0) {
LOGC("Requested to kill %d, this is an error. Please report the bug.\n", (int) pid);
abort();
}
return kill(pid, SIGTERM) != -1;
}

Expand Down

0 comments on commit 1846d2f

Please sign in to comment.