]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/machine-id-setup/machine-id-setup-main.c
logind: fix printf format
[thirdparty/systemd.git] / src / machine-id-setup / machine-id-setup-main.c
CommitLineData
d7ccca2e
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
d7ccca2e
LP
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 16 Lesser General Public License for more details.
d7ccca2e 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
d7ccca2e
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <unistd.h>
23#include <stdlib.h>
984bf931
LP
24#include <stdio.h>
25#include <getopt.h>
26#include <errno.h>
d7ccca2e 27
b6e66135 28#include "machine-id-setup.h"
d7ccca2e 29#include "log.h"
984bf931
LP
30#include "build.h"
31
32static int help(void) {
33
34 printf("%s [OPTIONS...]\n\n"
35 "Initialize /etc/machine-id from a random source.\n\n"
36 " -h --help Show this help\n"
37 " --version Show package version\n",
38 program_invocation_short_name);
39
40 return 0;
41}
42
43static int parse_argv(int argc, char *argv[]) {
44
45 enum {
46 ARG_VERSION = 0x100
47 };
48
49 static const struct option options[] = {
50 { "help", no_argument, NULL, 'h' },
51 { "version", no_argument, NULL, ARG_VERSION },
eb9da376 52 {}
984bf931
LP
53 };
54
55 int c;
56
57 assert(argc >= 0);
58 assert(argv);
59
60 while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0) {
61
62 switch (c) {
63
64 case 'h':
eb9da376 65 return help();
984bf931
LP
66
67 case ARG_VERSION:
68 puts(PACKAGE_STRING);
984bf931
LP
69 puts(SYSTEMD_FEATURES);
70 return 0;
71
72 case '?':
73 return -EINVAL;
74
75 default:
eb9da376 76 assert_not_reached("Unhandled option");
984bf931
LP
77 }
78 }
79
80 if (optind < argc) {
81 help();
82 return -EINVAL;
83 }
84
85 return 1;
86}
d7ccca2e
LP
87
88int main(int argc, char *argv[]) {
984bf931 89 int r;
d7ccca2e 90
d7ccca2e
LP
91 log_parse_environment();
92 log_open();
93
984bf931
LP
94 r = parse_argv(argc, argv);
95 if (r <= 0)
96 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
97
d7ccca2e
LP
98 return machine_id_setup() < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
99}