Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Feb 2015 18:11:02 -0800
From:      Xin Li <delphij@delphij.net>
To:        Nick Frampton <nick.frampton@akips.com>, freebsd-current@freebsd.org
Cc:        edwin@FreeBSD.org
Subject:   Re: tzsetup chroot
Message-ID:  <54D17FB6.1080400@delphij.net>
In-Reply-To: <54D1704B.8050900@akips.com>
References:  <54D1704B.8050900@akips.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------050606050705040702090400
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 02/03/15 17:05, Nick Frampton wrote:
> We have our own FreeBSD 10.1 installation script in which we call
> tzsetup.
> 
> I'm seeing different behaviour in tzsetup between these two
> invocations:
> 
> tzsetup -C /mnt chroot /mnt /usr/sbin/tzsetup
> 
> With the -C option, no matter which time zone I select, it asks:
> 
> Does the abbreviation 'UTC' look reasonable?
> 
> Using chroot, I get the expected behaviour, e.g. selecting 
> America/New_York:
> 
> Does the abbreviation 'EST' look reasonable?
> 
> /mnt contains the contents of base.txz, so it looks like all the 
> zoneinfo files are there.

Could you please submit a bug ticket for this?

It looks like what happens is that tzsetup does not really do a
chroot(2) system call.  Instead, it simulated the effect by prefixing
all paths with the chroot environment.

The problem is that when tzsetup is going to verify your
configuration, it would use tzset(3), which does not respect the
simulated chroot effect.  When no zoneinfo data is present, everything
would be considered as UTC.

Attached is an dirty hack (ugly enough that I don't wish to commit)
that changes tzsetup to use chroot instead, which should fix the
problem.  I'm not very satisfied with it as it does chroot() before
doing init_dialog, which may well fail as the devfs is not necessarily
mounted in the chroot, and on the other hand all termcap related data
would be sourced from the chroot, which is probably an undesirable
side effect.

Cheers,
- -- 
Xin LI <delphij@delphij.net>    https://www.delphij.net/
FreeBSD - The Power to Serve!           Live free or die
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.1.1 (FreeBSD)

iQIcBAEBCgAGBQJU0X+zAAoJEJW2GBstM+nsfpwQAIwPBj11lzJS662RPBPQR6dB
vb3gCGJjqRANCD+Sr8EqxzPlKOcC4UiBB5Khy39lidC+d4qgGQ3Mz3qIwjCdl3Aw
KUzkFfhvspGzE25tIwsPJ3A00NjXNJGqGqcDMitfls4SdYZWzCgs+gwa3zGq+yO3
/pPMQVVhhBz2pgkqxCtznFqY9paN5lzwaOqp9HepNz1g99Q4u+KpIUI93BMcMdMD
9HtY7YQYzDCnhi4OskdIB2BrLm1NSFPMkALASTMuCplFwtyI+emYD/GzOwUF5zay
Vk4QQ33Z9G1pw6jU730kFl/FU5tps35leUYUMcgiz2CG9DTz/wFRJ4SjwD4b1NYx
35nwbrhnp5TV4g94zFfY1NejSwmCpdzq5fvSYwu73yQ+pzwqA2xjXGMwICEo95Tj
Zop/T9gU3g2Hglmz6zTe7m4EXdruFZrADlI6K6cPg/52HosSi7iLnkebwX0nClbQ
HQeCdved38nzRBDZGaJmrDebHD3Uy+qrP5dxTaDe49JZZ+lnkceqy5s+OLQb78S3
Wt9q6GgdKLwa157K74ci/T3rSnty+dJlOXlaq2Bhbru8O7GGmIcmMtsAYzI7+C0z
0cuqsI2sXvT6i/XSjt2VK0D/aQfJ0NfpWDJ6rtlAnFc0g5UBncd8MrAfWo/KOPdH
nIdamgVfmtHcglu07fBq
=0pwZ
-----END PGP SIGNATURE-----

--------------050606050705040702090400
Content-Type: text/plain; charset=UTF-8;
 name="tzsetup.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
 filename="tzsetup.diff"

Index: tzsetup.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- tzsetup.c	(revision 278173)
+++ tzsetup.c	(working copy)
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sysexits.h>
 #include <time.h>
 #include <unistd.h>
=20
@@ -944,24 +945,19 @@ main(int argc, char **argv)
 	if (argc - optind > 1)
 		usage();
=20
-	if (chrootenv =3D=3D NULL) {
-		strcpy(path_zonetab, _PATH_ZONETAB);
-		strcpy(path_iso3166, _PATH_ISO3166);
-		strcpy(path_zoneinfo, _PATH_ZONEINFO);
-		strcpy(path_localtime, _PATH_LOCALTIME);
-		strcpy(path_db, _PATH_DB);
-		strcpy(path_wall_cmos_clock, _PATH_WALL_CMOS_CLOCK);
-	} 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_localtime, "%s/%s", chrootenv, _PATH_LOCALTIME);
-		sprintf(path_db, "%s/%s", chrootenv, _PATH_DB);
-		sprintf(path_wall_cmos_clock, "%s/%s", chrootenv,
-		    _PATH_WALL_CMOS_CLOCK);
+	strcpy(path_zonetab, _PATH_ZONETAB);
+	strcpy(path_iso3166, _PATH_ISO3166);
+	strcpy(path_zoneinfo, _PATH_ZONEINFO);
+	strcpy(path_localtime, _PATH_LOCALTIME);
+	strcpy(path_db, _PATH_DB);
+	strcpy(path_wall_cmos_clock, _PATH_WALL_CMOS_CLOCK);
+
+	if (chrootenv !=3D NULL) {
+		rv =3D chroot(chrootenv);
+		if (rv !=3D 0)
+			err(EX_OSERR, "chroot to %s", chrootenv);
 	}
=20
-
 	/* Override the user-supplied umask. */
 	(void)umask(S_IWGRP | S_IWOTH);
=20

--------------050606050705040702090400--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?54D17FB6.1080400>