[systemd-devel] [PATCH] timedatectl: fix when queried system has differn't timezone
Lennart Poettering
lennart at poettering.net
Thu Apr 2 02:55:35 PDT 2015
On Mon, 23.03.15 04:44, Shawn Landden (shawn at churchofgit.com) wrote:
> Also allow getting time from time(2) when BUS_TRANSPORT_MACHINE.
>
> v2: check for error
> ---
> src/timedate/timedatectl.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
> index 9e04f8f..44d329e 100644
> --- a/src/timedate/timedatectl.c
> +++ b/src/timedate/timedatectl.c
> @@ -106,14 +106,21 @@ static void print_status_info(const StatusInfo *i) {
>
> /* Enforce the values of /etc/localtime */
> if (getenv("TZ")) {
> - fprintf(stderr, "Warning: Ignoring the TZ variable. Reading the system's time zone setting only.\n\n");
> + fprintf(stderr, "Warning: Ignoring the TZ variable.\n\n");
> unsetenv("TZ");
> }
>
> + r = setenv("TZ", i->timezone, false);
> + if (r < 0) {
> + log_error_errno(errno, "Failed to set TZ environment variable: %m");
> + exit(EXIT_FAILURE);
No! Please never use exit() as a replacement for proper error
handling. In fact, exit() is never OK in our sources really. I have
added a section to CODING_STYLE now to explain this.
> + }
> + tzset();
> +
> if (i->time != 0) {
> sec = (time_t) (i->time / USEC_PER_SEC);
> have_time = true;
> - } else if (arg_transport == BUS_TRANSPORT_LOCAL) {
> + } else if (IN_SET(arg_transport, BUS_TRANSPORT_REMOTE,
> BUS_TRANSPORT_MACHINE)) {
THis makes no sense, the check is reversed, no? Why change this at
all?
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list