From nobody Sat Sep 21 11:10:34 2024 X-Original-To: dev-commits-src-branches@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 4X9mkz0zqzz5Vp6L; Sat, 21 Sep 2024 11:10:35 +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 4X9mky6ChBz4kgY; Sat, 21 Sep 2024 11:10:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726917034; 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=ygvJM+i23AwXVNkU3S/d5mOUcplVhSCCw14dsxHSxaA=; b=CqpAc+HRtnwRSsjK+/EyTyTvfUhUuZufCmd2yG2DYG6rqd5hZHibEWT6XGKrRYWobY9ESI YVDIzl7beHBoHSdDiM+qNLoViVeFdVovJUw7Bkoe9L38TFrCvr5cMnoX3r/Zb/Q+6AWBvj bVKjURWBLT5ud3gx5bsPqFBNYvuY3FarUGpvOZBaNf84SGwcjMgCQyjYLqqWpxlGtHP9RI Zf4o/4bEPtyOCBghK+SZa+1a/RAFgIY4AOTTpzuHclUDRlG4m5guOMDXnx2Rzqt2yflPU2 8ioODEtXEosObE0LvIEvjfhYG3Zo8AMiuBPVOMMUQVPV/s5TzL5TLGmjEIWuVw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726917034; a=rsa-sha256; cv=none; b=opw2IjDt+XYdpttJbgwnQQXQzBnkhmTSd8Ql+I1oB6iTTTThYr6Kb0C32fskArI852GK5+ THlhrqjHKiWAXiDciuQ6gVd5LbkZ8Jex57PsXDxv+azjJK6+j4akxcVrLZCmSTOOLjdARt urlQdeMhGpu8KRgqtdMRPWEuMWkraPs72uwyzzFLA+h+MxWQK32+jQp4TdrS5oKj2vs6aa 3pfJblo/cp+eL+gs43gLSIEuf5v49Lv5++6jJu41N4KgQZI9FTsTy99Xx3ZX1eXau7LIen 5FB7x/kb3FNhAgeYUu9gW5rKWznK68D60GRTz+Edk/bSR0gwRXW7i2b9Kpr+nA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726917034; 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=ygvJM+i23AwXVNkU3S/d5mOUcplVhSCCw14dsxHSxaA=; b=mboOt1WTtzWTV66/zt0wpxHDDVbISqKdhLvD61WO+Wcfkv8UEJBMDLrfLLiqGUfszc666X zgP/FetuxjOjDWKUywlsjNmflxpSIQJHqzbw52qdtR8+U5GkLwnAgdKhtrY8vfrKBtH6yW /7Di52Ki2Mx3JyCfxZS3H59TmDvL9EYogAq5cU8RKtZHTX0cb5DBsUWhQyQj5ztsdfOKCP zNeWZtdEzLNn1dbZLwrnHxqbGwgLU1cE7t0OSAZORVXv5XbLp5kSCdCJE6zoEgknbgqhFN lHOaxZOe7GPZLGy4Dk0NTue1uThmCXw0oMuT0mgBiYKy/P6e9CprwEe+iqWtvg== 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 4X9mky5kwmzX5p; Sat, 21 Sep 2024 11:10:34 +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 48LBAYZL015313; Sat, 21 Sep 2024 11:10:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48LBAYx0015310; Sat, 21 Sep 2024 11:10:34 GMT (envelope-from git) Date: Sat, 21 Sep 2024 11:10:34 GMT Message-Id: <202409211110.48LBAYx0015310@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 06a6d0259fe5 - stable/14 - Revert "tzsetup: symlink /etc/localtime instead of copying" List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 06a6d0259fe5721bfb3b745b231ecf7cf3a5e28e Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=06a6d0259fe5721bfb3b745b231ecf7cf3a5e28e commit 06a6d0259fe5721bfb3b745b231ecf7cf3a5e28e Author: Ed Maste AuthorDate: 2024-09-21 11:06:02 +0000 Commit: Ed Maste CommitDate: 2024-09-21 11:06:39 +0000 Revert "tzsetup: symlink /etc/localtime instead of copying" This failed when used with tzsetup's -C option (for example, when using etcupdate -D to update a jail from the host). Revert the stable/14 MFC for now; will be reapplied after being fixed in main.. This reverts commit fc43a1b6842afa806dfd7ba48de5bece63d04456. This reverts commit 87f7f0389f8b7bf30ef12df5c0d337cb2789883e. --- usr.sbin/etcupdate/tests/tzsetup_test.sh | 5 +- usr.sbin/tzsetup/tzsetup.8 | 2 +- usr.sbin/tzsetup/tzsetup.c | 119 ++++++++++++++++++++++++------- 3 files changed, 96 insertions(+), 30 deletions(-) diff --git a/usr.sbin/etcupdate/tests/tzsetup_test.sh b/usr.sbin/etcupdate/tests/tzsetup_test.sh index 155830bddae7..dd76884e13eb 100644 --- a/usr.sbin/etcupdate/tests/tzsetup_test.sh +++ b/usr.sbin/etcupdate/tests/tzsetup_test.sh @@ -232,8 +232,7 @@ echo "Differences for real update:" diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out \ || FAILED=yes -# XXX tzsetup installs a symlink as of 5e16809c953f -#file /etc/localtime "foo" -#file /var/db/zoneinfo "foo" +file /etc/localtime "foo" +file /var/db/zoneinfo "foo" [ "${FAILED}" = no ] diff --git a/usr.sbin/tzsetup/tzsetup.8 b/usr.sbin/tzsetup/tzsetup.8 index 499d25765541..bfa625a1af3a 100644 --- a/usr.sbin/tzsetup/tzsetup.8 +++ b/usr.sbin/tzsetup/tzsetup.8 @@ -52,7 +52,7 @@ The following options are available: Open all files and directories relative to .Ar chroot_directory . .It Fl n -Do not create or symlink files. +Do not create or copy files. .It Fl r Reinstall the zoneinfo file installed last time. The name is obtained from diff --git a/usr.sbin/tzsetup/tzsetup.c b/usr.sbin/tzsetup/tzsetup.c index 617de4efb765..6cd2e16b607c 100644 --- a/usr.sbin/tzsetup/tzsetup.c +++ b/usr.sbin/tzsetup/tzsetup.c @@ -744,42 +744,109 @@ static void message_zoneinfo_file(const char *title, char *prompt) static int install_zoneinfo_file(const char *zoneinfo_file) { + char buf[1024]; char prompt[SILLY_BUFFER_SIZE]; + struct stat sb; + ssize_t len; + int fd1, fd2, copymode; + + if (lstat(path_localtime, &sb) < 0) { + /* Nothing there yet... */ + copymode = 1; + } else if (S_ISLNK(sb.st_mode)) + copymode = 0; + else + copymode = 1; #ifdef VERBOSE - snprintf(prompt, sizeof(prompt), "Creating symbolic link %s to %s", - path_localtime, zoneinfo_file); + if (copymode) + snprintf(prompt, sizeof(prompt), + "Copying %s to %s", zoneinfo_file, path_localtime); + else + snprintf(prompt, sizeof(prompt), + "Creating symbolic link %s to %s", + path_localtime, zoneinfo_file); message_zoneinfo_file("Info", prompt); #endif if (reallydoit) { - if (access(zoneinfo_file, R_OK) != 0) { - snprintf(prompt, sizeof(prompt), - "Cannot access %s: %s", zoneinfo_file, - strerror(errno)); - message_zoneinfo_file("Error", prompt); - return (DITEM_FAILURE | DITEM_RECREATE); - } - if (unlink(path_localtime) < 0 && errno != ENOENT) { - snprintf(prompt, sizeof(prompt), - "Could not delete %s: %s", - path_localtime, strerror(errno)); - message_zoneinfo_file("Error", prompt); - return (DITEM_FAILURE | DITEM_RECREATE); - } - if (symlink(zoneinfo_file, path_localtime) < 0) { - snprintf(prompt, sizeof(prompt), - "Cannot create symbolic link %s to %s: %s", - path_localtime, zoneinfo_file, - strerror(errno)); - message_zoneinfo_file("Error", prompt); - return (DITEM_FAILURE | DITEM_RECREATE); + if (copymode) { + fd1 = open(zoneinfo_file, O_RDONLY, 0); + if (fd1 < 0) { + snprintf(prompt, sizeof(prompt), + "Could not open %s: %s", zoneinfo_file, + strerror(errno)); + message_zoneinfo_file("Error", prompt); + return (DITEM_FAILURE | DITEM_RECREATE); + } + + if (unlink(path_localtime) < 0 && errno != ENOENT) { + snprintf(prompt, sizeof(prompt), + "Could not delete %s: %s", + path_localtime, strerror(errno)); + message_zoneinfo_file("Error", prompt); + return (DITEM_FAILURE | DITEM_RECREATE); + } + + fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY, + S_IRUSR | S_IRGRP | S_IROTH); + if (fd2 < 0) { + snprintf(prompt, sizeof(prompt), + "Could not open %s: %s", + path_localtime, strerror(errno)); + message_zoneinfo_file("Error", prompt); + return (DITEM_FAILURE | DITEM_RECREATE); + } + + while ((len = read(fd1, buf, sizeof(buf))) > 0) + if ((len = write(fd2, buf, len)) < 0) + break; + + if (len == -1) { + snprintf(prompt, sizeof(prompt), + "Error copying %s to %s %s", zoneinfo_file, + path_localtime, strerror(errno)); + message_zoneinfo_file("Error", prompt); + /* Better to leave none than a corrupt one. */ + unlink(path_localtime); + return (DITEM_FAILURE | DITEM_RECREATE); + } + close(fd1); + close(fd2); + } else { + if (access(zoneinfo_file, R_OK) != 0) { + snprintf(prompt, sizeof(prompt), + "Cannot access %s: %s", zoneinfo_file, + strerror(errno)); + message_zoneinfo_file("Error", prompt); + return (DITEM_FAILURE | DITEM_RECREATE); + } + if (unlink(path_localtime) < 0 && errno != ENOENT) { + snprintf(prompt, sizeof(prompt), + "Could not delete %s: %s", + path_localtime, strerror(errno)); + message_zoneinfo_file("Error", prompt); + return (DITEM_FAILURE | DITEM_RECREATE); + } + if (symlink(zoneinfo_file, path_localtime) < 0) { + snprintf(prompt, sizeof(prompt), + "Cannot create symbolic link %s to %s: %s", + path_localtime, zoneinfo_file, + strerror(errno)); + message_zoneinfo_file("Error", prompt); + return (DITEM_FAILURE | DITEM_RECREATE); + } } #ifdef VERBOSE - snprintf(prompt, sizeof(prompt), - "Created symbolic link from %s to %s", zoneinfo_file, - path_localtime); + if (copymode) + snprintf(prompt, sizeof(prompt), + "Copied timezone file from %s to %s", + zoneinfo_file, path_localtime); + else + snprintf(prompt, sizeof(prompt), + "Created symbolic link from %s to %s", + zoneinfo_file, path_localtime); message_zoneinfo_file("Done", prompt); #endif } /* reallydoit */