From nobody Tue Jan 14 17:54:06 2025 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 4YXcFW1LlCz5kD7S; Tue, 14 Jan 2025 17:54:07 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YXcFW0VHhz445W; Tue, 14 Jan 2025 17:54:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736877247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Vp0X9WE27XzrSgAJLwXmxpH78yr7BDCDCr6QmfbsxrA=; b=NUkfs7kv0d4q7gfwSfxq/B8l5AgzgatKt3zsHgdlE6uVo0g8+fu7WBSLS/cx9mSfKRoMJ+ ueis1b3nlt+XM8/I24Q4wzxC5Q5bGZ6HPxD8itHjBGe1ylNjxHz3jcEGg1SkYRclRZdk18 0qX5hqj1Q3oFtfteAup5OmFK0Of54B/4Ch4gMnBENZBn+BhUMYCCVrwi2lteFySE8qm8qR vuBBVb53+tAs0s8/8vFxUYfQUZSiiwIbBQbH30bdbqpb3NEgrc3Au/grQce5fouvHMNCCa y2K7kNM5qT+iicM63ls2JyjUm+J7l1pymtF7ljvVYvHt5pKB7FquDmWIwmtwIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736877247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Vp0X9WE27XzrSgAJLwXmxpH78yr7BDCDCr6QmfbsxrA=; b=ybB5NbIq0p0aRSt2FOVtq5bJRM9CgjWPVSRRYxHBCxta5VbAIQxQJfHzTBZhr8ZtJIpRmt T6sXcekKzCh+BultCf6G3kHkk2DH1CpwtlUKAZ31VMtwmL/+bZyiBtVL2lL3/VByYZwiiT DuilNuCfQAGk72UXERfvuiMWPfmjH3Pu7veZuZsgUtIN6DCl4h/GgsKLYgxTiUZ2DvSFBd s3caRBACmWbZK7Cx0ZGkP5hEMbTlz2qRSCGEshShj5LdIV/DbYdgIl7MkLZC8Axog5yYXz ccBxZb1+5EoDItluNvnJviiC1Ks9XbU3Ps0MVC47gjF1jtp+vjORgRLJOahmQw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736877247; a=rsa-sha256; cv=none; b=ytyCRNvjhO3lOD4RoNw8pjEDsWkuJIwkQm0Mnuma4QOqgKeR+E1pTeKaokJ8DkKHcebQ0z WLo6ehqiQhUf2+0eDqyl4chzKI+OFQ06d0iFQyzzMD6/zbr4Slyr9a+J3ajwXLC89/B5mA qAAzPd3SHUmyONfa0k9p8fWcjEVeIniuLSQ3v6NZmt9iIVrchNlnn7pJwmknCpPp/V+/Oq tQWGvjRaAeHSDROs7ia4luYT1OR+MN4Wdux3TYg48KlVC0zf9uNwIU0ITcN9bdGSOtCegu fylQGPfpP2UohjdxftmE1LZUgwpRjVAEkEDLysIz7qiq3MLO1tA1BnHInKnXkg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YXcFV70h3z1QST; Tue, 14 Jan 2025 17:54:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50EHs63t071992; Tue, 14 Jan 2025 17:54:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50EHs6kJ071989; Tue, 14 Jan 2025 17:54:06 GMT (envelope-from git) Date: Tue, 14 Jan 2025 17:54:06 GMT Message-Id: <202501141754.50EHs6kJ071989@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: bec5a3c046ba - main - nextboot: Smarter warning about deleting nextboot 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bec5a3c046ba2bd970679a31f7227f260bef4935 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=bec5a3c046ba2bd970679a31f7227f260bef4935 commit bec5a3c046ba2bd970679a31f7227f260bef4935 Author: Warner Losh AuthorDate: 2025-01-14 17:32:01 +0000 Commit: Warner Losh CommitDate: 2025-01-14 17:52:54 +0000 nextboot: Smarter warning about deleting nextboot Read only filesystems always error when trying to remove something with EROFS. However, that's true even if the file isn't there. The code assumed it would always get a ENOENT if the file wasn't there, but produced a gross message on read only systems. This message was harmless, but annoying. Instead, stat the file first and return if it's already not there. Some readings of POSIX require that the ENOENT error take precidence over the EROFS error. Linux made this change years ago, and we should too. POSIX.1-2024 isn't explicit, but does say for unlink() does say "[EROFS] The directory entry to be unlinked is part of a read-only file system" and "[ENOENT] A component of path does not name an existing file" implying that EROFS should only be returned for an existing file. FreeBSD doesn't implement this, so this workaround is necessary. Ideally, we'd fix this in the kernel in the future. Sponsored by: Netflix Discussed with: jrtc23 Differential Revision: https://reviews.freebsd.org/D48425 --- sbin/reboot/reboot.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c index c6b0e0980c88..9825d4f96319 100644 --- a/sbin/reboot/reboot.c +++ b/sbin/reboot/reboot.c @@ -308,7 +308,22 @@ main(int argc, char *argv[]) errx(1, "-r and -k cannot be used together, there is no next kernel"); if (Dflag) { - if (unlink(PATH_NEXTBOOT) != 0 && errno != ENOENT) + struct stat sb; + + /* + * Break the rule about stat then doing + * something. When we're booting, there's no + * race. When we're a read-only root, though, the + * read-only error takes priority over the file not + * there error in unlink. So stat it first and exit + * with success if it isn't there. Otherwise, let + * unlink sort error reporting. POSIX-1.2024 suggests + * ENOENT should be preferred to EROFS for unlink, + * but FreeBSD historically has preferred EROFS. + */ + if (stat(PATH_NEXTBOOT, &sb) != 0 && errno == ENOENT) + exit(0); + if (unlink(PATH_NEXTBOOT) != 0) warn("unlink " PATH_NEXTBOOT); exit(0); }