[systemd-commits] 3 commits - src/systemctl.c
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Sep 14 13:23:31 PDT 2010
src/systemctl.c | 175 +++++++++++++++++++++++++++++++-------------------------
1 file changed, 98 insertions(+), 77 deletions(-)
New commits:
commit 333302226926abe653f0396db1d76b1f8c4d0fc7
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Sep 7 10:30:52 2010 +0200
systemctl: limit some column widths to widest actually used
old
UNIT LOAD ACTIVE SUB JOB
dev-hugepages.automount loaded active running Huge Page
dev-mqueue.automount loaded active waiting POSIX Mes
proc-sys...misc.automount loaded active waiting Arbitrary
sys-kern...ebug.automount loaded active running Debug Fil
new
UNIT LOAD ACTIVE SUB JOB
dev-hugepages.automount loaded active running Huge Pages File System Automount Poi
dev-mqueue.automount loaded active waiting POSIX Message Queue File System Auto
systemd-shutdownd.socket loaded active listening systemd Delayed Shutdown Socket
diff --git a/src/systemctl.c b/src/systemctl.c
index fe55eac..fa191ab 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -251,20 +251,39 @@ static int compare_unit_info(const void *a, const void *b) {
return strcasecmp(u->id, v->id);
}
+static bool output_show_job(const struct unit_info *u) {
+ const char *dot;
+ return (!arg_type || ((dot = strrchr(u->id, '.')) &&
+ streq(dot+1, arg_type))) &&
+ (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0);
+}
+
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
+ unsigned active_len, sub_len, job_len;
+
+ active_len = strlen("ACTIVE");
+ sub_len = strlen("SUB");
+ job_len = strlen("JOB");
+ for (const struct unit_info *u = unit_infos; u < unit_infos + c; u++) {
+ if (output_show_job(u)) {
+ active_len = MAX(active_len, strlen(u->active_state));
+ sub_len = MAX(sub_len, strlen(u->sub_state));
+ if (u->job_id != 0)
+ job_len = MAX(job_len, strlen(u->job_type));
+ }
+ }
+
if (on_tty()) {
+ printf("%-25s %-6s %-*s %-*s %-*s", "UNIT", "LOAD",
+ active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB");
if (columns() >= 80+12 || arg_full)
- printf("%-25s %-6s %-12s %-18s %-15s %s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB", "DESCRIPTION");
+ printf(" %s\n", "DESCRIPTION");
else
- printf("%-25s %-6s %-12s %-18s %-15s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB");
+ printf("\n");
}
for (const struct unit_info *u = unit_infos; u < unit_infos + c; u++) {
- const char *dot;
-
- if ((!arg_type || ((dot = strrchr(u->id, '.')) &&
- streq(dot+1, arg_type))) &&
- (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0)) {
+ if (output_show_job(u)) {
char *e;
int a = 0, b = 0;
const char *on_loaded, *off_loaded;
@@ -284,10 +303,11 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
e = arg_full ? NULL : ellipsize(u->id, 25, 33);
- printf("%-25s %s%-6s%s %s%-12s %-18s%s%n",
+ printf("%-25s %s%-6s%s %s%-*s %-*s%s%n",
e ? e : u->id,
on_loaded, u->load_state, off_loaded,
- on_active, u->active_state, u->sub_state, off_active,
+ on_active, active_len, u->active_state,
+ sub_len, u->sub_state, off_active,
&a);
free(e);
@@ -296,13 +316,13 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
a -= strlen(on_active) + strlen(off_active);
if (u->job_id != 0)
- printf(" %-15s%n", u->job_type, &b);
+ printf(" %-*s", job_len, u->job_type);
else
- b = 1 + 15;
+ b = 1 + job_len;
if (a + b + 1 < columns()) {
if (u->job_id == 0)
- printf(" ");
+ printf(" %-*s", job_len, "");
if (arg_full)
printf(" %s", u->description);
commit eb68c413aa539e7bda8fda59f423eaad811fe9fc
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Sep 7 10:30:51 2010 +0200
systemctl: split job list writing to a seperate function
diff --git a/src/systemctl.c b/src/systemctl.c
index ff6f86a..fe55eac 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -251,12 +251,88 @@ static int compare_unit_info(const void *a, const void *b) {
return strcasecmp(u->id, v->id);
}
+static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
+ if (on_tty()) {
+ if (columns() >= 80+12 || arg_full)
+ printf("%-25s %-6s %-12s %-18s %-15s %s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB", "DESCRIPTION");
+ else
+ printf("%-25s %-6s %-12s %-18s %-15s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB");
+ }
+
+ for (const struct unit_info *u = unit_infos; u < unit_infos + c; u++) {
+ const char *dot;
+
+ if ((!arg_type || ((dot = strrchr(u->id, '.')) &&
+ streq(dot+1, arg_type))) &&
+ (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0)) {
+ char *e;
+ int a = 0, b = 0;
+ const char *on_loaded, *off_loaded;
+ const char *on_active, *off_active;
+
+ if (!streq(u->load_state, "loaded")) {
+ on_loaded = ansi_highlight(true);
+ off_loaded = ansi_highlight(false);
+ } else
+ on_loaded = off_loaded = "";
+
+ if (streq(u->active_state, "failed")) {
+ on_active = ansi_highlight(true);
+ off_active = ansi_highlight(false);
+ } else
+ on_active = off_active = "";
+
+ e = arg_full ? NULL : ellipsize(u->id, 25, 33);
+
+ printf("%-25s %s%-6s%s %s%-12s %-18s%s%n",
+ e ? e : u->id,
+ on_loaded, u->load_state, off_loaded,
+ on_active, u->active_state, u->sub_state, off_active,
+ &a);
+
+ free(e);
+
+ a -= strlen(on_loaded) + strlen(off_loaded);
+ a -= strlen(on_active) + strlen(off_active);
+
+ if (u->job_id != 0)
+ printf(" %-15s%n", u->job_type, &b);
+ else
+ b = 1 + 15;
+
+ if (a + b + 1 < columns()) {
+ if (u->job_id == 0)
+ printf(" ");
+
+ if (arg_full)
+ printf(" %s", u->description);
+ else
+ printf(" %.*s", columns() - a - b - 1, u->description);
+ }
+
+ fputs("\n", stdout);
+ }
+ }
+
+ if (!on_tty()) {
+ printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
+ "ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
+ "SUB = The low-level unit activation state, values depend on unit type.\n"
+ "JOB = Pending job for the unit.\n");
+
+ if (arg_all)
+ printf("\n%u units listed.\n", c);
+ else
+ printf("\n%u units listed. Pass --all to see inactive units, too.\n", c);
+ }
+}
+
static int list_units(DBusConnection *bus, char **args, unsigned n) {
DBusMessage *m = NULL, *reply = NULL;
DBusError error;
int r;
DBusMessageIter iter, sub, sub2;
- unsigned c = 0, k, n_units = 0;
+ unsigned c = 0, n_units = 0;
struct unit_info *unit_infos = NULL;
dbus_error_init(&error);
@@ -336,82 +412,7 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
}
qsort(unit_infos, c, sizeof(struct unit_info), compare_unit_info);
-
- if (on_tty()) {
- if (columns() >= 80+12 || arg_full)
- printf("%-25s %-6s %-12s %-18s %-15s %s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB", "DESCRIPTION");
- else
- printf("%-25s %-6s %-12s %-18s %-15s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB");
- }
-
- for (k = 0; k < c; k++) {
- const char *dot;
- struct unit_info *u = unit_infos+k;
-
- if ((!arg_type || ((dot = strrchr(u->id, '.')) &&
- streq(dot+1, arg_type))) &&
- (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0)) {
- char *e;
- int a = 0, b = 0;
- const char *on_loaded, *off_loaded;
- const char *on_active, *off_active;
-
- if (!streq(u->load_state, "loaded")) {
- on_loaded = ansi_highlight(true);
- off_loaded = ansi_highlight(false);
- } else
- on_loaded = off_loaded = "";
-
- if (streq(u->active_state, "failed")) {
- on_active = ansi_highlight(true);
- off_active = ansi_highlight(false);
- } else
- on_active = off_active = "";
-
- e = arg_full ? NULL : ellipsize(u->id, 25, 33);
-
- printf("%-25s %s%-6s%s %s%-12s %-18s%s%n",
- e ? e : u->id,
- on_loaded, u->load_state, off_loaded,
- on_active, u->active_state, u->sub_state, off_active,
- &a);
-
- free(e);
-
- a -= strlen(on_loaded) + strlen(off_loaded);
- a -= strlen(on_active) + strlen(off_active);
-
- if (u->job_id != 0)
- printf(" %-15s%n", u->job_type, &b);
- else
- b = 1 + 15;
-
- if (a + b + 1 < columns()) {
- if (u->job_id == 0)
- printf(" ");
-
- if (arg_full)
- printf(" %s", u->description);
- else
- printf(" %.*s", columns() - a - b - 1, u->description);
- }
-
- fputs("\n", stdout);
- }
- }
-
- if (on_tty()) {
-
- printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
- "ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
- "SUB = The low-level unit activation state, values depend on unit type.\n"
- "JOB = Pending job for the unit.\n");
-
- if (arg_all)
- printf("\n%u units listed.\n", c);
- else
- printf("\n%u units listed. Pass --all to see inactive units, too.\n", c);
- }
+ output_units_list(unit_infos, c);
r = 0;
commit ef639c5f9e9ed397424b50b14e2160993c7841d1
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Sep 7 10:30:50 2010 +0200
systemctl: use on_tty() helper everywhere
diff --git a/src/systemctl.c b/src/systemctl.c
index 1f93bc9..ff6f86a 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -337,7 +337,7 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
qsort(unit_infos, c, sizeof(struct unit_info), compare_unit_info);
- if (isatty(STDOUT_FILENO)) {
+ if (on_tty()) {
if (columns() >= 80+12 || arg_full)
printf("%-25s %-6s %-12s %-18s %-15s %s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB", "DESCRIPTION");
else
@@ -400,7 +400,7 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
}
}
- if (isatty(STDOUT_FILENO)) {
+ if (on_tty()) {
printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
"ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
More information about the systemd-commits
mailing list