1 # Functions for getting and setting the timezone on Linux
3 $timezone_file = "/etc/TIMEZONE";
4 $timezones_dir = "/usr/share/lib/zoneinfo";
5 $rtc_config = "/etc/rtc_config";
12 &open_execute_command(FIND, "find $timezones_dir -type f", 1);
13 while($file = <FIND>) {
16 &open_readfile(INFO, $file);
20 # A timezone file we can use!
21 $file =~ s/^$timezones_dir\///;
22 push(@rv, [ $file, undef ]);
26 return sort { $a->[0] cmp $b->[0] } @rv;
29 # get_current_timezone()
30 sub get_current_timezone
33 &read_env_file($timezone_file, \%tz);
38 # set_current_timezone(zone)
39 sub set_current_timezone
42 &lock_file($timezone_file);
43 &read_env_file($timezone_file, \%tz);
45 &write_env_file($timezone_file, \%tz);
46 &unlock_file($timezone_file);
49 # Update x86 RTC timezone too
50 &lock_file($rtc_config);
52 &read_env_file($rtc_config, \%rtc);
53 $rtc{'zone_info'} = $_[0];
54 &write_env_file($rtc_config, \%rtc);
55 &unlock_file($rtc_config);
61 return -r $timezone_file && -d $timezones_dir;
66 return ( $timezone_file );