]> git.proxmox.com Git - mirror_ovs.git/blobdiff - lib/daemon-unix.c
odp-execute: Rename 'may_steal' to 'should_steal'.
[mirror_ovs.git] / lib / daemon-unix.c
index 967a2843251f6a793436e49cff9b55f56d49c4e1..3ad1c62889cf893ea479541ad217ffa7b9f265bc 100644 (file)
@@ -537,6 +537,8 @@ daemon_usage(void)
     printf(
         "\nDaemon options:\n"
         "  --detach                run in background as daemon\n"
+        "  --monitor               creates a process to monitor this daemon\n"
+        "  --user=username[:group] changes the effective daemon user:group\n"
         "  --no-chdir              do not chdir to '/'\n"
         "  --pidfile[=FILE]        create pidfile (default: %s/%s.pid)\n"
         "  --overwrite-pidfile     with --pidfile, start even if already "
@@ -570,7 +572,7 @@ lock_pidfile(FILE *file, int command)
 }
 
 static pid_t
-read_pidfile__(const char *pidfile, bool delete_if_stale)
+read_pidfile__(const char *pidfile_, bool delete_if_stale)
 {
     struct stat s, s2;
     struct flock lck;
@@ -579,7 +581,7 @@ read_pidfile__(const char *pidfile, bool delete_if_stale)
     int error;
 
     if ((pidfile_ino || pidfile_dev)
-        && !stat(pidfile, &s)
+        && !stat(pidfile_, &s)
         && s.st_ino == pidfile_ino && s.st_dev == pidfile_dev) {
         /* It's our own pidfile.  We can't afford to open it, because closing
          * *any* fd for a file that a process has locked also releases all the
@@ -589,19 +591,19 @@ read_pidfile__(const char *pidfile, bool delete_if_stale)
         return getpid();
     }
 
-    file = fopen(pidfile, "r+");
+    file = fopen(pidfile_, "r+");
     if (!file) {
         if (errno == ENOENT && delete_if_stale) {
             return 0;
         }
         error = errno;
-        VLOG_WARN("%s: open: %s", pidfile, ovs_strerror(error));
+        VLOG_WARN("%s: open: %s", pidfile_, ovs_strerror(error));
         goto error;
     }
 
     error = lock_pidfile__(file, F_GETLK, &lck);
     if (error) {
-        VLOG_WARN("%s: fcntl: %s", pidfile, ovs_strerror(error));
+        VLOG_WARN("%s: fcntl: %s", pidfile_, ovs_strerror(error));
         goto error;
     }
     if (lck.l_type == F_UNLCK) {
@@ -614,7 +616,7 @@ read_pidfile__(const char *pidfile, bool delete_if_stale)
          * pidfile locked, and only that process has the right to unlink it. */
         if (!delete_if_stale) {
             error = ESRCH;
-            VLOG_DBG("%s: pid file is stale", pidfile);
+            VLOG_DBG("%s: pid file is stale", pidfile_);
             goto error;
         }
 
@@ -622,28 +624,28 @@ read_pidfile__(const char *pidfile, bool delete_if_stale)
         error = lock_pidfile(file, F_SETLK);
         if (error) {
             /* We lost a race with someone else doing the same thing. */
-            VLOG_WARN("%s: lost race to lock pidfile", pidfile);
+            VLOG_WARN("%s: lost race to lock pidfile", pidfile_);
             goto error;
         }
 
-        /* Is the file we have locked still named 'pidfile'? */
-        if (stat(pidfile, &s) || fstat(fileno(file), &s2)
+        /* Is the file we have locked still named 'pidfile_'? */
+        if (stat(pidfile_, &s) || fstat(fileno(file), &s2)
             || s.st_ino != s2.st_ino || s.st_dev != s2.st_dev) {
             /* No.  We lost a race with someone else who got the lock before
              * us, deleted the pidfile, and closed it (releasing the lock). */
             error = EALREADY;
-            VLOG_WARN("%s: lost race to delete pidfile", pidfile);
+            VLOG_WARN("%s: lost race to delete pidfile", pidfile_);
             goto error;
         }
 
         /* We won the right to delete the stale pidfile. */
-        if (unlink(pidfile)) {
+        if (unlink(pidfile_)) {
             error = errno;
             VLOG_WARN("%s: failed to delete stale pidfile (%s)",
-                      pidfile, ovs_strerror(error));
+                      pidfile_, ovs_strerror(error));
             goto error;
         }
-        VLOG_DBG("%s: deleted stale pidfile", pidfile);
+        VLOG_DBG("%s: deleted stale pidfile", pidfile_);
         fclose(file);
         return 0;
     }
@@ -651,10 +653,10 @@ read_pidfile__(const char *pidfile, bool delete_if_stale)
     if (!fgets(line, sizeof line, file)) {
         if (ferror(file)) {
             error = errno;
-            VLOG_WARN("%s: read: %s", pidfile, ovs_strerror(error));
+            VLOG_WARN("%s: read: %s", pidfile_, ovs_strerror(error));
         } else {
             error = ESRCH;
-            VLOG_WARN("%s: read: unexpected end of file", pidfile);
+            VLOG_WARN("%s: read: unexpected end of file", pidfile_);
         }
         goto error;
     }
@@ -665,7 +667,7 @@ read_pidfile__(const char *pidfile, bool delete_if_stale)
          * preparing to delete it. */
         error = ESRCH;
         VLOG_WARN("%s: stale pidfile for pid %s being deleted by pid %ld",
-                  pidfile, line, (long int) lck.l_pid);
+                  pidfile_, line, (long int) lck.l_pid);
         goto error;
     }
 
