Skip to content

Commit

Permalink
Fix exec_before/after leaving a zombie process behind
Browse files Browse the repository at this point in the history
  • Loading branch information
junglerobba authored and emersion committed Sep 1, 2021
1 parent 5f5a29c commit 9ef1d6a
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/screencast/screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,30 @@ static const char object_path[] = "/org/freedesktop/portal/desktop";
static const char interface_name[] = "org.freedesktop.impl.portal.ScreenCast";

void exec_with_shell(char *command) {
pid_t pid = fork();
if (pid < 0) {
pid_t pid1 = fork();
if (pid1 < 0) {
perror("fork");
} else if (pid == 0) {
char *const argv[] = {
"sh",
"-c",
command,
NULL,
};
execvp("sh", argv);

perror("execvp");
exit(127);
return;
} else if (pid1 == 0) {
pid_t pid2 = fork();
if (pid2 < 0) {
perror("fork");
} else if (pid2 == 0) {
char *const argv[] = {
"sh",
"-c",
command,
NULL,
};
execvp("sh", argv);
perror("execvp");
_exit(127);
}
_exit(0);
}
int stat;
if (waitpid(pid1, &stat, 0) < 0) {
perror("waitpid");
}
}

Expand Down

0 comments on commit 9ef1d6a

Please sign in to comment.