From nobody Thu Jan 8 10:21:27 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dn1Cd0Wm3z62hFZ for ; Thu, 08 Jan 2026 10:21:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dn1CW714vz3sSM for ; Thu, 08 Jan 2026 10:21:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767867688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jpgksrmRAV0sUcO+gltoKl3/hILv9tGAe18Dm3Sse+I=; b=KSKWeWufQTaNWBOTiJtEuj6bO1wlRS0fDuW0T9kwc6F8TURAZsZl/O7KQstx+4ikhONqsi Pdi873RvqBfgH5sbV/HGj+7YqixheQ2HypeGwo525bS595oZHqEprcTSxR7IJc9S3XJ/Op 966EdfcuXTgjmtgZr/hZ5jlzSi4cuxlNG4BMT4sahACnDVxuRX5a8CRRCqV3uhhkoMkqyw v1adTEO+bIHAE6gyzp3H5Kffn3ycA5f0odfsaPwvZGQaJxdiOueHflS8NHVzdptRdLxJXu 8/8LCp7a7QcAp8OfkreyOj6sP7pUpoUUIi90sdcHOpH3QcNMccPm52a7+Nk1Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767867688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jpgksrmRAV0sUcO+gltoKl3/hILv9tGAe18Dm3Sse+I=; b=wT7LSvPfnWibUgJ2fkVR5JckLyoQN8eBDUbZVCozOwFHObpVNiqL/UCey04MeQNOs0W+K0 9m2ZvZJKYJIDZ3DKkmdr2n1wae/CexSgT0zi2QWM06zOUarzX0pga396+QdlFJjkhv9NyC ErgjKnwVa+30YUAHZ1DhG2r0MdiralZvfj/bDruRt4Aech7nbjU+knQDdUqwYb+SJJqOjc rRNkyHNiQA2KSRfsQM2anTWObpBaf64pUVwKhswFY4OdV6gzKQ4rdnuYJ06JCCTvxEZpEz lpN330dVWIWWikRFEpnz1XoTJJBd58yGh3hwK6fSBPTQUZbBvao8EbKSUBECvg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1767867688; a=rsa-sha256; cv=none; b=vjwTBYIGd7Qiftu80RH27G9kWCaoGS5eR4m7hqBIVQbSUt5c2fY2pBq8DZc+jH3qCaX17m E1kt3I7lz1RwqfmN1f7rqRMOMFtcNjgmXoe/i90HRGOCJfXJJ2XdeXMc5QMJpJ+i9/Q8qV xAun9AaxwKG4rK6TuiY/wzDNBuXzeV39gqPhdYb71ZNUCGK6jKehDeln8HUySYxX92ZxQk V+SUqAH2glp1OpW4pdXGM6IEgc9JsPZxinJaiBRJ86LCtxKPjVHc/uOO2nE9ra5Yh312Bp arDk/fZuyJQBI2Kh4uWdB7r1KAXE0ZiqGB5oHdQwwFmXSyGDxMsgcfgwH7f/rA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dn1CW6WMCzbP6 for ; Thu, 08 Jan 2026 10:21:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 27739 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 08 Jan 2026 10:21:27 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: =?utf-8?Q?Gon=C3=A9ri?= Le Bouder From: Baptiste Daroussin Subject: git: cae280931c9e - main - nuageinit: set the hostname when user-data is missing List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cae280931c9e1f072d8bf300c377ae120300b898 Auto-Submitted: auto-generated Date: Thu, 08 Jan 2026 10:21:27 +0000 Message-Id: <695f8527.27739.4f75fe6c@gitrepo.freebsd.org> The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=cae280931c9e1f072d8bf300c377ae120300b898 commit cae280931c9e1f072d8bf300c377ae120300b898 Author: Gonéri Le Bouder AuthorDate: 2026-01-07 21:03:34 +0000 Commit: Baptiste Daroussin CommitDate: 2026-01-08 09:55:27 +0000 nuageinit: set the hostname when user-data is missing This address the situation reported here https://github.com/freebsd/freebsd-src/pull/1952#issuecomment-3720210259 The user-data file was missing and the `sethostname` function is never called. This commit adjusts slightly the logic to avoid the `exit()` call when the `user-data` file is missing. MFC After: 1 week Signed-off-by: Gonéri Le Bouder Differential Revision: https://github.com/freebsd/freebsd-src/pull/1953 --- libexec/nuageinit/nuageinit | 113 ++++++++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 46 deletions(-) diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit index 40e19f98de6c..f7700f7d8e70 100755 --- a/libexec/nuageinit/nuageinit +++ b/libexec/nuageinit/nuageinit @@ -23,7 +23,7 @@ local function default_user(obj, metadata) table.insert(ssh_authorized_keys, k) end end - if type(obj.ssh_authorized_keys) == "table" then + if obj and type(obj.ssh_authorized_keys) == "table" then for _, k in ipairs(obj.ssh_authorized_keys) do table.insert(ssh_authorized_keys, k) end @@ -94,13 +94,13 @@ end local function sethostname(obj, metadata) -- always prefer fqdn if specified over hostname - if obj.fqdn then + if obj and obj.fqdn then nuage.sethostname(obj.fqdn) - elseif obj.hostname then + elseif obj and obj.hostname then nuage.sethostname(obj.hostname) - elseif metadata["local-hostname"] then + elseif metadata["local-hostname"] then nuage.sethostname(metadata["local-hostname"]) - elseif metadata["local"] then + elseif metadata["hostname"] then nuage.sethostname(metadata["hostname"]) end end @@ -130,6 +130,10 @@ end local function create_default_user(obj, metadata) local function need_default_user() + -- no user data + if not obj then + return true + end if not obj.users then -- default user if "users" is undefined return true @@ -269,7 +273,7 @@ local function nameservers(interface, obj) -- Only call resolvconf with interface if interface is provided if interface then resolvconf_command = "resolvconf -a " .. interface .. " < " .. resolv_conf - else + else resolvconf_command = "resolvconf -u" end if not os.execute(resolvconf_command) then @@ -662,7 +666,7 @@ local function parse_network_config() return netobj end -local function load_metadata() +local function load_metadata(citype) if citype == "config-2" then local parser = ucl.parser() local res, err = parser:parse_file(ni_path .. "/meta_data.json") @@ -690,46 +694,70 @@ local function load_metadata() return {} end +local function load_userdata() + local ud = nil + local f = nil + local userdatas = {"user-data", "user_data"} + for _, v in pairs(userdatas) do + f = io.open(ni_path .. "/" .. v, "r") + if f then + ud = v + break + end + end + if not f then + return nil, nil + end + local line = f:read("*l") + if not line or #string.gsub(line, "^%s*(.-)%s*$", "%1") == 0 then + f:close() + return + end + if citype ~= "postnet" then + local content = f:read("*a") + if not content or #string.gsub(content, "^%s*(.-)%s*$", "%1") == 0 then + f:close() + return + end + nuage.mkdir_p(root .. "/var/cache/nuageinit") + local tof = assert(io.open(root .. "/var/cache/nuageinit/user_data", "w")) + tof:write(line .. "\n" .. content) + tof:close() + end + f:close() + + local obj = nil + if ud then + f = io.open(ni_path .. "/" .. ud) + obj = yaml.load(f:read("*a")) + f:close() + if not obj then + nuage.err("error parsing cloud-config file: " .. ud) + end + end + return line, obj +end if citype == "config-2" then -- network config2_network(ni_path) end -local metadata = load_metadata() +local metadata = load_metadata(citype) +local line, obj = load_userdata() --- deal with user-data -local ud = nil -local f = nil -local userdatas = {"user-data", "user_data"} -for _, v in pairs(userdatas) do - f = io.open(ni_path .. "/" .. v, "r") - if f then - ud = v - break - end -end -if not f then - os.exit(0) -end -local line = f:read("*l") -if not line or #string.gsub(line, "^%s*(.-)%s*$", "%1") == 0 then - f:close() - os.exit(0) -end -if citype ~= "postnet" then - local content = f:read("*a") - if not content or #string.gsub(content, "^%s*(.-)%s*$", "%1") == 0 then - f:close() - os.exit(0) +-- No user-data +if line == nil then + local calls_table = { + sethostname, + create_default_user, + } + + for i = 1, #calls_table do + calls_table[i](obj, metadata) end - nuage.mkdir_p(root .. "/var/cache/nuageinit") - local tof = assert(io.open(root .. "/var/cache/nuageinit/user_data", "w")) - tof:write(line .. "\n" .. content) - tof:close() -end -f:close() -if line == "#cloud-config" then +-- YAML user-data +elseif line == "#cloud-config" then local pre_network_calls = { sethostname, settimezone, @@ -749,13 +777,6 @@ if line == "#cloud-config" then write_files_deferred, } - f = io.open(ni_path .. "/" .. ud) - local obj = yaml.load(f:read("*a")) - f:close() - if not obj then - nuage.err("error parsing cloud-config file: " .. ud) - end - local calls_table = pre_network_calls if citype == "postnet" then calls_table = post_network_calls