summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c36
-rw-r--r--manager.c14
-rw-r--r--manager.h2
-rw-r--r--test-engine.c2
4 files changed, 37 insertions, 17 deletions
diff --git a/main.c b/main.c
index acfa35fe6e..c2f1ef856d 100644
--- a/main.c
+++ b/main.c
@@ -39,6 +39,7 @@ static enum {
} action = ACTION_RUN;
static char *default_unit = NULL;
+static ManagerRunningAs running_as = _MANAGER_RUNNING_AS_INVALID;
static int set_default_unit(const char *u) {
char *c;
@@ -132,13 +133,15 @@ static int parse_argv(int argc, char *argv[]) {
enum {
ARG_LOG_LEVEL = 0x100,
ARG_LOG_TARGET,
- ARG_DEFAULT
+ ARG_DEFAULT,
+ ARG_RUNNING_AS
};
static const struct option options[] = {
{ "log-level", required_argument, NULL, ARG_LOG_LEVEL },
{ "log-target", required_argument, NULL, ARG_LOG_TARGET },
{ "default", required_argument, NULL, ARG_DEFAULT },
+ { "running-as", required_argument, NULL, ARG_RUNNING_AS },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};
@@ -178,6 +181,18 @@ static int parse_argv(int argc, char *argv[]) {
break;
+ case ARG_RUNNING_AS: {
+ ManagerRunningAs as;
+
+ if ((as = manager_running_as_from_string(optarg)) < 0) {
+ log_error("Failed to parse running as value %s", optarg);
+ return -EINVAL;
+ }
+
+ running_as = as;
+ break;
+ }
+
case 'h':
action = ACTION_HELP;
break;
@@ -204,7 +219,8 @@ static int help(void) {
" -h --help Show this help\n"
" --default=UNIT Set default unit\n"
" --log-level=LEVEL Set log level\n"
- " --log-target=TARGET Set log target (console, syslog, kmsg)\n",
+ " --log-target=TARGET Set log target (console, syslog, kmsg)\n"
+ " --running-as=AS Set running as (init, system, sesstion)\n",
__progname);
return 0;
@@ -216,6 +232,13 @@ int main(int argc, char *argv[]) {
Job *job = NULL;
int r, retval = 1;
+ if (getpid() == 1)
+ running_as = MANAGER_INIT;
+ else if (getuid() == 0)
+ running_as = MANAGER_SYSTEM;
+ else
+ running_as = MANAGER_SESSION;
+
if (set_default_unit(SPECIAL_DEFAULT_TARGET) < 0)
goto finish;
@@ -229,8 +252,9 @@ int main(int argc, char *argv[]) {
/* Close all open files */
assert_se(close_all_fds(NULL, 0) == 0);
- if (parse_proc_cmdline() < 0)
- goto finish;
+ if (running_as != MANAGER_SESSION)
+ if (parse_proc_cmdline() < 0)
+ goto finish;
log_parse_environment();
@@ -260,7 +284,9 @@ int main(int argc, char *argv[]) {
log_open_syslog();
log_open_kmsg();
- if ((r = manager_new(&m)) < 0) {
+ log_debug("systemd running in %s mode.", manager_running_as_to_string(running_as));
+
+ if ((r = manager_new(running_as, &m)) < 0) {
log_error("Failed to allocate manager object: %s", strerror(-r));
goto finish;
}
diff --git a/manager.c b/manager.c
index 7d3b8b5039..ddac4984ac 100644
--- a/manager.c
+++ b/manager.c
@@ -256,15 +256,18 @@ static int manager_find_paths(Manager *m) {
return 0;
}
-int manager_new(Manager **_m) {
+int manager_new(ManagerRunningAs running_as, Manager **_m) {
Manager *m;
int r = -ENOMEM;
assert(_m);
+ assert(running_as >= 0);
+ assert(running_as < _MANAGER_RUNNING_AS_MAX);
if (!(m = new0(Manager, 1)))
return -ENOMEM;
+ m->running_as = running_as;
m->signal_watch.fd = m->mount_watch.fd = m->udev_watch.fd = m->epoll_fd = -1;
m->current_job_id = 1; /* start as id #1, so that we can leave #0 around as "null-like" value */
@@ -286,15 +289,6 @@ int manager_new(Manager **_m) {
if ((m->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0)
goto fail;
- if (getpid() == 1)
- m->running_as = MANAGER_INIT;
- else if (getuid() == 0)
- m->running_as = MANAGER_SYSTEM;
- else
- m->running_as = MANAGER_SESSION;
-
- log_debug("systemd running in %s mode.", manager_running_as_to_string(m->running_as));
-
if ((r = manager_find_paths(m)) < 0)
goto fail;
diff --git a/manager.h b/manager.h
index 3dbac34e6c..39be0dc887 100644
--- a/manager.h
+++ b/manager.h
@@ -166,7 +166,7 @@ struct Manager {
char *cgroup_hierarchy;
};
-int manager_new(Manager **m);
+int manager_new(ManagerRunningAs running_as, Manager **m);
void manager_free(Manager *m);
int manager_coldplug(Manager *m);
diff --git a/test-engine.c b/test-engine.c
index 43a68fcdbd..cb817645ac 100644
--- a/test-engine.c
+++ b/test-engine.c
@@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
assert_se(set_unit_path("test2") >= 0);
- assert_se(manager_new(&m) >= 0);
+ assert_se(manager_new(MANAGER_INIT, &m) >= 0);
printf("Load1:\n");
assert_se(manager_load_unit(m, "a.service", &a) == 0);