[systemd-devel] [PATCH v2] journalctl: add --utc option

2014-10-02 Thread Jan Synacek
Lennart Poettering lenn...@poettering.net writes:
 On Thu, 02.10.14 09:36, Jan Synacek (jsyna...@redhat.com) wrote:
 This should not be part of OutputMode, but of OutputFlags!

Fixed.

 Otherwise looks good. Do you have commit access? If so, please push after 
 fixing the issue above.

I don't have commit access.

Thanks,
Jan

-- 
From 0fe80097271bd4a115c4365dbb1448f87bc5c432 Mon Sep 17 00:00:00 2001
From: Jan Synacek jsyna...@redhat.com
Date: Thu, 2 Oct 2014 08:45:49 +0200
Subject: [PATCH] journalctl: add --utc option

Introduce option to display time in UTC.
---
Changes in v2:
 - move OUTPUT_UTC from OutputMode to OutputFlags

 man/journalctl.xml   |  7 +++
 src/journal/journalctl.c | 11 ++-
 src/shared/logs-show.c   |  8 +---
 src/shared/output-mode.h |  1 +
 4 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/man/journalctl.xml b/man/journalctl.xml
index acd75a6..7fb6afc 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -380,6 +380,13 @@
 /varlistentry
 
 varlistentry
+termoption--utc/option/term
+
+listitemparaExpress time in Coordinated 
Universal
+Time (UTC)./para/listitem
+/varlistentry
+
+varlistentry
 termoption-x/option/term
 termoption--catalog/option/term
 
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 89a922c..395f85c 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -63,6 +63,7 @@
 #define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
 
 static OutputMode arg_output = OUTPUT_SHORT;
+static bool arg_utc = false;
 static bool arg_pager_end = false;
 static bool arg_follow = false;
 static bool arg_full = true;
