ATT System V Rlease 3.1 and Timezones

Guy Harris seismo!sun!guy
Sat Dec 13 21:23:28 UTC 1986

	> 2.  Init (/etc/init == process 1) reads and parses this file  and
	> sets the environment of all children processes with the TZ
	> variable...

	  There is no guarentee that some fiend doesn't step on the value
	before passing it to someone else.  Even if there are no fiends, there
	may be remote users.  One needs a mechanism to find out the correct
	timezone information from an unimpeachable source.  "Source'ing"
	/etc/timezone is not slick if your process isn't the Bourne/Korn shell.

True, but assuming that "/etc/TIMEZONE" has the format


that file can easily be parsed by a program other than a shell.  (Nothing
more is needed in "/etc/TIMEZONE"; e.g., if you want to export "TZ" after
fetching it from "/etc/TIMEZONE", you just do "export TZ" after sourcing

Given that, if the argument to "settz" were "(char *)NULL", "settz" could
fetch the machine's local time zone by doing something like

	register int fd;
	static char tzbuf[SIZE + 1];
	register int i;

	fd = open("/etc/timezone, O_RDONLY);
	if ((i = read(fd, tzbuf, SIZE + 1)) < 0)
		return (-1);

	 * The "SIZE + 1" is a hack to detect overly-long files.
	 * We advertise SIZE as the maximum size, and if there's anything
	 * after it, we complain.
	if (i == SIZE + 1)
		return (-1);

	if (i < 4)
		return (-1);	/* doesn't start with "TZ=" */

	if (strncmp(tzbuf, "TZ=", 3) != 0)
		return (-1);	/* doesn't start with "TZ=" */

	if (tzload(tzbuf + 3, &s) == -1)
		return (-1);

More information about the tz mailing list