|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From a62e83b48cda6a709a796a361abaf6b129650b3c Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: Jan Synacek <jsynacek@redhat.com>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Fri, 3 Oct 2014 09:51:33 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] journalctl: make --utc work everywhere
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
The --utc option was introduced by commit
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
9fd290443f5f99fca0dcd4216b1de70f7d3b8db1.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Howerver, the implementation was incomplete.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/journal/journalctl.c | 14 +++++++-------
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/shared/logs-show.c | 2 +-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/shared/time-util.c | 19 +++++++++++++++----
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/shared/time-util.h | 3 ++-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
4 files changed, 25 insertions(+), 13 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 395f85c9ae..816934ee6b 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/journal/journalctl.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/journal/journalctl.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -890,8 +890,8 @@ static int list_boots(sd_journal *j) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
printf("% *i " SD_ID128_FORMAT_STR " %s—%s\n",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
w, i - count + 1,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
SD_ID128_FORMAT_VAL(id->id),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- format_timestamp(a, sizeof(a), id->first),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- format_timestamp(b, sizeof(b), id->last));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ format_timestamp_internal(a, sizeof(a), id->first, arg_utc),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ format_timestamp_internal(b, sizeof(b), id->last, arg_utc));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -1502,8 +1502,8 @@ static int verify(sd_journal *j) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (arg_verify_key && JOURNAL_HEADER_SEALED(f->header)) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (validated > 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_info("=> Validated from %s to %s, final %s entries not sealed.",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- format_timestamp(a, sizeof(a), first),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- format_timestamp(b, sizeof(b), validated),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ format_timestamp_internal(a, sizeof(a), first, arg_utc),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ format_timestamp_internal(b, sizeof(b), validated, arg_utc),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
format_timespan(c, sizeof(c), last > validated ? last - validated : 0, 0));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
} else if (last > 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_info("=> No sealing yet, %s of entries not sealed.",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -1898,11 +1898,11 @@ int main(int argc, char *argv[]) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r > 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (arg_follow)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
printf("-- Logs begin at %s. --\n",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- format_timestamp(start_buf, sizeof(start_buf), start));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ format_timestamp_internal(start_buf, sizeof(start_buf), start, arg_utc));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
else
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
printf("-- Logs begin at %s, end at %s. --\n",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- format_timestamp(start_buf, sizeof(start_buf), start),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- format_timestamp(end_buf, sizeof(end_buf), end));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ format_timestamp_internal(start_buf, sizeof(start_buf), start, arg_utc),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ format_timestamp_internal(end_buf, sizeof(end_buf), end, arg_utc));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index d5d9d090b5..e30e6865ac 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/shared/logs-show.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/shared/logs-show.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -447,7 +447,7 @@ static int output_verbose(
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
fprintf(f, "%s [%s]\n",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- format_timestamp_us(ts, sizeof(ts), realtime),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ format_timestamp_us(ts, sizeof(ts), realtime, flags & OUTPUT_UTC),
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
cursor);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 066ef973ac..09f4a21354 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/shared/time-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/shared/time-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -152,7 +152,7 @@ struct timeval *timeval_store(struct timeval *tv, usec_t u) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return tv;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-char *format_timestamp(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+char *format_timestamp_internal(char *buf, size_t l, usec_t t, bool utc) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
struct tm tm;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
time_t sec;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -164,13 +164,21 @@ char *format_timestamp(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
sec = (time_t) (t / USEC_PER_SEC);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) <= 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (utc)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ gmtime_r(&sec, &tm;;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ else
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ localtime_r(&sec, &tm;;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S %Z", &tm) <= 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return buf;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-char *format_timestamp_us(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+char *format_timestamp(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return format_timestamp_internal(buf, l, t, false);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
struct tm tm;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
time_t sec;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -181,7 +189,10 @@ char *format_timestamp_us(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
sec = (time_t) (t / USEC_PER_SEC);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- localtime_r(&sec, &tm;;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (utc)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ gmtime_r(&sec, &tm;;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ else
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ localtime_r(&sec, &tm;;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S", &tm) <= 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/shared/time-util.h b/src/shared/time-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 8ba1cfee8e..16cc593cf5 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/shared/time-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/shared/time-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -84,8 +84,9 @@ struct timespec *timespec_store(struct timespec *ts, usec_t u);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
usec_t timeval_load(const struct timeval *tv) _pure_;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
struct timeval *timeval_store(struct timeval *tv, usec_t u);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+char *format_timestamp_internal(char *buf, size_t l, usec_t t, bool utc);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
char *format_timestamp(char *buf, size_t l, usec_t t);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-char *format_timestamp_us(char *buf, size_t l, usec_t t);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
char *format_timestamp_relative(char *buf, size_t l, usec_t t);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|