@@ -679,12 +681,12 @@ error:
     return -error;
 }
 
-/* Opens and reads a PID from 'pidfile'.  Returns the positive PID if
+/* Opens and reads a PID from 'pidfile_'.  Returns the positive PID if
  * successful, otherwise a negative errno value. */
 pid_t
-read_pidfile(const char *pidfile)
+read_pidfile(const char *pidfile_)
 {
-    return read_pidfile__(pidfile, false);
+    return read_pidfile__(pidfile_, false);
 }
 
 /* Checks whether a process with the given 'pidfile' is already running and,
@@ -728,22 +730,22 @@ gid_matches(gid_t expected, gid_t value)
 }
 
 static bool
-gid_verify(gid_t gid)
+gid_verify(gid_t gid_)
 {
     gid_t r, e;
 
     r = getgid();
     e = getegid();
-    return (gid_matches(gid, r) &&
-            gid_matches(gid, e));
+    return (gid_matches(gid_, r) &&
+            gid_matches(gid_, e));
 }
 
 static void
-daemon_switch_group(gid_t gid)
+daemon_switch_group(gid_t gid_)
 {
-    if ((setgid(gid) == -1) || !gid_verify(gid)) {
+    if ((setgid(gid_) == -1) || !gid_verify(gid_)) {
         VLOG_FATAL("%s: fail to switch group to gid as %d, aborting",
-                   pidfile, gid);
+                   pidfile, gid_);
     }
 }
 
@@ -754,22 +756,22 @@ uid_matches(uid_t expected, uid_t value)
 }
 
 static bool
-uid_verify(const uid_t uid)
+uid_verify(const uid_t uid_)
 {
     uid_t r, e;
 
     r = getuid();
     e = geteuid();
-    return (uid_matches(uid, r) &&
-            uid_matches(uid, e));
+    return (uid_matches(uid_, r) &&
+            uid_matches(uid_, e));
 }
 
 static void
-daemon_switch_user(const uid_t uid, const char *user)
+daemon_switch_user(const uid_t uid_, const char *user_)
 {
-    if ((setuid(uid) == -1) || !uid_verify(uid)) {
+    if ((setuid(uid_) == -1) || !uid_verify(uid_)) {
         VLOG_FATAL("%s: fail to switch user to %s, aborting",
-                   pidfile, user);
+                   pidfile, user_);
     }
 }
 
@@ -818,7 +820,8 @@ daemon_become_new_user_linux(bool access_datapath OVS_UNUSED)
 
             if (access_datapath && !ret) {
                 ret = capng_update(CAPNG_ADD, cap_sets, CAP_NET_ADMIN)
-                      || capng_update(CAPNG_ADD, cap_sets, CAP_NET_RAW);
+                      || capng_update(CAPNG_ADD, cap_sets, CAP_NET_RAW)
+                      || capng_update(CAPNG_ADD, cap_sets, CAP_NET_BROADCAST);
             }
         } else {
             ret = -1;