| File: | build-scan/../src/machine-id-setup/machine-id-setup-main.c |
| Warning: | line 111, column 34 Null pointer passed to 1st parameter expecting 'nonnull' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
| 2 | ||||
| 3 | #include <errno(*__errno_location ()).h> | |||
| 4 | #include <getopt.h> | |||
| 5 | #include <stdio.h> | |||
| 6 | #include <stdlib.h> | |||
| 7 | ||||
| 8 | #include "id128-util.h" | |||
| 9 | #include "log.h" | |||
| 10 | #include "machine-id-setup.h" | |||
| 11 | #include "path-util.h" | |||
| 12 | #include "util.h" | |||
| 13 | ||||
| 14 | static char *arg_root = NULL((void*)0); | |||
| 15 | static bool_Bool arg_commit = false0; | |||
| 16 | static bool_Bool arg_print = false0; | |||
| 17 | ||||
| 18 | static void help(void) { | |||
| 19 | printf("%s [OPTIONS...]\n\n" | |||
| 20 | "Initialize /etc/machine-id from a random source.\n\n" | |||
| 21 | " -h --help Show this help\n" | |||
| 22 | " --version Show package version\n" | |||
| 23 | " --root=ROOT Filesystem root\n" | |||
| 24 | " --commit Commit transient ID\n" | |||
| 25 | " --print Print used machine ID\n" | |||
| 26 | , program_invocation_short_name); | |||
| 27 | } | |||
| 28 | ||||
| 29 | static int parse_argv(int argc, char *argv[]) { | |||
| 30 | ||||
| 31 | enum { | |||
| 32 | ARG_VERSION = 0x100, | |||
| 33 | ARG_ROOT, | |||
| 34 | ARG_COMMIT, | |||
| 35 | ARG_PRINT, | |||
| 36 | }; | |||
| 37 | ||||
| 38 | static const struct option options[] = { | |||
| 39 | { "help", no_argument0, NULL((void*)0), 'h' }, | |||
| 40 | { "version", no_argument0, NULL((void*)0), ARG_VERSION }, | |||
| 41 | { "root", required_argument1, NULL((void*)0), ARG_ROOT }, | |||
| 42 | { "commit", no_argument0, NULL((void*)0), ARG_COMMIT }, | |||
| 43 | { "print", no_argument0, NULL((void*)0), ARG_PRINT }, | |||
| 44 | {} | |||
| 45 | }; | |||
| 46 | ||||
| 47 | int c, r; | |||
| 48 | ||||
| 49 | assert(argc >= 0)do { if ((__builtin_expect(!!(!(argc >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("argc >= 0"), "../src/machine-id-setup/machine-id-setup-main.c" , 49, __PRETTY_FUNCTION__); } while (0); | |||
| 50 | assert(argv)do { if ((__builtin_expect(!!(!(argv)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("argv"), "../src/machine-id-setup/machine-id-setup-main.c" , 50, __PRETTY_FUNCTION__); } while (0); | |||
| 51 | ||||
| 52 | while ((c = getopt_long(argc, argv, "hqcv", options, NULL((void*)0))) >= 0) | |||
| 53 | ||||
| 54 | switch (c) { | |||
| 55 | ||||
| 56 | case 'h': | |||
| 57 | help(); | |||
| 58 | return 0; | |||
| 59 | ||||
| 60 | case ARG_VERSION: | |||
| 61 | return version(); | |||
| 62 | ||||
| 63 | case ARG_ROOT: | |||
| 64 | r = parse_path_argument_and_warn(optarg, true1, &arg_root); | |||
| 65 | if (r < 0) | |||
| 66 | return r; | |||
| 67 | break; | |||
| 68 | ||||
| 69 | case ARG_COMMIT: | |||
| 70 | arg_commit = true1; | |||
| 71 | break; | |||
| 72 | ||||
| 73 | case ARG_PRINT: | |||
| 74 | arg_print = true1; | |||
| 75 | break; | |||
| 76 | ||||
| 77 | case '?': | |||
| 78 | return -EINVAL22; | |||
| 79 | ||||
| 80 | default: | |||
| 81 | assert_not_reached("Unhandled option")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, ( "Unhandled option"), "../src/machine-id-setup/machine-id-setup-main.c" , 81, __PRETTY_FUNCTION__); } while (0); | |||
| 82 | } | |||
| 83 | ||||
| 84 | if (optind < argc) { | |||
| 85 | log_error("Extraneous arguments")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/machine-id-setup/machine-id-setup-main.c", 85, __func__ , "Extraneous arguments") : -abs(_e); }); | |||
| 86 | return -EINVAL22; | |||
| 87 | } | |||
| 88 | ||||
| 89 | return 1; | |||
| 90 | } | |||
| 91 | ||||
| 92 | int main(int argc, char *argv[]) { | |||
| 93 | char buf[SD_ID128_STRING_MAX33]; | |||
| 94 | sd_id128_t id; | |||
| 95 | int r; | |||
| 96 | ||||
| 97 | log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD); | |||
| 98 | log_open(); | |||
| 99 | ||||
| 100 | r = parse_argv(argc, argv); | |||
| ||||
| 101 | if (r
| |||
| 102 | goto finish; | |||
| 103 | ||||
| 104 | if (arg_commit
| |||
| 105 | const char *etc_machine_id; | |||
| 106 | ||||
| 107 | r = machine_id_commit(arg_root); | |||
| 108 | if (r < 0) | |||
| 109 | goto finish; | |||
| 110 | ||||
| 111 | etc_machine_id = prefix_roota(arg_root, "/etc/machine-id")({ const char* _path = ("/etc/machine-id"), *_root = (arg_root ), *_ret; char *_p, *_n; size_t _l; while (_path[0] == '/' && _path[1] == '/') _path ++; if (empty_or_root(_root)) _ret = _path ; else { _l = strlen(_root) + 1 + strlen(_path) + 1; _n = __builtin_alloca (_l); _p = stpcpy(_n, _root); while (_p > _n && _p [-1] == '/') _p--; if (_path[0] != '/') *(_p++) = '/'; strcpy (_p, _path); _ret = _n; } _ret; }); | |||
| ||||
| 112 | r = id128_read(etc_machine_id, ID128_PLAIN, &id); | |||
| 113 | if (r < 0) { | |||
| 114 | log_error_errno(r, "Failed to read machine ID back: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/machine-id-setup/machine-id-setup-main.c", 114, __func__ , "Failed to read machine ID back: %m") : -abs(_e); }); | |||
| 115 | goto finish; | |||
| 116 | } | |||
| 117 | } else { | |||
| 118 | r = machine_id_setup(arg_root, SD_ID128_NULL((const sd_id128_t) { .qwords = { 0, 0 }}), &id); | |||
| 119 | if (r < 0) | |||
| 120 | goto finish; | |||
| 121 | } | |||
| 122 | ||||
| 123 | if (arg_print) | |||
| 124 | puts(sd_id128_to_string(id, buf)); | |||
| 125 | ||||
| 126 | finish: | |||
| 127 | free(arg_root); | |||
| 128 | return r < 0 ? EXIT_FAILURE1 : EXIT_SUCCESS0; | |||
| 129 | } |