For SNAT, don't store the pre-fragment L2 header before actions are applied.
[sliver-openvswitch.git] / utilities / ofp-kill.c
index 4518ad7..0ad0434 100644 (file)
@@ -43,6 +43,7 @@
 #include "daemon.h"
 #include "timeval.h"
 #include "util.h"
+#include "vlog.h"
 
 /* -s, --signal: signal to send. */
 static int sig_nr = SIGTERM;
@@ -51,7 +52,6 @@ static int sig_nr = SIGTERM;
 static bool force;
 
 static void cond_error(int err_no, const char *, ...) PRINTF_FORMAT(2, 3);
-static bool kill_pidfile(const char *pidfile, FILE *);
 
 static void parse_options(int argc, char *argv[]);
 static void usage(void);
@@ -64,6 +64,7 @@ main(int argc, char *argv[])
 
     set_program_name(argv[0]);
     time_init();
+    vlog_init();
     parse_options(argc, argv);
 
     argc -= optind;
@@ -77,16 +78,16 @@ main(int argc, char *argv[])
 
     for (i = 0; i < argc; i++) {
         char *pidfile;
-        FILE *file;
+        pid_t pid;
 
         pidfile = make_pidfile_name(argv[i]);
-        file = fopen(pidfile, "r");
-        if (!file) {
-            ok = false;
-            cond_error(errno, "%s: open", pidfile);
+        pid = read_pidfile(pidfile);
+        if (pid >= 0) {
+            if (kill(pid, sig_nr) < 0) {
+                cond_error(errno, "%s: kill(%ld)", pidfile, (long int) pid);
+            }
         } else {
-            ok = kill_pidfile(argv[i], file) && ok;
-            fclose(file);
+            cond_error(-pid, "could not read %s", pidfile);
         }
         free(pidfile);
     }
@@ -94,40 +95,6 @@ main(int argc, char *argv[])
     return ok || force ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-static bool
-kill_pidfile(const char *pidfile, FILE *file)
-{
-    char line[128];
-    struct flock lck;
-
-    lck.l_type = F_WRLCK;
-    lck.l_whence = SEEK_SET;
-    lck.l_start = 0;
-    lck.l_len = 0;
-    if (fcntl(fileno(file), F_GETLK, &lck)) {
-        cond_error(errno, "%s: fcntl", pidfile); 
-        return false;
-    }
-
-    if (!fgets(line, sizeof line, file)) {
-        cond_error(errno, "%s: read", pidfile);
-        return false;
-    }
-
-    if (lck.l_pid != strtoul(line, NULL, 10)) {
-        cond_error(errno, "l_pid (%ld) != %s pid (%s)",
-                   (long int) lck.l_pid, pidfile, line);
-        return false;
-    }
-
-    if (kill(lck.l_pid, sig_nr) < 0) {
-        cond_error(errno, "%s: kill(%ld)", pidfile, (long int) lck.l_pid);
-        return false;
-    }
-
-    return true;
-}
-
 static void
 parse_options(int argc, char *argv[])
 {
@@ -215,7 +182,8 @@ parse_options(int argc, char *argv[])
             usage();
 
         case 'V':
-            printf("%s "VERSION" compiled "__DATE__" "__TIME__"\n", argv[0]);
+            printf("%s %s compiled "__DATE__" "__TIME__"\n",
+                   program_name, VERSION BUILDNR);
             exit(EXIT_SUCCESS);
 
         case '?':