summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorJan Synacek <jsynacek@redhat.com>2014-10-03 09:51:33 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-03 08:38:01 -0400
commita62e83b48cda6a709a796a361abaf6b129650b3c (patch)
tree613269e0802988dddba1d8dabf0e27fd995473b3 /src/shared
parent1c92ff85b786c423f4436ec26007e79369c9ac05 (diff)
journalctl: make --utc work everywhere
The --utc option was introduced by commit 9fd290443f5f99fca0dcd4216b1de70f7d3b8db1. Howerver, the implementation was incomplete.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/logs-show.c2
-rw-r--r--src/shared/time-util.c19
-rw-r--r--src/shared/time-util.h3
3 files changed, 18 insertions, 6 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index d5d9d090b5..e30e6865ac 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -447,7 +447,7 @@ static int output_verbose(
}
fprintf(f, "%s [%s]\n",
- format_timestamp_us(ts, sizeof(ts), realtime),
+ format_timestamp_us(ts, sizeof(ts), realtime, flags & OUTPUT_UTC),
cursor);
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index 066ef973ac..09f4a21354 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -152,7 +152,7 @@ struct timeval *timeval_store(struct timeval *tv, usec_t u) {
return tv;
}
-char *format_timestamp(char *buf, size_t l, usec_t t) {
+char *format_timestamp_internal(char *buf, size_t l, usec_t t, bool utc) {
struct tm tm;
time_t sec;
@@ -164,13 +164,21 @@ char *format_timestamp(char *buf, size_t l, usec_t t) {
sec = (time_t) (t / USEC_PER_SEC);
- if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) <= 0)
+ if (utc)
+ gmtime_r(&sec, &tm);
+ else
+ localtime_r(&sec, &tm);
+ if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S %Z", &tm) <= 0)
return NULL;
return buf;
}
-char *format_timestamp_us(char *buf, size_t l, usec_t t) {
+char *format_timestamp(char *buf, size_t l, usec_t t) {
+ return format_timestamp_internal(buf, l, t, false);
+}
+
+char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc) {
struct tm tm;
time_t sec;
@@ -181,7 +189,10 @@ char *format_timestamp_us(char *buf, size_t l, usec_t t) {
return NULL;
sec = (time_t) (t / USEC_PER_SEC);
- localtime_r(&sec, &tm);
+ if (utc)
+ gmtime_r(&sec, &tm);
+ else
+ localtime_r(&sec, &tm);
if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S", &tm) <= 0)
return NULL;
diff --git a/src/shared/time-util.h b/src/shared/time-util.h
index 8ba1cfee8e..16cc593cf5 100644
--- a/src/shared/time-util.h
+++ b/src/shared/time-util.h
@@ -84,8 +84,9 @@ struct timespec *timespec_store(struct timespec *ts, usec_t u);
usec_t timeval_load(const struct timeval *tv) _pure_;
struct timeval *timeval_store(struct timeval *tv, usec_t u);
+char *format_timestamp_internal(char *buf, size_t l, usec_t t, bool utc);
char *format_timestamp(char *buf, size_t l, usec_t t);
-char *format_timestamp_us(char *buf, size_t l, usec_t t);
+char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc);
char *format_timestamp_relative(char *buf, size_t l, usec_t t);
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);