]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - src/netreport.c
- merge from TOTALNEW branch (see NEWS for more info)
[projects/rc-scripts.git] / src / netreport.c
index f708e58bea04961126e74988915f9bee194a5ba6..cceedc3a8576cc1315529d1c2c9ffc2a2727f934 100644 (file)
@@ -1,14 +1,14 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <libintl.h>
-#include <locale.h>
 
 /* this will be running setgid root, so be careful! */
 
-void usage(void) {
+static void
+usage(void) {
     fprintf(stderr, "usage: netreport [-r]\n");
     exit(1);
 }
@@ -21,16 +21,24 @@ int main(int argc, char ** argv) {
     char netreport_name[64];
     int  netreport_file;
 
-    if (argc > 2) usage();
+    if (argc > 2) {
+       usage();
+    }
 
-    if ((argc > 1) && !strcmp(argv[1], "-r")) {
-       action = DEL;
+    if (argc > 1) {
+         if (strcmp(argv[1], "-r") == 0) {
+                 action = DEL;
+         } else {
+                 usage();
+         }
     }
 
-    sprintf(netreport_name, "/var/run/netreport/%d", getppid());
+    snprintf(netreport_name, sizeof(netreport_name),
+            "/var/run/netreport/%d", getppid());
     if (action == ADD) {
-       netreport_file = creat(netreport_name, 0);
-       if (netreport_file < 0) {
+       netreport_file = open(netreport_name,
+                             O_EXCL|O_CREAT|O_WRONLY|O_TRUNC|O_NOFOLLOW, 0);
+       if (netreport_file == -1) {
            if (errno != EEXIST) {
                perror("Could not create netreport file");
                exit (1);
@@ -43,5 +51,5 @@ int main(int argc, char ** argv) {
        unlink(netreport_name);
     }
 
-    exit(0);
+    return 0;
 }
This page took 0.02443 seconds and 4 git commands to generate.