-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/prctl.h> | ||
#include <signal.h> | ||
|
||
/* | ||
preexec_fn is not safe to use in the presence of threads, | ||
child process could deadlock before exec is called. | ||
this little shim is a workaround to avoid using preexe_fn and | ||
still get the desired behavior (PR_SET_PDEATHSIG). | ||
*/ | ||
int main(int argc, char *argv[]) { | ||
if (argc < 2) { | ||
fprintf(stderr, "Usage: %s /path/to/binary [args...]\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
if (prctl(PR_SET_PDEATHSIG, SIGKILL) == -1) { | ||
perror("prctl"); | ||
return 1; | ||
} | ||
|
||
execvp(argv[1], &argv[1]); | ||
|
||
perror("execvp"); | ||
return 1; | ||
} |