Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
robn committed Nov 2, 2015
0 parents commit 19bfb52
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pact
*.o
19 changes: 19 additions & 0 deletions LICENSE
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.
9 changes: 9 additions & 0 deletions Makefile
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
23 changes: 23 additions & 0 deletions README.md
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.
25 changes: 25 additions & 0 deletions pact.c
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]);
}

0 comments on commit 19bfb52

Please sign in to comment.