summaryrefslogtreecommitdiff
path: root/src/machine-id-setup
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-04-12 15:07:24 +0200
committerLennart Poettering <lennart@poettering.net>2012-04-12 15:07:24 +0200
commit984bf9312e3f2c7cc165b54546270ce7804d5a4d (patch)
treef3b17af9bab1d958493271465351fcf563bd7d45 /src/machine-id-setup
parent2c4ff63406c80839c6c8e838c1279934a0bc150e (diff)
downloadsystemd-984bf9312e3f2c7cc165b54546270ce7804d5a4d.tar.gz
machine-id-setup: add the usual command line parameters
Diffstat (limited to 'src/machine-id-setup')
l---------src/machine-id-setup/Makefile1
-rw-r--r--src/machine-id-setup/machine-id-setup-main.c68
2 files changed, 69 insertions, 0 deletions
diff --git a/src/machine-id-setup/Makefile b/src/machine-id-setup/Makefile
new file mode 120000
index 0000000000..d0b0e8e008
--- /dev/null
+++ b/src/machine-id-setup/Makefile
@@ -0,0 +1 @@
+../Makefile \ No newline at end of file
diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c
index ca8af596f7..60f9ef837b 100644
--- a/src/machine-id-setup/machine-id-setup-main.c
+++ b/src/machine-id-setup/machine-id-setup-main.c
@@ -21,15 +21,83 @@
#include <unistd.h>
#include <stdlib.h>
+#include <stdio.h>
+#include <getopt.h>
+#include <errno.h>
#include "machine-id-setup.h"
#include "log.h"
+#include "build.h"
+
+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",
+ program_invocation_short_name);
+
+ return 0;
+}
+
+static int parse_argv(int argc, char *argv[]) {
+
+ enum {
+ ARG_VERSION = 0x100
+ };
+
+ static const struct option options[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, ARG_VERSION },
+ { NULL, 0, NULL, 0 }
+ };
+
+ int c;
+
+ assert(argc >= 0);
+ assert(argv);
+
+ while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0) {
+
+ switch (c) {
+
+ case 'h':
+ help();
+ return 0;
+
+ case ARG_VERSION:
+ puts(PACKAGE_STRING);
+ puts(DISTRIBUTION);
+ puts(SYSTEMD_FEATURES);
+ return 0;
+
+ case '?':
+ return -EINVAL;
+
+ default:
+ log_error("Unknown option code %c", c);
+ return -EINVAL;
+ }
+ }
+
+ if (optind < argc) {
+ help();
+ return -EINVAL;
+ }
+
+ return 1;
+}
int main(int argc, char *argv[]) {
+ int r;
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
log_open();
+ r = parse_argv(argc, argv);
+ if (r <= 0)
+ return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+
return machine_id_setup() < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}