From: Zbigniew Jędrzejewski-Szmek Date: Wed, 3 Dec 2025 21:58:46 +0000 (+0100) Subject: nspawn: simplify parsing of --hostname/--machine X-Git-Tag: v257.11~63 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9b8e3314609ade5030ff0a786d945c770590def9;p=thirdparty%2Fsystemd.git nspawn: simplify parsing of --hostname/--machine (cherry picked from commit 26de1563d0ee1c6d1a94b99c662da7c5e103991e) (cherry picked from commit abc3c7ad958580b21cb038bd80057eea77a75a88) (cherry picked from commit cde2e773efa12cb6b01f2b5dc0731fe07ec1a05f) --- diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 57bba0f9dce..45ae091f553 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -1022,31 +1022,23 @@ static int parse_argv(int argc, char *argv[]) { } case 'M': - if (isempty(optarg)) - arg_machine = mfree(arg_machine); - else { - if (!hostname_is_valid(optarg, 0)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Invalid machine name: %s", optarg); + if (!isempty(optarg) && !hostname_is_valid(optarg, /* flags= */ 0)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid machine name: %s", optarg); - r = free_and_strdup(&arg_machine, optarg); - if (r < 0) - return log_oom(); - } + r = free_and_strdup_warn(&arg_machine, optarg); + if (r < 0) + return r; break; case ARG_HOSTNAME: - if (isempty(optarg)) - arg_hostname = mfree(arg_hostname); - else { - if (!hostname_is_valid(optarg, 0)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Invalid hostname: %s", optarg); + if (!isempty(optarg) && !hostname_is_valid(optarg, /* flags= */ 0)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid hostname: %s", optarg); - r = free_and_strdup(&arg_hostname, optarg); - if (r < 0) - return log_oom(); - } + r = free_and_strdup_warn(&arg_hostname, optarg); + if (r < 0) + return r; arg_settings_mask |= SETTING_HOSTNAME; break;