diff options
author | Greg KH <gregkh@linuxfoundation.org> | 2014-03-14 04:43:04 +0000 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-03-14 12:44:17 +0100 |
commit | 92f2f92edcad46ce4098ee26504edca0a1dad68e (patch) | |
tree | 9ad2337000ed976c22f42adf19595800671824a2 /src/machine-id-setup/machine-id-setup-main.c | |
parent | 06f021a8048583d66202e3ac5cd0a12386d33ac2 (diff) | |
download | systemd-92f2f92edcad46ce4098ee26504edca0a1dad68e.tar.gz |
machine-id: add --root option to operate on an alternate fs tree
This makes it possible to initialize the /etc/machine-id file on an
arbitrary filesystem hierarchy. This helps systems that wish to run
this at image creation time in a subdirectory, or from initramfs before
pivot-root is called.
[tomegun: converted to using _cleanup_free_ macros]
Diffstat (limited to 'src/machine-id-setup/machine-id-setup-main.c')
-rw-r--r-- | src/machine-id-setup/machine-id-setup-main.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c index 84af925f51..a67d436dbd 100644 --- a/src/machine-id-setup/machine-id-setup-main.c +++ b/src/machine-id-setup/machine-id-setup-main.c @@ -29,12 +29,15 @@ #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" - " --version Show package version\n", + " --version Show package version\n" + " --root Filesystem root\n", program_invocation_short_name); return 0; @@ -43,12 +46,14 @@ static int help(void) { 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 }, + { "root", required_argument, NULL, ARG_ROOT }, {} }; @@ -69,6 +74,10 @@ static int parse_argv(int argc, char *argv[]) { puts(SYSTEMD_FEATURES); return 0; + case ARG_ROOT: + arg_root = optarg; + break; + case '?': return -EINVAL; @@ -95,5 +104,5 @@ int main(int argc, char *argv[]) { 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; } |