home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / mod.std.unix.v5 / text0002.txt < prev    next >
Encoding:
Internet Message Format  |  1987-06-30  |  12.3 KB

  1. Date: Wed, 1 Jan 86 18:39:26 est
  2. From: seismo!cbpavo.cbosgd.ATT.UUCP!mark@sally.UTEXAS.EDU (Mark Horton)
  3.  
  4. The latest draft asked for input about time zones.  I'd like to
  5. make a few comments.
  6.  
  7. There are two basic ways that time zones are done today.  There
  8. is the V7 method (where the zone offset is in the kernel) and the
  9. System III method (where the zone offset and name is in an environment
  10. variable.)  4.2BSD descends from V7 (although it has a fancier "offset
  11. to zone name" conversion algorithm that knows more about the world)
  12. and System V descends from System III.
  13.  
  14. There are elegance considerations (e.g. should the kernel know or
  15. care about time zones?) and efficiency considerations (e.g. is it
  16. faster to look in the environment, do a system call, or read a file.)
  17. But both of these are dwarfed by a much more important consideration:
  18. does it work properly in all cases?  I claim that neither method is
  19. correct all the time, but the V7 method is right more often than the
  20. System III method.
  21.  
  22. In V7, when you configure your kernel, you tell it the zone offset,
  23. in minutes, from GMT, and whether you observe Daylight time.  These
  24. numbers are stored in the kernel, which doesn't do anything with them
  25. except return them when an ftime system call asks for them.  So, in
  26. effect, they are in the kernel for administrative convenience.  (You
  27. don't have to open a file, and they aren't compiled into ctime, so it
  28. isn't necessary to relink every program that calls ctime or localtime
  29. when you install a new system.)  The smarts that generate the time zone
  30. name and decide if Daylight time is in effect are in ctime in user code.
  31. (By comparison, in TOPS 20, the equivalent of ctime is a system call,
  32. with lots of options for the format.  This may seem inelegant, but it
  33. results in only one copy of the code on the system, even without shared
  34. libraries.)
  35.  
  36. In System III, the kernel doesn't know about time zones at all.  The
  37. environment variable TZ stores both the zone names and the zone offset,
  38. and ctime looks there.  This makes things very flexible - no assumptions
  39. about 3 character zone names, and it's easy for a person dialing in from
  40. a different time zone to run in their own time zone.  Also, it's very
  41. efficient to look in the environment - faster than a system call.
  42.  
  43. However, there are some very serious problems with the System III method.
  44. One problem is that, with an offset measured in hours, places like
  45. Newfoundland, Central Australia, and Saudi Arabia, which don't have
  46. even hour time zones, are in trouble.  But that's easy to fix in the standard.
  47.  
  48. The time zone is configured into the system by modifying /etc/profile,
  49. which is a shell script of startup commands run by the Bourne shell when
  50. any user logs in, much like .profile or .login.  This means that we assume
  51. everybody is using the Bourne shell.  This is a false assumption - one of
  52. the documented features of UNIX ever since V6 is that the shell is an
  53. ordinary program, and a user can have any shell they like.  In particular,
  54. the Berkeley C shell does not read /etc/profile, so all csh users don't get
  55. a TZ variable set up for them in every System III or V UNIX I've ever used.
  56.  
  57. Well, after all, the Bourne shell is the standard shell, and everybody should
  58. use the standard shell, right?  After all, the new Korn shell reads and
  59. understands /etc/profile.
  60.  
  61. Even if we believe the above statement and ignore the documented feature
  62. of being able to put your favorite shell in the passwd file (and I don't)
  63. we still get into trouble.  For example, uucp has a special shell: uucico.
  64. It doesn't read /etc/profile.  And what about programs that don't get run
  65. from a login shell?  For example, all the background daemons run out of
  66. /etc/rc?  Or programs run from cron?  Or from at?  Or programs run while
  67. single user?  None of these programs get a TZ.
  68.  
  69. Does it matter if a non-interactive program is in the wrong time zone?
  70. After all, the files it touches are touched in GMT.  The answer is yes:
  71. background processes generally keep logs, and the logs have time stamps.
  72. For example, uucico gets started hourly out of crontab, and this means
  73. that almost any uucico on the system (from crontab or from another system
  74. logging in) will run in the wrong time zone.  Since L.sys has restrictions
  75. on the times it can dial out, being in the wrong time zone can cause calls
  76. to be placed during the day, even if this is supposedly forbidden in L.sys.
  77. Also, of course, things like "date > /dev/console" every hour from crontab
  78. will have problems.
  79.  
  80. It turns out that System III has a "default time zone" which is used by
  81. localtime if there is no TZ variable.  On every version of System III or
  82. V I've ever used, this is set to the time zone of the developer.  It's
  83. EST in the traditional versions from AT&T.  It's PST in Xenix.  So the
  84. developers of the system never see any problems - uucp logs are right,
  85. for example, and csh users still get the right time.  Until they ship
  86. the system out of their time zone.
  87.  
  88. This problem isn't really that hard to fix.  You just have init open
  89. a configuration file when it starts up, and set its own environment
  90. from there.  (If you're willing to have init open files that early.)
  91.  
  92. But it turns out there is an even more serious problem with the TZ
  93. environment variable method.  It's a security problem.  Let's say the
  94. system administrator has configured UUCP to only call out when the
  95. phone rates are low, because the site is poor and can't afford daytime
  96. rates, or to keep the machine load low during the day.  But some user
  97. wants to push something through right away.  He sets TZ to indicate that
  98. he's in, say, China.  Now, he starts up a uucico (or a cu.)  The localtime
  99. routine believes the forged TZ and thinks it's within the allowed time zone,
  100. and an expensive phone call is placed.  The log will be made in the wrong
  101. time zone too, so unless the SA is sharp, he won't notice until the phone
  102. bill shows up.
  103.  
  104. The fundamental difference between the two approaches is that the V7
  105. method makes the timezone a per-system entity, while the Sys III method
  106. makes the timezone a per-process entity.  While an argument can be made
  107. that users dialing in from other time zones might want their processes
  108. to be in their local time zone, this isn't a very strong argument.
  109. (I've never seen anyone actually do it.)  [This is a symptom of a disease
  110. that is affecting UNIX: a tendency to put things in the environment that
  111. are not per-process.  David Yost pointed out, for example, that TERM is
  112. not a per-process entity, it's a per-port entity.  Berkeley's V6 had a
  113. file in /etc with per-port terminal codes, similar to /etc/utmp, but
  114. we've actually taken a step backwards by putting it into the environment.
  115. Take a look at tset and people's .profile's and .login's to see the
  116. complexity this decision has cost us.]
  117.  
  118. So anyway, so far I've argued that the System III method is inadequate.
  119. How about the V7 method?
  120.  
  121. The V7 method doesn't suffer from any of the weaknesses described above.
  122. It does require a system call to get the time zone, which is a bit more
  123. overhead than a getenv, and the kernel doesn't have any business knowing
  124. about time zones.  (The same argument could be made that the kernel doesn't
  125. have any business knowing the host name, too, but both System III and
  126. 4.2BSD have that information in the kernel, and it works awfully well.)
  127.  
  128. The weaknesses in the V7/4.2BSD method are in the time zone name
  129. (since it's computed from a table and the offset value) and in the
  130. rule for deciding when DST begins and ends.  The second problem is
  131. also present in the Sys III method.
  132.  
  133. Suppose localtime finds out that the offset is +60, that is, we are
  134. one hour east of GMT.  What time zone name do we use?  Well, if we're
  135. France, it might be MET (Middle European Time.)  If we're in Germany,
  136. it might be MEZ (Mitten European Zeit.)  I probably have the specifics
  137. wrong (I doubt that the French tell time in English) but you get the
  138. idea.  An offset just specifies 1/24 of the world, and moving north/south
  139. along that zone you can get a lot of countries, each with widely varying
  140. languages and time zone names.  Even Alaska/Hawaii had trouble sharing
  141. a time zone.  (The mapping in the other direction is ambiguous too, there
  142. has been lots of amusement and frustration from code that thought BST was
  143. Bering Standard Time, when run in England in July and fed the local
  144. abbreviation for British Summer Time.  This is why electronic mail and
  145. news standards currently recommend that messages be stamped in UTC.
  146. Or is that UT?  Or GMT?  Ick.)  So far we've survived because there tends
  147. to be a dominant time zone name in each zone where UNIX has appeared, and
  148. source has been present for the places that have to change it.  But as UNIX
  149. becomes more popular in places like Africa, Eastern Europe, and Asia, this
  150. will get a lot messier, especially with binary licenses.
  151.  
  152. The decision about when daylight time begins and ends is more interesting.
  153. If you read the manual page or the code, you'll discover that localtime
  154. knows rules like "the 3rd Sunday in October" and has a table with special
  155. hacks for 1974 and 1975, when the US Congress decided to change things.
  156. This table "can be extended if necessary".  Of course, extending the table
  157. means modifying the source and recompiling the world.  Might be hard on
  158. all those binary systems, especially the ones without a programmer on staff.
  159. This hasn't been a problem yet, but now Congress is making noises about
  160. moving the dates around a bit.  It's a controversial proposal, and I wouldn't
  161. be surprised if they try two or three rules before the pick one they like.
  162. Given all the old releases still out there, and the development time for
  163. a new release, we need about a 2 year warning of such an impending change.
  164. We'll be lucky to get 6 months.
  165.  
  166. So what do we do about all this?  Well, I think the basic requirements are
  167. that
  168.  
  169.  (1) The time zone should be a per-system entity.  There should only be
  170.      one place on each system where the zone is specified to ensure that
  171.      all programs on the system use the same notion of time zone.
  172.  
  173.  (2) The time zone offset, names, and daylight conventions should be
  174.      easily configured by the system administrator.  We should have a
  175.      standard that allows zone offsets in minutes (maybe even seconds,
  176.      I don't know how precise Saudi Arabia needs), zone names of arbitrary
  177.      length (they are 7 characters in Australia, for example), whether
  178.      we use daylight time at all, when daylight time begins, and when it ends.
  179.      The latter two must be allowed to vary as a function of the year.
  180.  
  181. The exact method for doing this isn't clear.  We certainly need a configuration
  182. file.  But interpreting this file on each call to ctime isn't a good idea.
  183. It would be nice to have /etc/rc look at the source file and plug a simple
  184. interpretation of it into either a binary file or the kernel, but we have
  185. to worry about what happens if the system is up (and processes are running)
  186. when we convert over to or from daylight time.  Perhaps cron has to run a
  187. program to update it every hour.  You could have cron only run this program
  188. twice a year, but this would require putting the configuration information
  189. into crontab (which doesn't understand things like "3rd Sunday in October")
  190. and would lose if the system happened to be down at conversion time.  Also,
  191. the algorithm has to work for dates that aren't this year, e.g. "ls -l" of
  192. an old file.
  193.  
  194. How much of this does P1003 need to specify?  After all, if they are just
  195. specifying sections 2 and 3, then the file format and the method for making
  196. sure things are right should be up to the implementor.  Well, at a minimum,
  197. we need ctime and localtime.  We also a standard way to get the time zone
  198. name and offset - there is a lot of ifdeffed code out there that either
  199. looks for TZ or calls ftime - and whether daylight time applies (and by
  200. how much) for a given time.
  201.  
  202. But there's more.  When the mood strikes Congress to change the rules and
  203. gives us 2 months notice, it ought to be possible to publish a new table
  204. that everybody with a P1003 system can just type in.  It would be nice if
  205. the location and format of this table were standardized.  (After all, the
  206. US Congress doesn't set the rules for the rest of the world, and they are
  207. just as subject to having arbitrary bodies with different rules.)
  208.  
  209. Finally, there needs to be a requirement that the time zone always work.
  210. Some discussion of these issues should be present.  Otherwise, some
  211. implementor is going to think that the System III method works adequately.
  212.  
  213.     Mark Horton
  214.  
  215. Volume-Number: Volume 5, Number 3
  216.  
  217.