-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 19bfb52
Showing
5 changed files
with
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pact | ||
*.o |
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,19 @@ | ||
Copyright (c) 2015 Robert Norris. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,9 @@ | ||
CFLAGS=-Wall -Werror -O2 | ||
|
||
all: pact | ||
|
||
pact: pact.o | ||
$(CC) -o pact pact.o | ||
|
||
clean: | ||
rm -f pact *.o |
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,23 @@ | ||
# pact | ||
|
||
This runs another program in such a way that when the calling process dies, a | ||
`SIGTERM` is delivered to the program. | ||
|
||
This is useful in command pipelines, shells, process managers and other | ||
situations where an intermediate process recieves a signal and dies, causing | ||
its children to be reattached to PID 1. | ||
|
||
## running | ||
|
||
```bash | ||
$ make | ||
$ ./pact [-N] path/to/command | ||
``` | ||
|
||
## options | ||
|
||
* `-N` - signal number to send. Default is 15 (`SIGTERM`). | ||
|
||
## credits and license | ||
|
||
Copyright (c) 2015 Robert Norris. MIT license. See LICENSE. |
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,25 @@ | ||
#include <sys/prctl.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#include <stdio.h> | ||
|
||
int main(int argc, char **argv) { | ||
if(argc < 2) | ||
return 1; | ||
int cmd = 1; | ||
int signo = 0; | ||
if (*argv[1] == '-') { | ||
signo = atoi(argv[1] + 1); | ||
if (argc < 3) | ||
return 1; | ||
cmd = 2; | ||
} | ||
if (!signo) | ||
signo = 15; | ||
if (prctl(PR_SET_PDEATHSIG, signo, 0, 0, 0) < 0) { | ||
perror("prctl"); | ||
return 1; | ||
} | ||
return execvp(argv[cmd], &argv[cmd]); | ||
} |