diff options
author | Joshua Colp <jcolp@digium.com> | 2016-03-08 11:29:45 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2016-03-08 11:29:45 -0600 |
commit | 5cf2226e0123f7cfa40345098223f2fa1303454b (patch) | |
tree | 6a0acbbd9c7f696e36a69fe4d791823d0eb866e8 /main | |
parent | 760444a1f571b038fc0402a0d3588a477304d188 (diff) | |
parent | 0ec9fe54219f8ad8a1e2c6f0a17843dcf08b7451 (diff) |
Merge "main/cli.c: Refactor function to print seconds formatted"
Diffstat (limited to 'main')
-rw-r--r-- | main/cli.c | 21 |
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); +} |