diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-04-23 13:20:35 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-04-23 13:20:35 +0100 |
commit | 58fa012f4bd6ee93ded8f10f24961ce6a1e0559e (patch) | |
tree | 4700039cf17a9f56828e3ab5d0b752c9912a5735 /src/client | |
parent | e73e539a28af82a10c073b01a5a80ac9ea06f0b0 (diff) | |
download | rspamd-58fa012f4bd6ee93ded8f10f24961ce6a1e0559e.tar.gz rspamd-58fa012f4bd6ee93ded8f10f24961ce6a1e0559e.zip |
Make human readable `uptime` output.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/rspamc.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 68b5cacab..65de5de48 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -81,6 +81,7 @@ static GOptionEntry entries[] = }; static void rspamc_symbols_output (ucl_object_t *obj); +static void rspamc_uptime_output (ucl_object_t *obj); enum rspamc_command_type { RSPAMC_COMMAND_UNKNOWN = 0, @@ -195,7 +196,7 @@ struct rspamc_command { .is_controller = TRUE, .is_privileged = FALSE, .need_input = FALSE, - .command_output_func = NULL + .command_output_func = rspamc_uptime_output }, { .cmd = RSPAMC_COMMAND_ADD_SYMBOL, @@ -500,6 +501,47 @@ rspamc_symbols_output (ucl_object_t *obj) } static void +rspamc_uptime_output (ucl_object_t *obj) +{ + const ucl_object_t *elt; + int64_t seconds, days, hours, minutes; + + elt = ucl_object_find_key (obj, "version"); + if (elt != NULL) { + rspamd_fprintf (stdout, "Rspamd version: %s\n", ucl_object_tostring (elt)); + } + + elt = ucl_object_find_key (obj, "uptime"); + if (elt != NULL) { + rspamd_printf ("Uptime: "); + seconds = ucl_object_toint (elt); + if (seconds >= 2 * 3600) { + days = seconds / 86400; + hours = seconds / 3600 - days * 24; + minutes = seconds / 60 - hours * 60 - days * 1440; + rspamd_printf ("%L day%s %L hour%s %L minute%s\n", days, + days > 1 ? "s" : " ", hours, hours > 1 ? "s" : " ", + minutes, minutes > 1 ? "s" : " "); + } + /* If uptime is less than 1 minute print only seconds */ + else if (seconds / 60 == 0) { + rspamd_printf ("%L second%s\n", (gint)seconds, + (gint)seconds > 1 ? "s" : " "); + } + /* Else print the minutes and seconds. */ + else { + hours = seconds / 3600; + minutes = seconds / 60 - hours * 60; + seconds -= hours * 3600 + minutes * 60; + rspamd_printf ("%L hour%s %L minute%s %L second%s\n", hours, + hours > 1 ? "s" : " ", minutes, + minutes > 1 ? "s" : " ", + seconds, seconds > 1 ? "s" : " "); + } + } +} + +static void rspamc_output_headers (struct rspamd_http_message *msg) { struct rspamd_http_header *h; |