|
Zbigniew Jędrzejewski-Szmek |
f1004d |
From 5ab99e076c72a44f2e174e48abd9945cd0180d76 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
From: Lennart Poettering <lennart@poettering.net>
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
Date: Wed, 8 Oct 2014 22:37:45 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
Subject: [PATCH] time: functions named "internal" really shouldn't be exported
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
Also, let's try to make function names descriptive, instead of using
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
bools for flags.
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
---
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
src/journal/journalctl.c | 22 +++++++++++++++-------
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
src/shared/logs-show.c | 4 +++-
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
src/shared/time-util.c | 16 ++++++++++++++--
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
src/shared/time-util.h | 5 +++--
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
4 files changed, 35 insertions(+), 12 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
index 816934ee6b..feb53bd203 100644
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
--- a/src/journal/journalctl.c
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+++ b/src/journal/journalctl.c
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
@@ -127,6 +127,14 @@ static void pager_open_if_enabled(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
pager_open(arg_pager_end);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+static char *format_timestamp_maybe_utc(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ if (arg_utc)
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ return format_timestamp_utc(buf, l, t);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ return format_timestamp(buf, l, t);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
sd_id128_t id = SD_ID128_NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
int off = 0, r;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
@@ -890,8 +898,8 @@ static int list_boots(sd_journal *j) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
printf("% *i " SD_ID128_FORMAT_STR " %s—%s\n",
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
w, i - count + 1,
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
SD_ID128_FORMAT_VAL(id->id),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
- format_timestamp_internal(a, sizeof(a), id->first, arg_utc),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
- format_timestamp_internal(b, sizeof(b), id->last, arg_utc));
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ format_timestamp_maybe_utc(a, sizeof(a), id->first),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ format_timestamp_maybe_utc(b, sizeof(b), id->last));
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
@@ -1502,8 +1510,8 @@ static int verify(sd_journal *j) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
if (arg_verify_key && JOURNAL_HEADER_SEALED(f->header)) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
if (validated > 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
log_info("=> Validated from %s to %s, final %s entries not sealed.",
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
- format_timestamp_internal(a, sizeof(a), first, arg_utc),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
- format_timestamp_internal(b, sizeof(b), validated, arg_utc),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ format_timestamp_maybe_utc(a, sizeof(a), first),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ format_timestamp_maybe_utc(b, sizeof(b), validated),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
format_timespan(c, sizeof(c), last > validated ? last - validated : 0, 0));
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
} else if (last > 0)
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
log_info("=> No sealing yet, %s of entries not sealed.",
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
@@ -1898,11 +1906,11 @@ int main(int argc, char *argv[]) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
if (r > 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
if (arg_follow)
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
printf("-- Logs begin at %s. --\n",
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
- format_timestamp_internal(start_buf, sizeof(start_buf), start, arg_utc));
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ format_timestamp_maybe_utc(start_buf, sizeof(start_buf), start));
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
else
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
printf("-- Logs begin at %s, end at %s. --\n",
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
- format_timestamp_internal(start_buf, sizeof(start_buf), start, arg_utc),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
- format_timestamp_internal(end_buf, sizeof(end_buf), end, arg_utc));
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ format_timestamp_maybe_utc(start_buf, sizeof(start_buf), start),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ format_timestamp_maybe_utc(end_buf, sizeof(end_buf), end));
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
index e30e6865ac..3d742491c9 100644
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
--- a/src/shared/logs-show.c
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+++ b/src/shared/logs-show.c
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
@@ -447,7 +447,9 @@ static int output_verbose(
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
fprintf(f, "%s [%s]\n",
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
- format_timestamp_us(ts, sizeof(ts), realtime, flags & OUTPUT_UTC),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ flags & OUTPUT_UTC ?
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ format_timestamp_us_utc(ts, sizeof(ts), realtime) :
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ format_timestamp_us(ts, sizeof(ts), realtime),
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
cursor);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
index 09f4a21354..433c262dfa 100644
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
--- a/src/shared/time-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+++ b/src/shared/time-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
@@ -152,7 +152,7 @@ struct timeval *timeval_store(struct timeval *tv, usec_t u) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
return tv;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
-char *format_timestamp_internal(char *buf, size_t l, usec_t t, bool utc) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+static char *format_timestamp_internal(char *buf, size_t l, usec_t t, bool utc) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
struct tm tm;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
time_t sec;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
@@ -178,7 +178,11 @@ char *format_timestamp(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
return format_timestamp_internal(buf, l, t, false);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
-char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+char *format_timestamp_utc(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ return format_timestamp_internal(buf, l, t, true);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+static char *format_timestamp_internal_us(char *buf, size_t l, usec_t t, bool utc) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
struct tm tm;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
time_t sec;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
@@ -203,6 +207,14 @@ char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
return buf;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+char *format_timestamp_us(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ return format_timestamp_internal_us(buf, l, t, false);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+char *format_timestamp_us_utc(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+ return format_timestamp_internal_us(buf, l, t, true);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
const char *s;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
usec_t n, d;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
diff --git a/src/shared/time-util.h b/src/shared/time-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
index 16cc593cf5..05369d295b 100644
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
--- a/src/shared/time-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+++ b/src/shared/time-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
@@ -84,9 +84,10 @@ struct timespec *timespec_store(struct timespec *ts, usec_t u);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
usec_t timeval_load(const struct timeval *tv) _pure_;
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
struct timeval *timeval_store(struct timeval *tv, usec_t u);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
-char *format_timestamp_internal(char *buf, size_t l, usec_t t, bool utc);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
char *format_timestamp(char *buf, size_t l, usec_t t);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
-char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+char *format_timestamp_utc(char *buf, size_t l, usec_t t);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+char *format_timestamp_us(char *buf, size_t l, usec_t t);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
+char *format_timestamp_us_utc(char *buf, size_t l, usec_t t);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
char *format_timestamp_relative(char *buf, size_t l, usec_t t);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);
|
|
Zbigniew Jędrzejewski-Szmek |
f1004d |
|