Commit 8f2d43a0 authored by Lennart Poettering's avatar Lennart Poettering
Browse files

cgtop: add new cgtop tool

parent 1733ca54
/systemd-cgtop
/systemd-coredump
/systemd-cat
/systemd-rc-local-generator
......
......@@ -169,6 +169,7 @@ rootbin_PROGRAMS = \
bin_PROGRAMS = \
systemd-cgls \
systemd-cgtop \
systemd-stdio-bridge \
systemd-nspawn
......@@ -1008,6 +1009,13 @@ systemd_cgls_SOURCES = \
systemd_cgls_LDADD = \
libsystemd-basic.la
systemd_cgtop_SOURCES = \
src/cgtop.c \
src/cgroup-util.c
systemd_cgtop_LDADD = \
libsystemd-basic.la
systemd_nspawn_SOURCES = \
src/nspawn.c \
src/cgroup-util.c \
......
This diff is collapsed.
......@@ -282,7 +282,7 @@ int main(int argc, char *argv[]) {
if (!arg_follow)
break;
r = fd_wait_for_event(fd, POLLIN);
r = fd_wait_for_event(fd, POLLIN, (usec_t) -1);
if (r < 0) {
log_error("Couldn't wait for event: %s", strerror(-r));
goto finish;
......
......@@ -633,7 +633,7 @@ int show_journal_by_unit(
if (!follow)
break;
r = fd_wait_for_event(fd, POLLIN);
r = fd_wait_for_event(fd, POLLIN, (usec_t) -1);
if (r < 0)
goto finish;
......
......@@ -2434,7 +2434,7 @@ fail:
return r;
}
int read_one_char(FILE *f, char *ret, bool *need_nl) {
int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
struct termios old_termios, new_termios;
char c;
char line[LINE_MAX];
......@@ -2452,6 +2452,13 @@ int read_one_char(FILE *f, char *ret, bool *need_nl) {
if (tcsetattr(fileno(f), TCSADRAIN, &new_termios) >= 0) {
size_t k;
if (t != (usec_t) -1) {
if (fd_wait_for_event(fileno(f), POLLIN, t) <= 0) {
tcsetattr(fileno(f), TCSADRAIN, &old_termios);
return -ETIMEDOUT;
}
}
k = fread(&c, 1, 1, f);
tcsetattr(fileno(f), TCSADRAIN, &old_termios);
......@@ -2467,7 +2474,11 @@ int read_one_char(FILE *f, char *ret, bool *need_nl) {
}
}
if (!(fgets(line, sizeof(line), f)))
if (t != (usec_t) -1)
if (fd_wait_for_event(fileno(f), POLLIN, t) <= 0)
return -ETIMEDOUT;
if (!fgets(line, sizeof(line), f))
return -EIO;
truncate_nl(line);
......@@ -2509,7 +2520,8 @@ int ask(char *ret, const char *replies, const char *text, ...) {
fflush(stdout);
if ((r = read_one_char(stdin, &c, &need_nl)) < 0) {
r = read_one_char(stdin, &c, (usec_t) -1, &need_nl);
if (r < 0) {
if (r == -EBADMSG) {
puts("Bad input, please try again.");
......@@ -4079,6 +4091,39 @@ unsigned columns(void) {
return parsed_columns;
}
int fd_lines(int fd) {
struct winsize ws;
zero(ws);
if (ioctl(fd, TIOCGWINSZ, &ws) < 0)
return -errno;
if (ws.ws_row <= 0)
return -EIO;
return ws.ws_row;
}
unsigned lines(void) {
static __thread int parsed_lines = 0;
const char *e;
if (_likely_(parsed_lines > 0))
return parsed_lines;
e = getenv("LINES");
if (e)
parsed_lines = atoi(e);
if (parsed_lines <= 0)
parsed_lines = fd_lines(STDOUT_FILENO);
if (parsed_lines <= 0)
parsed_lines = 25;
return parsed_lines;
}
int running_in_chroot(void) {
struct stat a, b;
......@@ -4850,7 +4895,7 @@ int pipe_eof(int fd) {
return pollfd.revents & POLLHUP;
}
int fd_wait_for_event(int fd, int event) {
int fd_wait_for_event(int fd, int event, usec_t t) {
struct pollfd pollfd;
int r;
......@@ -4858,7 +4903,7 @@ int fd_wait_for_event(int fd, int event) {
pollfd.fd = fd;
pollfd.events = event;
r = poll(&pollfd, 1, -1);
r = poll(&pollfd, 1, t == (usec_t) -1 ? -1 : (int) (t / USEC_PER_MSEC));
if (r < 0)
return -errno;
......
......@@ -327,7 +327,7 @@ bool fstype_is_network(const char *fstype);
int chvt(int vt);
int read_one_char(FILE *f, char *ret, bool *need_nl);
int read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
int ask(char *ret, const char *replies, const char *text, ...);
int reset_terminal_fd(int fd);
......@@ -384,6 +384,9 @@ void status_welcome(void);
int fd_columns(int fd);
unsigned columns(void);
int fd_lines(int fd);
unsigned lines(void);
int running_in_chroot(void);
char *ellipsize(const char *s, size_t length, unsigned percent);
......@@ -525,7 +528,7 @@ unsigned long cap_last_cap(void);
char *format_bytes(char *buf, size_t l, off_t t);
int fd_wait_for_event(int fd, int event);
int fd_wait_for_event(int fd, int event, usec_t timeout);
void* memdup(const void *p, size_t l);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment