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