From 4d853d354f36bfb4eba021ee18153a781bc8f479 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Sat, 27 Oct 2018 14:33:31 +0100 Subject: [PATCH] Add -u/--user to force running as a user service manager. Since running as root now runs as a system service manager by default, provide an option not to do so. --- doc/manpages/dinit.8 | 20 ++++++++++++++------ src/dinit.cc | 6 +++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/doc/manpages/dinit.8 b/doc/manpages/dinit.8 index db5b848..09188c9 100644 --- a/doc/manpages/dinit.8 +++ b/doc/manpages/dinit.8 @@ -4,8 +4,12 @@ dinit \- supervise processes and manage services .\" .SH SYNOPSIS .\" +.HP \w'\ 'u .B dinit -[\-s] [\-d \fIdir\fR] [\-p \fIpath\fR] [\fIservice-name\fR] +[\fB\-s\fR|\fB\-\-system\fR|\fB\-u\fR|\fB\-\-user\fR] [\fB\-d\fR|\fB\-\-services\-dir\fR \fIdir\fR] +[\fB\-p\fR|\fB\-\-socket\-path\fR \fIpath\fR] [\fB\-e\fR|\fB\-\-env\-file\fR \fIpath\fR] +[\fB\-l\fR|\fB\-\-log\-file\fR \fIpath\fR] +[\fIservice-name\fR] .\" .SH DESCRIPTION .\" @@ -15,7 +19,7 @@ feature set, offering service dependency handling, parallel startup, automatic rate-limited restart of failing processes, and service control functions. -Dinit can be run as a system instance (when used as an \fBinit\fR or when +Dinit can be run as a system instance (when run as the root user or when specified via command line parameter) or as a user instance. This affects the default paths used to locate certain files, and the reaction to various signals. @@ -43,15 +47,19 @@ commands from the \fBdinitctl\fR program. .TP \fB\-l\fR \fIpath\fP, \fB\-\-log\-file\fR \fIpath\fP Species \fIpath\fP as the path to the log file, to which Dinit will log status -and error messages. Note that when running as the system init process, Dinit +and error messages. Note that when running as the system service manager, Dinit does not begin logging until the log service has started. Using this option inhibits logging via the syslog facility, however, all logging messages are duplicated as usual to the console (so long as no service owns the console). .TP \fB\-s\fR, \fB\-\-system\fR -Run as the system init process. This is the default if invoked as PID 1. -This option affects the default service definition directory and -control socket path. +Run as the system service manager. This is the default if invoked as the root +user. This option affects the default service definition directory and control +socket path. +.TP +\fB\-u\fR, \fB\-\-user\fR +Run as a user. This is the opposite of \fB\-\-system\fR, and is the default if +not invoked as the root user. .TP \fB\-\-help\fR display this help and exit diff --git a/src/dinit.cc b/src/dinit.cc index c9392f8..535dcaa 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -212,6 +212,9 @@ int dinit_main(int argc, char **argv) else if (strcmp(argv[i], "--system") == 0 || strcmp(argv[i], "-s") == 0) { am_system_init = true; } + else if (strcmp(argv[i], "--user") == 0 || strcmp(argv[i], "-u") == 0) { + am_system_init = false; + } else if (strcmp(argv[i], "--socket-path") == 0 || strcmp(argv[i], "-p") == 0) { if (++i < argc) { control_socket_path = argv[i]; @@ -240,7 +243,8 @@ int dinit_main(int argc, char **argv) " --services-dir , -d \n" " set base directory for service description\n" " files (-d )\n" - " --system, -s run as the system init process\n" + " --system, -s run as the system service manager\n" + " --user, -u run as a user service manager\n" " --socket-path , -p \n" " path to control socket\n" " start service with name \n"; -- 2.25.1