On Thu, 02.10.14 09:36, Jan Synacek ([email protected]) wrote:
> Introduce option to display time in UTC.
Looks generally OK.
> struct tm tm;
> + struct tm *(*gettime_r)(const time_t *, struct tm *);
This isn't particularly beautiful and easy to grok, but certainly
efficient. So, let's leave it in...
>
> r = -ENOENT;
> + gettime_r = (flags & OUTPUT_UTC) ? gmtime_r : localtime_r;
>
> if (realtime)
> r = safe_atou64(realtime, &x);
> @@ -329,17 +331,17 @@ static int output_short(
>
> switch(mode) {
> case OUTPUT_SHORT_ISO:
> - r = strftime(buf, sizeof(buf),
> "%Y-%m-%dT%H:%M:%S%z", localtime_r(&t, &tm));
> + r = strftime(buf, sizeof(buf),
> "%Y-%m-%dT%H:%M:%S%z", gettime_r(&t, &tm));
> break;
> case OUTPUT_SHORT_PRECISE:
> - r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S",
> localtime_r(&t, &tm));
> + r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S",
> gettime_r(&t, &tm));
> if (r > 0) {
> snprintf(buf + strlen(buf), sizeof(buf) -
> strlen(buf),
> ".%06llu", (unsigned long long) (x
> % USEC_PER_SEC));
> }
> break;
> default:
> - r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S",
> localtime_r(&t, &tm));
> + r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S",
> gettime_r(&t, &tm));
> }
>
> if (r <= 0) {
> diff --git a/src/shared/output-mode.h b/src/shared/output-mode.h
> index ac1bb01..8f78aac 100644
> --- a/src/shared/output-mode.h
> +++ b/src/shared/output-mode.h
> @@ -26,6 +26,7 @@ typedef enum OutputMode {
> OUTPUT_SHORT_ISO,
> OUTPUT_SHORT_PRECISE,
> OUTPUT_SHORT_MONOTONIC,
> + OUTPUT_UTC,
> OUTPUT_VERBOSE,
> OUTPUT_EXPORT,
> OUTPUT_JSON,
This should not be part of OutputMode, but of OutputFlags!
Otherwise looks good. Do you have commit access? If so, please push after
fixing the issue above.
Lennart
--
Lennart Poettering, Red Hat
_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel