]> git.proxmox.com Git - systemd.git/blobdiff - src/machine-id-setup/machine-id-setup-main.c
Imported Upstream version 227
[systemd.git] / src / machine-id-setup / machine-id-setup-main.c
index 20cb60b804592f4896eb70cfe35e6708617222ef..a9c4e3fadfc226554d259b560bf72b979a6d9f71 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <getopt.h>
 #include <errno.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
 
-#include "machine-id-setup.h"
 #include "log.h"
-#include "build.h"
+#include "machine-id-setup.h"
+#include "util.h"
 
-static const char *arg_root = "";
+static const char *arg_root = NULL;
+static bool arg_commit = false;
 
 static void 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"
-               "     --root=ROOT        Filesystem root\n",
-               program_invocation_short_name);
+               "     --root=ROOT        Filesystem root\n"
+               "     --commit           Commit transient ID\n"
+               , program_invocation_short_name);
 }
 
 static int parse_argv(int argc, char *argv[]) {
@@ -44,12 +46,14 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
                 ARG_ROOT,
+                ARG_COMMIT,
         };
 
         static const struct option options[] = {
                 { "help",      no_argument,       NULL, 'h'           },
                 { "version",   no_argument,       NULL, ARG_VERSION   },
                 { "root",      required_argument, NULL, ARG_ROOT      },
+                { "commit",    no_argument,       NULL, ARG_COMMIT    },
                 {}
         };
 
@@ -67,14 +71,16 @@ static int parse_argv(int argc, char *argv[]) {
                         return 0;
 
                 case ARG_VERSION:
-                        puts(PACKAGE_STRING);
-                        puts(SYSTEMD_FEATURES);
-                        return 0;
+                        return version();
 
                 case ARG_ROOT:
                         arg_root = optarg;
                         break;
 
+                case ARG_COMMIT:
+                        arg_commit = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -100,5 +106,11 @@ int main(int argc, char *argv[]) {
         if (r <= 0)
                 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 
-        return machine_id_setup(arg_root) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+        if (arg_commit)
+                r = machine_id_commit(arg_root);
+        else
+                r = machine_id_setup(arg_root);
+
+
+        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }