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 "
}
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;
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
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) {
* 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;
}
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;
}
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;
}
* 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;
}
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,
}
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_);
}
}
}
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_);
}
}
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;