1 # Functions for getting and setting the timezone on Linux
3 $timezones_file = "/usr/share/zoneinfo/zone.tab";
4 $currentzone_link = "/etc/localtime";
5 $currentzone_file = "/etc/timezone";
6 $timezones_dir = "/usr/share/zoneinfo";
7 $sysclock_file = "/etc/sysconfig/clock";
14 &open_readfile(ZONE, $timezones_file) || return ( );
18 if (/^(\S+)\s+(\S+)\s+(\S+)\s+(\S.*)/) {
19 push(@rv, [ $3, $4 ]);
22 elsif (/^(\S+)\s+(\S+)\s+(\S+)/) {
23 push(@rv, [ $3, undef ]);
28 push(@rv, [ "GMT", "GMT" ]) if (!$done{'GMT'});
29 push(@rv, [ "UTC", "UTC" ]) if (!$done{'UTC'});
30 return sort { $a->[0] cmp $b->[0] } @rv;
33 # get_current_timezone()
34 sub get_current_timezone
36 local $lnk = readlink(&translate_filename($currentzone_link));
39 $lnk =~ s/$timezones_dir\///;
43 # Need to compare with all timezone files!
44 return &find_same_zone($currentzone_link);
48 # set_current_timezone(zone)
49 sub set_current_timezone
51 &lock_file($currentzone_link);
52 unlink(&translate_filename($currentzone_link));
53 symlink(&translate_filename("$timezones_dir/$_[0]"),
54 &translate_filename($currentzone_link));
55 &unlock_file($currentzone_link);
57 if (-r $currentzone_file) {
58 # This file is used on Debian systems
59 &open_lock_tempfile(FILE, ">$currentzone_file");
60 &print_tempfile(FILE, $_[0],"\n");
61 &close_tempfile(FILE);
65 if (&read_env_file($sysclock_file, \%clock)) {
66 $clock{'ZONE'} = $_[0];
67 &lock_file($sysclock_file);
68 &write_env_file($sysclock_file, \%clock);
69 &unlock_file($sysclock_file);
75 return -r $timezones_file;
80 local @rv = ( $currentzone_link );
81 push(@rv, $currentzone_file) if (-r $currentzone_file);
82 push(@rv, $sysclock_file) if (-r $sysclock_file);