diff --git a/src/Makefile.am b/src/Makefile.am index 68e804e1..e8a082f2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -62,8 +62,8 @@ initctl_SOURCES = initctl.c initctl.h cgutil.c cgutil.h \ client.c client.h cond.c cond.h reboot.c \ serv.c serv.h svc.h util.c util.h initctl_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99 -initctl_CFLAGS += $(lite_CFLAGS) -initctl_LDADD = $(lite_LIBS) +initctl_CFLAGS += $(lite_CFLAGS) $(uev_CFLAGS) +initctl_LDADD = $(lite_LIBS) $(uev_LIBS) INIT_LNKS = init telinit REBOOT_LNKS = reboot shutdown halt poweroff suspend diff --git a/src/cgutil.c b/src/cgutil.c index 484aec5d..b71bdbf1 100644 --- a/src/cgutil.c +++ b/src/cgutil.c @@ -459,13 +459,20 @@ int show_cgroup(char *arg) } return cgroup_tree(arg, NULL, 0); +static void cgtop(uev_t *w, void *arg, int events) +{ + fputs("\e[2J\e[1;1H", stdout); + if (heading) + print_header(" VmSIZE RSS VmLIB %%MEM %%CPU GROUP"); + cgroup_tree(arg, NULL, 1); } int show_cgtop(char *arg) { struct sysinfo si = { 0 }; char path[512]; - int laps = 0; + uev_ctx_t ctx; + uev_t timer; if (!arg) arg = FINIT_CGPATH; @@ -480,18 +487,10 @@ int show_cgtop(char *arg) sysinfo(&si); total_ram = si.totalram * si.mem_unit; - while (1) { - fputs("\e[2J\e[1;1H", stdout); - if (heading) - print_header(" VmSIZE RSS VmLIB %%MEM %%CPU GROUP"); - cgroup_tree(arg, NULL, 1); + uev_init(&ctx); + uev_timer_init(&ctx, &timer, cgtop, arg, 1, ionce ? 0 : 1000); - if (ionce && laps++) - break; - sleep(1); - } - - return 0; + return uev_run(&ctx, 0); } /**