diff options
author | Erik Troan <ewt@redhat.com> | 1997-09-16 14:12:05 +0000 |
---|---|---|
committer | Erik Troan <ewt@redhat.com> | 1997-09-16 14:12:05 +0000 |
commit | ced9dffda28f1ec2b060f3e419cf3c6b964b03a1 (patch) | |
tree | da3f56c24861ddc77e2910291c71adc12dca136b /src/netreport.c | |
download | initscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.tar initscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.tar.gz initscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.tar.bz2 initscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.tar.xz initscripts-ced9dffda28f1ec2b060f3e419cf3c6b964b03a1.zip |
Initial revision
Diffstat (limited to 'src/netreport.c')
-rw-r--r-- | src/netreport.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/netreport.c b/src/netreport.c new file mode 100644 index 00000000..56088ec1 --- /dev/null +++ b/src/netreport.c @@ -0,0 +1,45 @@ +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +/* this will be running setgid root, so be careful! */ + +void usage(void) { + fprintf(stderr, "usage: netreport [-r]\n"); + exit(1); +} + +#define ADD 1 +#define DEL 0 +int main(int argc, char ** argv) { + int action = ADD; + /* more than long enough for "/var/run/netreport/<pid>\0" */ + char netreport_name[64]; + int netreport_file; + + if (argc > 2) usage(); + + if ((argc > 1) && !strcmp(argv[1], "-r")) { + action = DEL; + } + + sprintf(netreport_name, "/var/run/netreport/%d", getppid()); + if (action == ADD) { + netreport_file = creat(netreport_name, 0); + if (netreport_file < 0) { + if (errno != EEXIST) { + perror("Could not create netreport file"); + exit (1); + } + } else { + close(netreport_file); + } + } else { + /* ignore errors; not much we can do, won't hurt anything */ + unlink(netreport_name); + } + + exit(0); +} |