chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
timedatectl: many fixes
[elogind.git]
/
src
/
timedate
/
timedatectl.c
diff --git
a/src/timedate/timedatectl.c
b/src/timedate/timedatectl.c
index 1d10c195c442c317c37d93828fbfcbf906c2e0e2..89913cc4edc5915965eb1e70ed0959670024736d 100644
(file)
--- a/
src/timedate/timedatectl.c
+++ b/
src/timedate/timedatectl.c
@@
-77,31
+77,30
@@
static void print_status_info(const StatusInfo *i) {
struct tm tm;
time_t sec;
bool have_time = false;
struct tm tm;
time_t sec;
bool have_time = false;
+ const char *old_tz = NULL, *tz;
int r;
assert(i);
int r;
assert(i);
- /* Enforce the values of /etc/localtime */
- if (getenv("TZ")) {
- fprintf(stderr, "Warning: Ignoring the TZ variable.\n\n");
- unsetenv("TZ");
- }
+ /* Save the old $TZ */
+ tz = getenv("TZ");
+ if (tz)
+ old_tz = strdupa(tz);
- r = setenv("TZ", i->timezone, false);
- if (r < 0) {
- log_error_errno(errno, "Failed to set TZ environment variable: %m");
- exit(EXIT_FAILURE);
- }
- tzset();
+ /* Set the new $TZ */
+ if (setenv("TZ", i->timezone, true) < 0)
+ log_warning_errno(errno, "Failed to set TZ environment variable, ignoring: %m");
+ else
+ tzset();
if (i->time != 0) {
sec = (time_t) (i->time / USEC_PER_SEC);
have_time = true;
if (i->time != 0) {
sec = (time_t) (i->time / USEC_PER_SEC);
have_time = true;
- } else if (IN_SET(arg_transport, BUS_TRANSPORT_
REMOTE
, BUS_TRANSPORT_MACHINE)) {
+ } else if (IN_SET(arg_transport, BUS_TRANSPORT_
LOCAL
, BUS_TRANSPORT_MACHINE)) {
sec = time(NULL);
have_time = true;
} else
sec = time(NULL);
have_time = true;
} else
-
fprintf(stderr, "Warning: Could not get time from timedated and not operating locally.\n\n
");
+
log_warning("Could not get time from timedated and not operating locally, ignoring.
");
if (have_time) {
xstrftime(a, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm));
if (have_time) {
xstrftime(a, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm));
@@
-117,7
+116,7
@@
static void print_status_info(const StatusInfo *i) {
if (i->rtc_time > 0) {
time_t rtc_sec;
if (i->rtc_time > 0) {
time_t rtc_sec;
- rtc_sec = (time_t)(i->rtc_time / USEC_PER_SEC);
+ rtc_sec = (time_t)
(i->rtc_time / USEC_PER_SEC);
xstrftime(a, "%a %Y-%m-%d %H:%M:%S", gmtime_r(&rtc_sec, &tm));
printf(" RTC time: %.*s\n", (int) sizeof(a), a);
} else
xstrftime(a, "%a %Y-%m-%d %H:%M:%S", gmtime_r(&rtc_sec, &tm));
printf(" RTC time: %.*s\n", (int) sizeof(a), a);
} else
@@
-126,6
+125,16
@@
static void print_status_info(const StatusInfo *i) {
if (have_time)
xstrftime(a, "%Z, %z", localtime_r(&sec, &tm));
if (have_time)
xstrftime(a, "%Z, %z", localtime_r(&sec, &tm));
+ /* Restore the $TZ */
+ if (old_tz)
+ r = setenv("TZ", old_tz, true);
+ else
+ r = unsetenv("TZ");
+ if (r < 0)
+ log_warning_errno(errno, "Failed to set TZ environment variable, ignoring: %m");
+ else
+ tzset();
+
printf(" Time zone: %s (%.*s)\n"
" NTP enabled: %s\n"
"NTP synchronized: %s\n"
printf(" Time zone: %s (%.*s)\n"
" NTP enabled: %s\n"
"NTP synchronized: %s\n"