From 780fe62ecab08850cefd136b95f38c15cb31c0ec Mon Sep 17 00:00:00 2001 From: Charles Duffy Date: Fri, 22 May 2015 22:18:15 -0500 Subject: cgtop: allow user to force looping behavior even in non-TTY mode --- man/systemd-cgtop.xml | 14 ++++++++------ src/cgtop/cgtop.c | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/man/systemd-cgtop.xml b/man/systemd-cgtop.xml index b3298b64f3..d14564480d 100644 --- a/man/systemd-cgtop.xml +++ b/man/systemd-cgtop.xml @@ -65,10 +65,12 @@ groups of the local Linux control group hierarchy, ordered by their CPU, memory, or disk I/O load. The display is refreshed in regular intervals (by default every 1s), similar in style to - top1. - If systemd-cgtop is not connected to a tty, - only one iteration is performed and no columns headers are - printed. This mode is suitable for scripting. + top1. + + If systemd-cgtop is not connected to a tty, no + column headers are printed and the default is to only run one iteration. + The --iterations argument, if given, is still honored. + This mode is suitable for scripting. Resource usage is only accounted for control groups in the relevant hierarchy, i.e. CPU usage is only accounted for control @@ -155,8 +157,8 @@ - Perform only this many iterations. - + Perform only this many iterations. A value of 0 + indicates that the program should run indefinitely. diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 8c58cd2c04..d04d6f225c 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -60,7 +60,7 @@ typedef struct Group { } Group; static unsigned arg_depth = 3; -static unsigned arg_iterations = 0; +static unsigned arg_iterations = (unsigned)-1; static bool arg_batch = false; static bool arg_raw = false; static usec_t arg_delay = 1*USEC_PER_SEC; @@ -715,8 +715,8 @@ int main(int argc, char *argv[]) { signal(SIGWINCH, columns_lines_cache_reset); - if (!on_tty()) - arg_iterations = 1; + if (arg_iterations == (unsigned)-1) + arg_iterations = on_tty() ? 0 : 1; while (!quit) { Hashmap *c; -- cgit v1.2.3-54-g00ecf