mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-12-18 22:14:20 +01:00
Prevent killing unexpected process
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 <https://github.com/Genymobile/scrcpy/issues/182>.
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
pid_t cmd_execute(const char *path, const char *const argv[]) {
|
pid_t cmd_execute(const char *path, const char *const argv[]) {
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
@@ -20,6 +22,10 @@ pid_t cmd_execute(const char *path, const char *const argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_bool cmd_terminate(pid_t pid) {
|
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;
|
return kill(pid, SIGTERM) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user