summaryrefslogtreecommitdiff
path: root/main/cli.c
diff options
context:
space:
mode:
authorRodrigo Ramírez Norambuena <a@rodrigoramirez.com>2016-02-18 01:58:01 -0300
committerRodrigo Ramírez Norambuena <a@rodrigoramirez.com>2016-03-07 03:42:18 -0300
commit0ec9fe54219f8ad8a1e2c6f0a17843dcf08b7451 (patch)
treec2607814027ff8a7c5c9c88b49542948003ec819 /main/cli.c
parent62282bb8ce15e3e70b3e2fd79834c02911b5f8ff (diff)
main/cli.c: Refactor function to print seconds formatted
Refactor and created function ast_cli_print_timestr_fromseconds to print seconds formatted: year(s) week(s) day(s) hour(s) second(s) This function now is used in addons/cdr_mysql.c,cdr_pgsql.c, main/cli.c, res_config_ldap.c, res_config_pgsql.c. Change-Id: Ibeb8634102cd11d3f8623398b279cb731bcde36c
Diffstat (limited to 'main/cli.c')
-rw-r--r--main/cli.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/main/cli.c b/main/cli.c
index 917305594..0ac5d612a 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -807,7 +807,7 @@ static void print_uptimestr(int fd, struct timeval timeval, const char *prefix,
return;
if (printsec) { /* plain seconds output */
- ast_cli(fd, "%s: %lu\n", prefix, (u_long)timeval.tv_sec);
+ ast_cli(fd, "%s%lu\n", prefix, (u_long)timeval.tv_sec);
return;
}
out = ast_str_alloca(256);
@@ -841,7 +841,7 @@ static void print_uptimestr(int fd, struct timeval timeval, const char *prefix,
/* if there is nothing, print 0 seconds */
ast_str_append(&out, 0, "%d second%s", x, ESS(x));
}
- ast_cli(fd, "%s: %s\n", prefix, ast_str_buffer(out));
+ ast_cli(fd, "%s%s\n", prefix, ast_str_buffer(out));
}
static struct ast_cli_entry *cli_next(struct ast_cli_entry *e)
@@ -877,10 +877,12 @@ static char * handle_showuptime(struct ast_cli_entry *e, int cmd, struct ast_cli
printsec = 0;
else
return CLI_SHOWUSAGE;
- if (ast_startuptime.tv_sec)
- print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime", printsec);
- if (ast_lastreloadtime.tv_sec)
- print_uptimestr(a->fd, ast_tvsub(curtime, ast_lastreloadtime), "Last reload", printsec);
+ if (ast_startuptime.tv_sec) {
+ print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime: ", printsec);
+ }
+ if (ast_lastreloadtime.tv_sec) {
+ print_uptimestr(a->fd, ast_tvsub(curtime, ast_lastreloadtime), "Last reload: ", printsec);
+ }
return CLI_SUCCESS;
}
@@ -972,7 +974,7 @@ static char *handle_showcalls(struct ast_cli_entry *e, int cmd, struct ast_cli_a
ast_cli(a->fd, "%d call%s processed\n", ast_processed_calls(), ESS(ast_processed_calls()));
if (ast_startuptime.tv_sec && showuptime) {
- print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime", printsec);
+ print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime: ", printsec);
}
return RESULT_SUCCESS;
@@ -2744,3 +2746,8 @@ int ast_cli_command_multiple_full(int uid, int gid, int fd, size_t size, const c
}
return count;
}
+
+void ast_cli_print_timestr_fromseconds(int fd, int seconds, const char *prefix)
+{
+ print_uptimestr(fd, ast_tv(seconds, 0), prefix, 0);
+}