summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-04-06 23:55:42 +0200
committerLennart Poettering <lennart@poettering.net>2010-04-06 23:55:42 +0200
commita5dab5ce0fd4aafc394afe30eda0e6b01a13256b (patch)
treef1333d22edc0ab69f79fbe558e9becef77a32e4d /main.c
parentf170852aea19408cfefcd1b9df4aa8942dbbca98 (diff)
manager: make running_as configurable
Diffstat (limited to 'main.c')
-rw-r--r--main.c36
1 files changed, 31 insertions, 5 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;
}