summaryrefslogtreecommitdiff
path: root/src/unit.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2011-11-10 12:53:39 +0100
committerMichal Schmidt <mschmidt@redhat.com>2011-11-11 00:27:02 +0100
commit5831e9b726ab6e76b28a94861a014d3bc2aa3015 (patch)
tree6d09c764e274702cc83bebfb8a743f05fcc5e33a /src/unit.c
parentc5419d4239ceb4c3bd0263a0a810cf24a072b3c0 (diff)
job: colored status messages on boot
The lack or green/red status marks on boot has been described by some users as "critical", "dramatic", "dealbreaker", "showstopper". Seriously.
Diffstat (limited to 'src/unit.c')
-rw-r--r--src/unit.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/unit.c b/src/unit.c
index 903a8e4da4..ad4063b07b 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -924,7 +924,7 @@ int unit_start(Unit *u) {
unit_add_to_dbus_queue(u);
- unit_status_printf(u, "Starting %s...\n", unit_description(u));
+ unit_status_printf(u, NULL, "Starting %s...", unit_description(u));
return UNIT_VTABLE(u)->start(u);
}
@@ -966,7 +966,7 @@ int unit_stop(Unit *u) {
unit_add_to_dbus_queue(u);
- unit_status_printf(u, "Stopping %s...\n", unit_description(u));
+ unit_status_printf(u, NULL, "Stopping %s...", unit_description(u));
return UNIT_VTABLE(u)->stop(u);
}
@@ -2426,8 +2426,11 @@ int unit_coldplug(Unit *u) {
return 0;
}
-void unit_status_printf(Unit *u, const char *format, ...) {
+void unit_status_printf(Unit *u, const char *status, const char *format, ...) {
va_list ap;
+ char *s, *e;
+ int err;
+ const unsigned emax = status ? 80 - (sizeof("[ OK ]")-1) : 80;
assert(u);
assert(format);
@@ -2442,8 +2445,21 @@ void unit_status_printf(Unit *u, const char *format, ...) {
return;
va_start(ap, format);
- status_vprintf(format, ap);
+ err = vasprintf(&s, format, ap);
va_end(ap);
+ if (err < 0)
+ return;
+
+ e = ellipsize(s, emax, 100);
+ free(s);
+ if (!e)
+ return;
+
+ if (status)
+ status_printf("%s%*s[%s]\n", e, emax - strlen(e), "", status);
+ else
+ status_printf("%s\n", e);
+ free(e);
}
bool unit_need_daemon_reload(Unit *u) {