X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fmachine-id-setup%2Fmachine-id-setup-main.c;h=1c933ce600b3cc0e324a8e4a7c0ec0f4254d66a2;hp=eb2d514855ade593a4ff325afcfb0e875346a49c;hb=f27e2d8c0c0c18d5a1be62c87ea89fcd4894fffa;hpb=f274ece0f76b5709408821e317e87aef76123db6 diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c index eb2d51485..1c933ce60 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=ROOT Filesystem root\n", program_invocation_short_name); return 0; @@ -43,13 +46,15 @@ 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 }, - { NULL, 0, NULL, 0 } + { "root", required_argument, NULL, ARG_ROOT }, + {} }; int c; @@ -62,25 +67,27 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': - help(); - return 0; + return help(); case ARG_VERSION: puts(PACKAGE_STRING); puts(SYSTEMD_FEATURES); return 0; + case ARG_ROOT: + arg_root = optarg; + break; + case '?': return -EINVAL; default: - log_error("Unknown option code %c", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } } if (optind < argc) { - help(); + log_error("Extraneous arguments"); return -EINVAL; } @@ -97,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; }