@@ -191,6 +192,7 @@ static void help(void) {
  -o --output=STRING   Change journal output mode (short, 
short-iso,\n
   short-precise, 
short-monotonic, verbose,\n
   export, json, json-pretty, 
json-sse, cat)\n
+--utc Express time in Coordinated 
Universal Time (UTC)\n
  -x --catalog Add message explanations where 
available\n
 --no-full Ellipsize fields\n
  -a --all Show all fields, including long and 
unprintable\n
@@ -250,6 +252,7 @@ static int parse_argv(int argc, char *argv[]) {
 ARG_DUMP_CATALOG,
 ARG_UPDATE_CATALOG,
 ARG_FORCE,
+ARG_UTC,
 };
 
 static const struct option options[] = {
@@ -299,6 +302,7 @@ static int parse_argv(int argc, char *argv[]) {
 { update-catalog, no_argument,   NULL, 
ARG_UPDATE_CATALOG },
 { reverse,no_argument,   NULL, 'r'   
 },
 { machine,required_argument, NULL, 'M'   
 },
+{ utc,no_argument,   NULL, ARG_UTC   
 },
 {}
 };
 
@@ -639,6 +643,10 @@ static int parse_argv(int argc, char *argv[]) {
 arg_reverse = true;
 break;
 
+case ARG_UTC:
+arg_utc = true;
+break;
+
 case '?':
 return -EINVAL;
 
@@ -1958,7 +1966,8 @@ int main(int argc, char *argv[]) {
 arg_all * OUTPUT_SHOW_ALL |
 arg_full * OUTPUT_FULL_WIDTH |
 on_tty() * OUTPUT_COLOR |
-arg_catalog * OUTPUT_CATALOG;
+arg_catalog * OUTPUT_CATALOG |
+arg_utc * OUTPUT_UTC;
 
 r = output_journal(stdout, j, arg_output, 0, flags, 
ellipsized);
 need_seek = true;
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 5a7bbaf..d5d9d09 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -311,8 +311,10 @@ static int output_short(
 uint64_t x;
 time_t t;
 struct tm tm;
+struct tm *(*gettime_r)(const time_t *, struct tm *);
 
 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, 

Re: [systemd-devel] [PATCH v2] journalctl: add --utc option

2014-10-02 Thread Lennart Poettering
On Thu, 02.10.14 14:39, Jan Synacek (jsyna...@redhat.com) wrote:

 Introduce option to display time in UTC.

Thanks!

Applied!

 ---
 Changes in v2:
  - move OUTPUT_UTC from OutputMode to OutputFlags
 
  man/journalctl.xml   |  7 +++
  src/journal/journalctl.c | 11 ++-
  src/shared/logs-show.c   |  8 +---
  src/shared/output-mode.h |  1 +
  4 files changed, 23 insertions(+), 4 deletions(-)
 
 diff --git a/man/journalctl.xml b/man/journalctl.xml
 index acd75a6..7fb6afc 100644
 --- a/man/journalctl.xml
 +++ b/man/journalctl.xml
 @@ -380,6 +380,13 @@
  /varlistentry
  
  varlistentry
 +termoption--utc/option/term
 +
 +listitemparaExpress time in Coordinated 
 Universal
 +Time (UTC)./para/listitem
 +/varlistentry
 +
 +varlistentry
  termoption-x/option/term
  termoption--catalog/option/term
  
 diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
 index 89a922c..395f85c 100644
 --- a/src/journal/journalctl.c
 +++ b/src/journal/journalctl.c
 @@ -63,6 +63,7 @@
  #define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
  
  static OutputMode arg_output = OUTPUT_SHORT;
 +static bool arg_utc = false;
  static bool arg_pager_end = false;
  static bool arg_follow = false;
  static bool arg_full = true;
 @@ -191,6 +192,7 @@ static void help(void) {
   -o --output=STRING   Change journal output mode 
 (short, short-iso,\n
short-precise, 
 short-monotonic, verbose,\n
export, json, 
 json-pretty, json-sse, cat)\n
 +--utc Express time in Coordinated 
 Universal Time (UTC)\n
   -x --catalog Add message explanations where 
 available\n
  --no-full Ellipsize fields\n
   -a --all Show all fields, including long 
 and unprintable\n
 @@ -250,6 +252,7 @@ static int parse_argv(int argc, char *argv[]) {
  ARG_DUMP_CATALOG,
  ARG_UPDATE_CATALOG,
  ARG_FORCE,
 +ARG_UTC,
  };
  
  static const struct option options[] = {
 @@ -299,6 +302,7 @@ static int parse_argv(int argc, char *argv[]) {
  { update-catalog, no_argument,   NULL, 
 ARG_UPDATE_CATALOG },
  { reverse,no_argument,   NULL, 'r' 
},
  { machine,required_argument, NULL, 'M' 
},
 +{ utc,no_argument,   NULL, ARG_UTC 
},
  {}
  };
  
 @@ -639,6 +643,10 @@ static int parse_argv(int argc, char *argv[]) {
  arg_reverse = true;
  break;
  
 +case ARG_UTC:
 +arg_utc = true;
 +break;
 +
  case '?':
  return -EINVAL;
  
 @@ -1958,7 +1966,8 @@ int main(int argc, char *argv[]) {
  arg_all * OUTPUT_SHOW_ALL |
  arg_full * OUTPUT_FULL_WIDTH |
  on_tty() * OUTPUT_COLOR |
 -arg_catalog * OUTPUT_CATALOG;
 +arg_catalog * OUTPUT_CATALOG |
 +arg_utc * OUTPUT_UTC;
  
  r = output_journal(stdout, j, arg_output, 0, flags, 
 ellipsized);
  need_seek = true;
 diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
 index 5a7bbaf..d5d9d09 100644
 --- a/src/shared/logs-show.c
 +++ b/src/shared/logs-show.c
 @@ -311,8 +311,10 @@ static int output_short(
  uint64_t x;
  time_t t;
  struct tm tm;
 +struct tm *(*gettime_r)(const time_t *, struct tm *);
  
  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) {
   

Re: [systemd-devel] [PATCH v2] journalctl: add --utc option

2014-10-02 Thread Jan Synacek
Lennart Poettering lenn...@poettering.net writes:
 On Thu, 02.10.14 14:39, Jan Synacek (jsyna...@redhat.com) wrote:

 Introduce option to display time in UTC.

 Thanks!

 Applied!

Thanks! I just realized that the patch was incomplete. There are at
least two different places that need to be patched - format_timestamp()
and format_timestamp_us() in src/shared/time-util.c. I'm not sure about
the rest (grepping localtime_r reveals some more uses). I would extend
the API of those calls by one boolean saying if they should use UTC or
not, however that would break API. Would that be OK? Or do you suggest
anything else?

Cheers,
-- 
Jan Synacek
Software Engineer, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH v2] journalctl: add --utc option

2014-10-02 Thread Lennart Poettering
On Thu, 02.10.14 15:19, Jan Synacek (jsyna...@redhat.com) wrote:

 Lennart Poettering lenn...@poettering.net writes:
  On Thu, 02.10.14 14:39, Jan Synacek (jsyna...@redhat.com) wrote:
 
  Introduce option to display time in UTC.
 
  Thanks!
 
  Applied!
 
 Thanks! I just realized that the patch was incomplete. There are at
 least two different places that need to be patched - format_timestamp()
 and format_timestamp_us() in src/shared/time-util.c. I'm not sure about
 the rest (grepping localtime_r reveals some more uses). I would extend
 the API of those calls by one boolean saying if they should use UTC or
 not, however that would break API. Would that be OK? Or do you suggest
 anything else?

Hmm, I'd probably rename format_timestamp() to
format_timestamp_internal(), add the bool to it, and then make
format_timestamp() just invoke that with the bool set to false, and
then add format_timestamp_utc() which calls it with true. That way you
don't have to patch that many invocations, and the invocations stay
more readable.

(breaking internal API is fine btw, we only need to be careful with
exported API.)

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel