]> git.pld-linux.org Git - projects/rc-scripts.git/blob - src/netreport.c
Synced with 0.0.4
[projects/rc-scripts.git] / src / netreport.c
1 #include <errno.h>
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <unistd.h>
6
7 /* this will be running setgid root, so be careful! */
8
9 void usage(void) {
10     fprintf(stderr, "usage: netreport [-r]\n");
11     exit(1);
12 }
13
14 #define ADD 1
15 #define DEL 0
16 int main(int argc, char ** argv) {
17     int action = ADD;
18     /* more than long enough for "/var/run/netreport/<pid>\0" */
19     char netreport_name[64];
20     int  netreport_file;
21
22     if (argc > 2) usage();
23
24     if ((argc > 1) && !strcmp(argv[1], "-r")) {
25         action = DEL;
26     }
27
28     sprintf(netreport_name, "/var/run/netreport/%d", getppid());
29     if (action == ADD) {
30         netreport_file = creat(netreport_name, 0);
31         if (netreport_file < 0) {
32             if (errno != EEXIST) {
33                 perror("Could not create netreport file");
34                 exit (1);
35             }
36         } else {
37             close(netreport_file);
38         }
39     } else {
40         /* ignore errors; not much we can do, won't hurt anything */
41         unlink(netreport_name);
42     }
43
44     exit(0);
45 }
This page took 0.059891 seconds and 3 git commands to generate.