From nobody Fri Nov 24 02:17:11 2023 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 4SbzBv74Dtz526rL; Fri, 24 Nov 2023 02:17:11 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SbzBv6PPFz3LHD; Fri, 24 Nov 2023 02:17:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700792231; 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=9iZjghIhefOTZAkJQqJYXdC8hwZw5HPjsaGUENGTJoQ=; b=is8AeFsDMnVBtdLgZ4d40qWZzSc2rA+Rs71w9ZI++levtxiTxV9ksEC+eLTAyt5yeThveo KpGtWGLE3M14EqEnb4ZkFhiypf0+QOyDLZmhY8E+Bdu0fCxA7jAPLIkHB0W5BGZkSuAGT2 WyxLN2N3bCoXtq5ThDseumiDu/FmW7OT93RZ0gubfBW8t4dv3WgPXmPhE3kMC7w3MBFV5W dU0RSZlCbUl6UNUZ6GRA3XFyyp6n2LQTyvKWZbR/Ktd4sqB8x/KaklMg4Gxmy01/T6XTc1 zRb0JX0E8mfOyYtkx5QTlBWNdNJEogtK+r1YGhWVPQQyNBMue/E0I3LlMjUUAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700792231; 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=9iZjghIhefOTZAkJQqJYXdC8hwZw5HPjsaGUENGTJoQ=; b=PTicPM20TBgvUx+l7zGoM0p/aegJZNn2nEORAqbGRDrSqU7yLq7AvzF+dGarC3wbx6+NaR oZyaGgoKi+GlAsvsdBXI8KJEJ5XD5rby1cQAMdj1J6DxzS0MP5+yEHIWZ0NwqMyya2VM+4 evCUkrRJYHUWrTlgIu5WsT33t7K1NMxSe7eVKwsondaFl0NXLnaycx0Jp1M2SMzbF6uZhH YqmlG4nEHCRbCw2/SBnw4L+fxRNEg9GlMu/9Sf4NydtND1xZLJ6yiIHGQP/MEXXj8jJsSd xFng7S2Q6cBqouZZjqnDE+C2Hqh/12iadmmlG6Waop+mxDJGbpwZkf8enlRfYQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700792231; a=rsa-sha256; cv=none; b=VJM0Cf2xzfwvrZbvWLLpdUVoKAcKoJqmt3ZscIShYhG3KKlBbPaCZTp+9gEJOlwJIG4Oom uPHYypumxUFStDdmiVpj0Ei5XqzOUPdQyw8jb33sPkzRNDaUnmfaeng7M8yCT3C49l84Iq hekMw+2CwEZ/Gr+KslBMP+T4pP52kNGG2J0x4s4Mg0aJxhb14x/VUOfT/20RDqRzrX1ZYm jcCyP+TWH2HbkjUTsj0EJKDAxztfAVHrjZM/EAf1qodZ/FSMdDTQUWq/rMaFkblEfxyTNs cy7T5nn8z73EvrEuiuWNewIbtp2NRLbXTQP4oDS4llx3dR0KoaXnM2LSIILGFA== 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 4SbzBv5T5zzBhD; Fri, 24 Nov 2023 02:17:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3AO2HBdU026264; Fri, 24 Nov 2023 02:17:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AO2HBCq026261; Fri, 24 Nov 2023 02:17:11 GMT (envelope-from git) Date: Fri, 24 Nov 2023 02:17:11 GMT Message-Id: <202311240217.3AO2HBCq026261@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 5e16809c953f - main - tzsetup: symlink /etc/localtime instead of copying 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 5e16809c953f4cd19fadb1767469dec319de0353 Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=5e16809c953f4cd19fadb1767469dec319de0353 commit 5e16809c953f4cd19fadb1767469dec319de0353 Author: Ed Maste AuthorDate: 2022-10-14 16:44:35 +0000 Commit: Ed Maste CommitDate: 2023-11-24 02:13:49 +0000 tzsetup: symlink /etc/localtime instead of copying Using a symlink means that new timezone data (installed by an errata update, say) will be usable without having to be copied again. Reviewed by: bapt, kevans, philip Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37005 --- usr.sbin/tzsetup/tzsetup.8 | 2 +- usr.sbin/tzsetup/tzsetup.c | 119 ++++++++++----------------------------------- 2 files changed, 27 insertions(+), 94 deletions(-) diff --git a/usr.sbin/tzsetup/tzsetup.8 b/usr.sbin/tzsetup/tzsetup.8 index 109a52beb164..60461363da9a 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 copy files. +Do not create or symlink 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 f6440a0ea736..9610023ec3ea 100644 --- a/usr.sbin/tzsetup/tzsetup.c +++ b/usr.sbin/tzsetup/tzsetup.c @@ -744,109 +744,42 @@ 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 - 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); + snprintf(prompt, sizeof(prompt), "Creating symbolic link %s to %s", + path_localtime, zoneinfo_file); message_zoneinfo_file("Info", prompt); #endif if (reallydoit) { - 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); - } + 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); } - -#ifdef VERBOSE - if (copymode) + if (unlink(path_localtime) < 0 && errno != ENOENT) { snprintf(prompt, sizeof(prompt), - "Copied timezone file from %s to %s", - zoneinfo_file, path_localtime); - else + "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), - "Created symbolic link from %s to %s", - zoneinfo_file, path_localtime); + "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); message_zoneinfo_file("Done", prompt); #endif } /* reallydoit */