Browse Source

Add support for "Loading any service with `dinit` on `system manager mode`" (#76)

Adds --service (-t) option to specify that next command line argument is a service name. This provides a way to load arbitrary service targets via the Linux kernel command line (more specifically, allows dinit to distinguish between targets that should be started vs arbitrary words that may have leaked from the kernel command line to dinit's command line, since Linux isn't great at removing all the kernel parameters before passing them on).
Mobin Aydinfar 1 year ago
parent
commit
2b8384ae57
3 changed files with 19 additions and 3 deletions
  1. 1 1
      CONTRIBUTORS
  2. 6 1
      doc/manpages/dinit.8.m4
  3. 12 1
      src/dinit.cc

+ 1 - 1
CONTRIBUTORS

@@ -4,4 +4,4 @@ The following people have contributed:
  * Daniel Kolesa - Code, testing, documentation.
  * Edd Barrett - Testing, documentation.
  * Fabien Poussin - Code, services, documentation.
- * Mobin Aydinfar - CI
+ * Mobin Aydinfar - Code, documentation, CI

+ 6 - 1
doc/manpages/dinit.8.m4

@@ -117,11 +117,16 @@ If none are specified, defaults to \fIboot\fR (which requires that a suitable se
 for the \fIboot\fR service exists).
 .sp
 \fBNote:\fR on Linux, if \fBdinit\fR is running as PID 1 and with UID 0, it will ignore
-service names provided on the command line, other than "single", unless they appear
+service names provided on the command line, other than "single", unless use \fB-t\fR, \fB--service\fR argument or they appear
 anywhere after the "\-o" or "\-m" options (or their long forms).
 This is to filter arguments that were intended for the kernel and not for \fBinit\fR.
 If running in a container, the "\-o" option should be used regardless and will inhibit this
 filtering for any subsequent service names.
+.TP
+\fB\-t\fR, \fB--service\fR \fIservice-name\fR
+Specifies the name of a service that should be started (along with its
+dependencies) and its work when \fBdinit\fR started as \fBinit\fR. you can use this argument(s) in kernel/bootloader command line (E.g: \fB-t tty1\fR).
+also possible to start several services by adding several \fB-t\fR, \fB--service\fR (E.g: \fB-t tty1 -t tty2\fR).
 .\"
 .SH SERVICE DESCRIPTION FILES
 .\"

+ 12 - 1
src/dinit.cc

@@ -322,6 +322,15 @@ static int process_commandline_arg(char **argv, int argc, int &i, options &opts)
             }
         }
         #endif
+        else if (strcmp(argv[i], "--service") == 0 || strcmp(argv[i], "-t") == 0) {
+            if (++i < argc) {
+                services_to_start.push_back(argv[i]);
+            }
+            else {
+                cerr << "dinit: '--service' (-t) requires an argument\n";
+                return 1;
+            }
+        }
         else if (strcmp(argv[i], "--version") == 0) {
             printVersion();
             return -1;
@@ -349,7 +358,9 @@ static int process_commandline_arg(char **argv, int argc, int &i, options &opts)
                     #endif
                     " --log-file <file>, -l <file> log to the specified file\n"
                     " --quiet, -q                  disable output to standard output\n"
-                    " <service-name> [...]         start service with name <service-name>\n";
+                    " <service-name>               start service with name <service-name>\n"
+                    " --service <service-name>, -t <service-name>\n" 
+                    "                              start service with name <service-name>\n";
             return -1;
         }
         else {