Re: git: fc43a1b6842a - stable/14 - tzsetup: symlink /etc/localtime instead of copying

From: Herbert J. Skuhra <herbert_at_gojira.at>
Date: Sun, 01 Sep 2024 21:12:46 UTC
On Fri, 30 Aug 2024 09:04:04 +0200, "Herbert J. Skuhra" <herbert@gojira.at> wrote:
> 
> On Tue, 27 Aug 2024 10:09:00 +0200, "Herbert J. Skuhra" wrote:
> > 
> > On Thu, 08 Aug 2024 06:35:38 +0200, "Sean C. Farley" wrote:
> > > 
> > > On Thu, 1 Aug 2024, Ed Maste wrote:
> > > 
> > > > The branch stable/14 has been updated by emaste:
> > > > 
> > > > URL: https://cgit.FreeBSD.org/src/commit/?id=fc43a1b6842afa806dfd7ba48de5bece63d04456
> > > > 
> > > > commit fc43a1b6842afa806dfd7ba48de5bece63d04456
> > > > Author:     Ed Maste <emaste@FreeBSD.org>
> > > > AuthorDate: 2022-10-14 16:44:35 +0000
> > > > Commit:     Ed Maste <emaste@FreeBSD.org>
> > > > CommitDate: 2024-08-01 15:11:45 +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
> > > > 
> > > >    (cherry picked from commit 5e16809c953f4cd19fadb1767469dec319de0353)
> > > 
> > > I ran across an issue with this when using "etcupdate -D" to update a
> > > jail from the host.  "tzsetup -r -C /tmp/chroot", as called by
> > > etcupdate, prepends the path of the chroot to the link which breaks
> > > things inside the jail.
> > 
> > I have this issue whenerver I update jails with 'make installworld
> > DESTDIR=$X'. Will this be fixed or reverted (at least) in stable/14?
> > Or works as expected? 
> 
> Maybe:
> 
> diff --git a/usr.sbin/tzsetup/tzsetup.c b/usr.sbin/tzsetup/tzsetup.c
> index 617de4efb765..38d7ccf5e00c 100644
> --- a/usr.sbin/tzsetup/tzsetup.c
> +++ b/usr.sbin/tzsetup/tzsetup.c
> @@ -884,7 +884,7 @@ main(int argc, char **argv)
>         } else {
>                 sprintf(path_zonetab, "%s/%s", chrootenv, _PATH_ZONETAB);
>                 sprintf(path_iso3166, "%s/%s", chrootenv, _PATH_ISO3166);
> -               sprintf(path_zoneinfo, "%s/%s", chrootenv, _PATH_ZONEINFO);
> +               sprintf(path_zoneinfo, "%s", _PATH_ZONEINFO);
>                 sprintf(path_localtime, "%s/%s", chrootenv, _PATH_LOCALTIME);
>                 sprintf(path_db, "%s/%s", chrootenv, _PATH_DB);
>                 sprintf(path_wall_cmos_clock, "%s/%s", chrootenv,

Or:

diff --git a/usr.sbin/tzsetup/tzsetup.c b/usr.sbin/tzsetup/tzsetup.c
index 617de4efb765..30d019214ab5 100644
--- a/usr.sbin/tzsetup/tzsetup.c
+++ b/usr.sbin/tzsetup/tzsetup.c
@@ -884,7 +884,7 @@ main(int argc, char **argv)
        } else {
                sprintf(path_zonetab, "%s/%s", chrootenv, _PATH_ZONETAB);
                sprintf(path_iso3166, "%s/%s", chrootenv, _PATH_ISO3166);
-               sprintf(path_zoneinfo, "%s/%s", chrootenv, _PATH_ZONEINFO);
+               strcpy(path_zoneinfo, _PATH_ZONEINFO);
                sprintf(path_localtime, "%s/%s", chrootenv, _PATH_LOCALTIME);
                sprintf(path_db, "%s/%s", chrootenv, _PATH_DB);
                sprintf(path_wall_cmos_clock, "%s/%s", chrootenv,
		
With the unpatched version of tzsetup I get:

60294: open("/mnt//var/db/zoneinfo",O_RDONLY,0666) = 3 (0x3)
60294: fstat(3,{ mode=-rw-r--r-- ,inode=16728,size=14,blksize=4096 }) = 0 (0x0)
60294: read(3,"Europe/Berlin\n",4096)            = 14 (0xe)
60294: access("/mnt//usr/share/zoneinfo/Europe/Berlin",R_OK) = 0 (0x0)
60294: unlink("/mnt//etc/localtime")             = 0 (0x0)
60294: symlink("/mnt//usr/share/zoneinfo/Europe/Berlin","/mnt//etc/localtime") = 0 (0x0)
60294: open("/mnt//var/db/zoneinfo",O_WRONLY|O_CREAT|O_TRUNC,0666) = 4 (0x4)
60294: fstat(4,{ mode=-rw-r--r-- ,inode=16728,size=0,blksize=4096 }) = 0 (0x0)
60294: write(4,"Europe/Berlin\n",14)             = 14 (0xe)

# ls -l /mnt/etc/localtime
lrwxr-xr-x  1 root wheel 38 Sep  1 22:30 /mnt/etc/localtime -> /mnt//usr/share/zoneinfo/Europe/Berlin

And with the patched version:

61015: open("/mnt//var/db/zoneinfo",O_RDONLY,0666) = 3 (0x3)
61015: fstat(3,{ mode=-rw-r--r-- ,inode=16728,size=14,blksize=4096 }) = 0 (0x0)
61015: read(3,"Europe/Berlin\n",4096)            = 14 (0xe)
61015: access("/usr/share/zoneinfo/Europe/Berlin",R_OK) = 0 (0x0)
61015: unlink("/mnt//etc/localtime")             = 0 (0x0)
61015: symlink("/usr/share/zoneinfo/Europe/Berlin","/mnt//etc/localtime") = 0 (0x0)
61015: open("/mnt//var/db/zoneinfo",O_WRONLY|O_CREAT|O_TRUNC,0666) = 4 (0x4)
61015: fstat(4,{ mode=-rw-r--r-- ,inode=16728,size=0,blksize=4096 }) = 0 (0x0)
61015: write(4,"Europe/Berlin\n",14)             = 14 (0xe)

# ls -l /mnt/etc/localtime
lrwxr-xr-x  1 root wheel 33 Sep  1 22:31 /mnt/etc/localtime -> /usr/share/zoneinfo/Europe/Berlin

But maybe the link should be created like:

# ls -l /mnt/etc/localtime
lrwxr-xr-x  1 root wheel 38 Sep  1 23:07 /mnt/etc/localtime -> ../../usr/share/zoneinfo/Europe/Berlin

--
Herbert