2007-10-08 11:07:39 +00:00
|
|
|
/*
|
2015-12-04 16:52:19 -06:00
|
|
|
* rc-misc.c
|
|
|
|
* rc misc functions
|
|
|
|
*/
|
2007-10-08 11:07:39 +00:00
|
|
|
|
2008-01-14 05:05:22 +00:00
|
|
|
/*
|
2015-12-04 16:52:19 -06:00
|
|
|
* Copyright (c) 2007-2015 The OpenRC Authors.
|
|
|
|
* See the Authors file at the top-level directory of this distribution and
|
|
|
|
* https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
2007-11-14 15:22:04 +00:00
|
|
|
*
|
2015-12-04 16:52:19 -06:00
|
|
|
* This file is part of OpenRC. It is subject to the license terms in
|
|
|
|
* the LICENSE file found in the top-level directory of this
|
|
|
|
* distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
|
|
|
* This file may not be copied, modified, propagated, or distributed
|
|
|
|
* except according to the terms contained in the LICENSE file.
|
2007-11-14 15:22:04 +00:00
|
|
|
*/
|
|
|
|
|
2009-04-17 22:55:11 +00:00
|
|
|
#include <sys/file.h>
|
2007-10-09 12:52:09 +00:00
|
|
|
#include <sys/types.h>
|
2008-03-16 17:00:56 +00:00
|
|
|
#include <sys/utsname.h>
|
2007-10-09 12:52:09 +00:00
|
|
|
|
2007-10-08 11:07:39 +00:00
|
|
|
#ifdef __linux__
|
2009-04-23 21:31:22 +00:00
|
|
|
# include <sys/sysinfo.h>
|
2007-10-08 11:07:39 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-23 14:06:31 -06:00
|
|
|
#include <sys/time.h>
|
2007-11-23 12:04:11 +00:00
|
|
|
#include <ctype.h>
|
2009-04-17 22:55:11 +00:00
|
|
|
#include <fcntl.h>
|
2007-10-08 11:07:39 +00:00
|
|
|
#include <limits.h>
|
2008-02-01 13:20:19 +00:00
|
|
|
#include <signal.h>
|
2007-10-08 11:07:39 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-12-23 14:06:31 -06:00
|
|
|
#include <time.h>
|
2008-03-28 08:42:05 +00:00
|
|
|
#include <unistd.h>
|
2015-12-23 14:06:31 -06:00
|
|
|
#include <utime.h>
|
2007-10-08 11:07:39 +00:00
|
|
|
|
2008-02-01 13:20:19 +00:00
|
|
|
#include "einfo.h"
|
2014-10-23 18:33:27 -04:00
|
|
|
#include "queue.h"
|
2007-10-08 11:07:39 +00:00
|
|
|
#include "rc.h"
|
2008-01-06 13:47:39 +00:00
|
|
|
#include "rc-misc.h"
|
2009-05-23 20:38:12 +01:00
|
|
|
#include "version.h"
|
2007-10-08 11:07:39 +00:00
|
|
|
|
2011-01-17 08:46:41 +00:00
|
|
|
extern char **environ;
|
2007-11-23 12:04:11 +00:00
|
|
|
|
2008-10-10 08:37:21 +00:00
|
|
|
bool
|
|
|
|
rc_conf_yesno(const char *setting)
|
2007-12-06 10:48:00 +00:00
|
|
|
{
|
2008-03-16 17:00:56 +00:00
|
|
|
return rc_yesno(rc_conf_value (setting));
|
2007-11-23 12:04:11 +00:00
|
|
|
}
|
|
|
|
|
2008-03-16 17:00:56 +00:00
|
|
|
static const char *const env_whitelist[] = {
|
2015-07-23 12:25:25 -05:00
|
|
|
"EERROR_QUIET", "EINFO_QUIET",
|
2016-01-04 12:32:16 -06:00
|
|
|
"IN_BACKGROUND", "IN_HOTPLUG",
|
2016-01-13 19:34:22 -06:00
|
|
|
"LANG", "LC_MESSAGES", "TERM",
|
2008-03-16 17:00:56 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2008-10-10 08:37:21 +00:00
|
|
|
void
|
|
|
|
env_filter(void)
|
2007-10-08 11:07:39 +00:00
|
|
|
{
|
2008-03-16 17:00:56 +00:00
|
|
|
RC_STRINGLIST *env_allow;
|
2008-10-10 08:37:21 +00:00
|
|
|
RC_STRINGLIST *profile;
|
2008-03-16 17:00:56 +00:00
|
|
|
RC_STRINGLIST *env_list;
|
|
|
|
RC_STRING *env;
|
2007-10-08 11:07:39 +00:00
|
|
|
char *e;
|
2008-03-16 17:00:56 +00:00
|
|
|
size_t i = 0;
|
2008-01-05 20:43:08 +00:00
|
|
|
|
|
|
|
/* Add the user defined list of vars */
|
2008-10-03 17:50:10 +00:00
|
|
|
env_allow = rc_stringlist_split(rc_conf_value("rc_env_allow"), " ");
|
2011-01-17 19:22:53 +00:00
|
|
|
profile = rc_config_load(RC_PROFILE_ENV);
|
2007-10-08 11:07:39 +00:00
|
|
|
|
2008-09-18 19:46:10 +00:00
|
|
|
/* Copy the env and work from this so we can manipulate it safely */
|
2008-03-16 17:00:56 +00:00
|
|
|
env_list = rc_stringlist_new();
|
2008-10-03 17:50:10 +00:00
|
|
|
while (environ && environ[i]) {
|
2008-09-18 19:46:10 +00:00
|
|
|
env = rc_stringlist_add(env_list, environ[i++]);
|
|
|
|
e = strchr(env->value, '=');
|
|
|
|
if (e)
|
|
|
|
*e = '\0';
|
|
|
|
}
|
2007-10-08 11:07:39 +00:00
|
|
|
|
2008-03-16 17:00:56 +00:00
|
|
|
TAILQ_FOREACH(env, env_list, entries) {
|
|
|
|
/* Check the whitelist */
|
2008-09-18 19:46:10 +00:00
|
|
|
for (i = 0; env_whitelist[i]; i++) {
|
|
|
|
if (strcmp(env_whitelist[i], env->value) == 0)
|
2008-03-16 17:00:56 +00:00
|
|
|
break;
|
2007-10-08 11:07:39 +00:00
|
|
|
}
|
2008-03-16 17:00:56 +00:00
|
|
|
if (env_whitelist[i])
|
|
|
|
continue;
|
2007-10-08 11:07:39 +00:00
|
|
|
|
2008-03-16 17:00:56 +00:00
|
|
|
/* Check our user defined list */
|
2008-09-18 15:28:20 +00:00
|
|
|
if (rc_stringlist_find(env_allow, env->value))
|
2007-10-08 11:07:39 +00:00
|
|
|
continue;
|
|
|
|
|
2008-03-16 17:00:56 +00:00
|
|
|
/* OK, not allowed! */
|
2008-09-18 19:46:10 +00:00
|
|
|
unsetenv(env->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now add anything missing from the profile */
|
2008-10-10 08:37:21 +00:00
|
|
|
TAILQ_FOREACH(env, profile, entries) {
|
|
|
|
e = strchr(env->value, '=');
|
|
|
|
*e = '\0';
|
|
|
|
if (!getenv(env->value))
|
|
|
|
setenv(env->value, e + 1, 1);
|
2007-10-08 11:07:39 +00:00
|
|
|
}
|
2008-10-10 08:37:21 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_MEMORY
|
2008-03-16 17:00:56 +00:00
|
|
|
rc_stringlist_free(env_list);
|
|
|
|
rc_stringlist_free(env_allow);
|
|
|
|
rc_stringlist_free(profile);
|
2008-10-10 08:37:21 +00:00
|
|
|
#endif
|
2007-10-08 11:07:39 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 08:37:21 +00:00
|
|
|
void
|
|
|
|
env_config(void)
|
2007-10-08 11:07:39 +00:00
|
|
|
{
|
2011-01-17 19:22:53 +00:00
|
|
|
size_t pplen = strlen(RC_PATH_PREFIX);
|
2008-03-16 17:00:56 +00:00
|
|
|
char *path;
|
|
|
|
char *p;
|
|
|
|
char *e;
|
2008-01-22 11:07:39 +00:00
|
|
|
size_t l;
|
2007-10-08 11:07:39 +00:00
|
|
|
struct utsname uts;
|
|
|
|
FILE *fp;
|
2008-03-16 17:00:56 +00:00
|
|
|
char *token;
|
|
|
|
char *np;
|
|
|
|
char *npp;
|
|
|
|
char *tok;
|
2016-01-17 21:43:46 -08:00
|
|
|
const char *sys = rc_sys();
|
2007-10-08 11:07:39 +00:00
|
|
|
char buffer[PATH_MAX];
|
2008-03-16 17:00:56 +00:00
|
|
|
|
|
|
|
/* Ensure our PATH is prefixed with the system locations first
|
|
|
|
for a little extra security */
|
|
|
|
path = getenv("PATH");
|
|
|
|
if (! path)
|
2011-01-17 19:22:53 +00:00
|
|
|
setenv("PATH", RC_PATH_PREFIX, 1);
|
|
|
|
else if (strncmp (RC_PATH_PREFIX, path, pplen) != 0) {
|
2008-03-16 17:00:56 +00:00
|
|
|
l = strlen(path) + pplen + 3;
|
|
|
|
e = p = xmalloc(sizeof(char) * l);
|
2011-01-17 19:22:53 +00:00
|
|
|
p += snprintf(p, l, "%s", RC_PATH_PREFIX);
|
2008-03-16 17:00:56 +00:00
|
|
|
|
2008-10-10 08:37:21 +00:00
|
|
|
/* Now go through the env var and only add bits not in our
|
|
|
|
* PREFIX */
|
2008-03-16 17:00:56 +00:00
|
|
|
while ((token = strsep(&path, ":"))) {
|
2011-01-17 19:22:53 +00:00
|
|
|
np = npp = xstrdup(RC_PATH_PREFIX);
|
2008-03-16 17:00:56 +00:00
|
|
|
while ((tok = strsep(&npp, ":")))
|
|
|
|
if (strcmp(tok, token) == 0)
|
|
|
|
break;
|
|
|
|
if (! tok)
|
|
|
|
p += snprintf(p, l - (p - e), ":%s", token);
|
|
|
|
free (np);
|
|
|
|
}
|
|
|
|
*p++ = '\0';
|
|
|
|
unsetenv("PATH");
|
|
|
|
setenv("PATH", e, 1);
|
|
|
|
free(e);
|
|
|
|
}
|
|
|
|
|
2009-05-23 20:38:12 +01:00
|
|
|
setenv("RC_VERSION", VERSION, 1);
|
|
|
|
setenv("RC_LIBEXECDIR", RC_LIBEXECDIR, 1);
|
2008-03-16 17:00:56 +00:00
|
|
|
setenv("RC_SVCDIR", RC_SVCDIR, 1);
|
2008-04-21 10:29:29 +00:00
|
|
|
setenv("RC_TMPDIR", RC_SVCDIR "/tmp", 1);
|
2008-03-16 17:00:56 +00:00
|
|
|
setenv("RC_BOOTLEVEL", RC_LEVEL_BOOT, 1);
|
|
|
|
e = rc_runlevel_get();
|
|
|
|
setenv("RC_RUNLEVEL", e, 1);
|
|
|
|
free(e);
|
|
|
|
|
2008-03-19 17:11:50 +00:00
|
|
|
if ((fp = fopen(RC_KRUNLEVEL, "r"))) {
|
2008-03-16 17:00:56 +00:00
|
|
|
memset(buffer, 0, sizeof (buffer));
|
|
|
|
if (fgets(buffer, sizeof (buffer), fp)) {
|
2008-01-22 11:07:39 +00:00
|
|
|
l = strlen (buffer) - 1;
|
|
|
|
if (buffer[l] == '\n')
|
|
|
|
buffer[l] = 0;
|
2008-03-16 17:00:56 +00:00
|
|
|
setenv("RC_DEFAULTLEVEL", buffer, 1);
|
2007-10-08 11:07:39 +00:00
|
|
|
}
|
2008-03-16 17:00:56 +00:00
|
|
|
fclose(fp);
|
2007-10-08 11:07:39 +00:00
|
|
|
} else
|
2008-03-16 17:00:56 +00:00
|
|
|
setenv("RC_DEFAULTLEVEL", RC_LEVEL_DEFAULT, 1);
|
|
|
|
|
2016-01-18 23:40:20 -06:00
|
|
|
if (sys)
|
2008-03-16 17:00:56 +00:00
|
|
|
setenv("RC_SYS", sys, 1);
|
2007-10-08 11:07:39 +00:00
|
|
|
|
2012-09-09 22:22:15 -05:00
|
|
|
#ifdef PREFIX
|
|
|
|
setenv("RC_PREFIX", RC_PREFIX, 1);
|
|
|
|
#endif
|
|
|
|
|
2009-04-23 21:31:22 +00:00
|
|
|
/* Some scripts may need to take a different code path if
|
|
|
|
Linux/FreeBSD, etc
|
2007-10-08 11:07:39 +00:00
|
|
|
To save on calling uname, we store it in an environment variable */
|
2008-03-16 17:00:56 +00:00
|
|
|
if (uname(&uts) == 0)
|
|
|
|
setenv("RC_UNAME", uts.sysname, 1);
|
2007-10-08 11:07:39 +00:00
|
|
|
|
2007-12-06 10:48:00 +00:00
|
|
|
/* Be quiet or verbose as necessary */
|
2008-03-16 17:00:56 +00:00
|
|
|
if (rc_conf_yesno("rc_quiet"))
|
|
|
|
setenv("EINFO_QUIET", "YES", 1);
|
|
|
|
if (rc_conf_yesno("rc_verbose"))
|
|
|
|
setenv("EINFO_VERBOSE", "YES", 1);
|
2007-12-06 10:48:00 +00:00
|
|
|
|
|
|
|
errno = 0;
|
2008-03-16 17:00:56 +00:00
|
|
|
if ((! rc_conf_yesno("rc_color") && errno == 0) ||
|
|
|
|
rc_conf_yesno("rc_nocolor"))
|
|
|
|
setenv("EINFO_COLOR", "NO", 1);
|
2007-10-08 11:07:39 +00:00
|
|
|
}
|
2008-01-13 17:47:23 +00:00
|
|
|
|
2008-10-10 08:37:21 +00:00
|
|
|
int
|
|
|
|
signal_setup(int sig, void (*handler)(int))
|
2008-02-01 13:20:19 +00:00
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
|
2008-03-16 17:00:56 +00:00
|
|
|
memset(&sa, 0, sizeof (sa));
|
|
|
|
sigemptyset(&sa.sa_mask);
|
2008-02-02 00:17:35 +00:00
|
|
|
sa.sa_handler = handler;
|
2008-03-16 17:00:56 +00:00
|
|
|
return sigaction(sig, &sa, NULL);
|
2008-02-01 13:20:19 +00:00
|
|
|
}
|
2008-03-28 08:42:05 +00:00
|
|
|
|
2009-04-17 22:55:11 +00:00
|
|
|
int
|
|
|
|
svc_lock(const char *applet)
|
|
|
|
{
|
|
|
|
char file[PATH_MAX];
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
snprintf(file, sizeof(file), RC_SVCDIR "/exclusive/%s", applet);
|
|
|
|
fd = open(file, O_WRONLY | O_CREAT | O_NONBLOCK, 0664);
|
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
|
|
|
if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
svc_unlock(const char *applet, int fd)
|
|
|
|
{
|
|
|
|
char file[PATH_MAX];
|
|
|
|
|
|
|
|
snprintf(file, sizeof(file), RC_SVCDIR "/exclusive/%s", applet);
|
|
|
|
close(fd);
|
|
|
|
unlink(file);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:37:21 +00:00
|
|
|
pid_t
|
|
|
|
exec_service(const char *service, const char *arg)
|
2008-03-28 08:42:05 +00:00
|
|
|
{
|
2009-04-17 22:55:11 +00:00
|
|
|
char *file, sfd[32];
|
|
|
|
int fd;
|
2008-03-28 08:42:05 +00:00
|
|
|
pid_t pid = -1;
|
|
|
|
sigset_t full;
|
|
|
|
sigset_t old;
|
|
|
|
struct sigaction sa;
|
|
|
|
|
2009-04-17 22:55:11 +00:00
|
|
|
fd = svc_lock(basename_c(service));
|
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
2011-01-17 08:28:43 +00:00
|
|
|
|
2008-03-28 08:42:05 +00:00
|
|
|
file = rc_service_resolve(service);
|
2008-10-10 08:37:21 +00:00
|
|
|
if (!exists(file)) {
|
2008-03-28 08:42:05 +00:00
|
|
|
rc_service_mark(service, RC_SERVICE_STOPPED);
|
2009-04-17 22:55:11 +00:00
|
|
|
svc_unlock(basename_c(service), fd);
|
2008-03-28 08:42:05 +00:00
|
|
|
free(file);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-17 22:55:11 +00:00
|
|
|
snprintf(sfd, sizeof(sfd), "%d", fd);
|
2008-03-28 08:42:05 +00:00
|
|
|
|
|
|
|
/* We need to block signals until we have forked */
|
|
|
|
memset(&sa, 0, sizeof (sa));
|
|
|
|
sa.sa_handler = SIG_DFL;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sigfillset(&full);
|
|
|
|
sigprocmask(SIG_SETMASK, &full, &old);
|
|
|
|
|
|
|
|
if ((pid = fork()) == 0) {
|
|
|
|
/* Restore default handlers */
|
|
|
|
sigaction(SIGCHLD, &sa, NULL);
|
|
|
|
sigaction(SIGHUP, &sa, NULL);
|
|
|
|
sigaction(SIGINT, &sa, NULL);
|
|
|
|
sigaction(SIGQUIT, &sa, NULL);
|
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
|
|
|
sigaction(SIGUSR1, &sa, NULL);
|
|
|
|
sigaction(SIGWINCH, &sa, NULL);
|
|
|
|
|
|
|
|
/* Unmask signals */
|
|
|
|
sigprocmask(SIG_SETMASK, &old, NULL);
|
|
|
|
|
|
|
|
/* Safe to run now */
|
2009-04-17 22:55:11 +00:00
|
|
|
execl(file, file, "--lockfd", sfd, arg, (char *) NULL);
|
2008-03-28 08:42:05 +00:00
|
|
|
fprintf(stderr, "unable to exec `%s': %s\n",
|
2009-04-23 21:31:22 +00:00
|
|
|
file, strerror(errno));
|
2009-04-17 22:55:11 +00:00
|
|
|
svc_unlock(basename_c(service), fd);
|
2008-03-28 08:42:05 +00:00
|
|
|
_exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2009-04-18 19:54:04 +00:00
|
|
|
if (pid == -1) {
|
2008-03-28 08:42:05 +00:00
|
|
|
fprintf(stderr, "fork: %s\n",strerror (errno));
|
2009-04-18 19:54:04 +00:00
|
|
|
svc_unlock(basename_c(service), fd);
|
|
|
|
} else
|
|
|
|
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
|
2008-03-28 08:42:05 +00:00
|
|
|
|
|
|
|
sigprocmask(SIG_SETMASK, &old, NULL);
|
|
|
|
free(file);
|
|
|
|
return pid;
|
|
|
|
}
|
2008-08-20 10:02:11 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
parse_mode(mode_t *mode, char *text)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
unsigned long l;
|
|
|
|
|
|
|
|
/* Check for a numeric mode */
|
|
|
|
if ((*text - '0') < 8) {
|
|
|
|
l = strtoul(text, &p, 8);
|
|
|
|
if (*p || l > 07777U) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*mode = (mode_t) l;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We currently don't check g+w type stuff */
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2012-01-26 20:44:33 +01:00
|
|
|
|
|
|
|
int
|
|
|
|
is_writable(const char *path)
|
|
|
|
{
|
|
|
|
if (access(path, W_OK) == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-12-04 18:02:43 -06:00
|
|
|
|
2015-12-23 14:06:31 -06:00
|
|
|
RC_DEPTREE * _rc_deptree_load(int force, int *regen)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int retval;
|
|
|
|
int serrno = errno;
|
|
|
|
int merrno;
|
|
|
|
time_t t;
|
|
|
|
char file[PATH_MAX];
|
|
|
|
struct stat st;
|
|
|
|
struct utimbuf ut;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
t = 0;
|
|
|
|
if (rc_deptree_update_needed(&t, file) || force != 0) {
|
|
|
|
/* Test if we have permission to update the deptree */
|
|
|
|
fd = open(RC_DEPTREE_CACHE, O_WRONLY);
|
|
|
|
merrno = errno;
|
|
|
|
errno = serrno;
|
|
|
|
if (fd == -1 && merrno == EACCES)
|
|
|
|
return rc_deptree_load();
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (regen)
|
|
|
|
*regen = 1;
|
|
|
|
ebegin("Caching service dependencies");
|
|
|
|
retval = rc_deptree_update() ? 0 : -1;
|
|
|
|
eend (retval, "Failed to update the dependency tree");
|
|
|
|
|
|
|
|
if (retval == 0) {
|
|
|
|
stat(RC_DEPTREE_CACHE, &st);
|
|
|
|
if (st.st_mtime < t) {
|
|
|
|
eerror("Clock skew detected with `%s'", file);
|
|
|
|
eerrorn("Adjusting mtime of `" RC_DEPTREE_CACHE
|
|
|
|
"' to %s", ctime(&t));
|
|
|
|
fp = fopen(RC_DEPTREE_SKEWED, "w");
|
|
|
|
if (fp != NULL) {
|
|
|
|
fprintf(fp, "%s\n", file);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
ut.actime = t;
|
|
|
|
ut.modtime = t;
|
|
|
|
utime(RC_DEPTREE_CACHE, &ut);
|
|
|
|
} else {
|
|
|
|
if (exists(RC_DEPTREE_SKEWED))
|
|
|
|
unlink(RC_DEPTREE_SKEWED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (force == -1 && regen != NULL)
|
|
|
|
*regen = retval;
|
|
|
|
}
|
|
|
|
return rc_deptree_load();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _rc_can_find_pids(void)
|
|
|
|
{
|
|
|
|
RC_PIDLIST *pids;
|
|
|
|
RC_PID *pid;
|
|
|
|
RC_PID *pid2;
|
|
|
|
bool retval = false;
|
|
|
|
|
|
|
|
if (geteuid() == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* If we cannot see process 1, then we don't test to see if
|
|
|
|
* services crashed or not */
|
|
|
|
pids = rc_find_pids(NULL, NULL, 0, 1);
|
|
|
|
if (pids) {
|
|
|
|
pid = LIST_FIRST(pids);
|
|
|
|
if (pid) {
|
|
|
|
retval = true;
|
|
|
|
while (pid) {
|
|
|
|
pid2 = LIST_NEXT(pid, entries);
|
|
|
|
free(pid);
|
|
|
|
pid = pid2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(pids);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
const char * const name;
|
|
|
|
RC_SERVICE bit;
|
|
|
|
} service_bits[] = {
|
|
|
|
{ "service_started", RC_SERVICE_STARTED, },
|
|
|
|
{ "service_stopped", RC_SERVICE_STOPPED, },
|
|
|
|
{ "service_inactive", RC_SERVICE_INACTIVE, },
|
|
|
|
{ "service_starting", RC_SERVICE_STARTING, },
|
|
|
|
{ "service_stopping", RC_SERVICE_STOPPING, },
|
|
|
|
{ "service_hotplugged", RC_SERVICE_HOTPLUGGED, },
|
|
|
|
{ "service_wasinactive", RC_SERVICE_WASINACTIVE, },
|
|
|
|
{ "service_failed", RC_SERVICE_FAILED, },
|
|
|
|
};
|
|
|
|
|
|
|
|
RC_SERVICE lookup_service_state(const char *service)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(service_bits); ++i)
|
|
|
|
if (!strcmp(service, service_bits[i].name))
|
|
|
|
return service_bits[i].bit;
|
|
|
|
return 0;
|
|
|
|
}
|