chiark / gitweb /
machine-id: add --root option to operate on an alternate fs tree
[elogind.git] / src / machine-id-setup / machine-id-setup-main.c
index 84af925f517e9c3b3d39c0f8786355b21c84c8a6..a67d436dbd7c40a5f305a8ad535ffe220c0b836d 100644 (file)
 #include "log.h"
 #include "build.h"
 
 #include "log.h"
 #include "build.h"
 
+static const char *arg_root = "";
+
 static int help(void) {
 
         printf("%s [OPTIONS...]\n\n"
                "Initialize /etc/machine-id from a random source.\n\n"
                "  -h --help             Show this help\n"
 static int help(void) {
 
         printf("%s [OPTIONS...]\n\n"
                "Initialize /etc/machine-id from a random source.\n\n"
                "  -h --help             Show this help\n"
-               "     --version          Show package version\n",
+               "     --version          Show package version\n"
+               "     --root             Filesystem root\n",
                program_invocation_short_name);
 
         return 0;
                program_invocation_short_name);
 
         return 0;
@@ -43,12 +46,14 @@ static int help(void) {
 static int parse_argv(int argc, char *argv[]) {
 
         enum {
 static int parse_argv(int argc, char *argv[]) {
 
         enum {
-                ARG_VERSION = 0x100
+                ARG_VERSION = 0x100,
+                ARG_ROOT,
         };
 
         static const struct option options[] = {
                 { "help",      no_argument,       NULL, 'h'           },
                 { "version",   no_argument,       NULL, ARG_VERSION   },
         };
 
         static const struct option options[] = {
                 { "help",      no_argument,       NULL, 'h'           },
                 { "version",   no_argument,       NULL, ARG_VERSION   },
+                { "root",      required_argument, NULL, ARG_ROOT      },
                 {}
         };
 
                 {}
         };
 
@@ -69,6 +74,10 @@ static int parse_argv(int argc, char *argv[]) {
                         puts(SYSTEMD_FEATURES);
                         return 0;
 
                         puts(SYSTEMD_FEATURES);
                         return 0;
 
+                case ARG_ROOT:
+                        arg_root = optarg;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
                 case '?':
                         return -EINVAL;
 
@@ -95,5 +104,5 @@ int main(int argc, char *argv[]) {
         if (r <= 0)
                 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 
         if (r <= 0)
                 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 
-        return machine_id_setup() < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+        return machine_id_setup(arg_root) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 }