chiark / gitweb /
systemctl: avoid wrapping of headers/footers
[elogind.git] / src / systemctl.c
index bfb7001efc0b7f58e6f901bdb1161686f2351c19..de41db79e2eb4e5bcd9bef7733fae1bae2476f04 100644 (file)
@@ -130,8 +130,7 @@ static const char *ansi_highlight_green(bool b) {
         return b ? ANSI_HIGHLIGHT_GREEN_ON : ANSI_HIGHLIGHT_OFF;
 }
 
-static bool error_is_no_service(DBusError *error) {
-
+static bool error_is_no_service(const DBusError *error) {
         assert(error);
 
         if (!dbus_error_is_set(error))
@@ -313,8 +312,12 @@ 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))
-                printf("%-45s %-6s %-12s %-12s %-15s %s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB", "DESCRIPTION");
+        if (isatty(STDOUT_FILENO)) {
+                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;
@@ -325,30 +328,47 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
                     (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0)) {
                         char *e;
                         int a = 0, b = 0;
-                        const char *on, *off;
+                        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, "maintenance")) {
-                                on = ansi_highlight(true);
-                                off = ansi_highlight(false);
+                        if (streq(u->active_state, "failed")) {
+                                on_active = ansi_highlight(true);
+                                off_active = ansi_highlight(false);
                         } else
-                                on = off = "";
+                                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);
 
-                        e = arg_full ? NULL : ellipsize(u->id, 45, 33);
-                        printf("%-45s %-6s %s%-12s %-12s%s%n", e ? e : u->id, u->load_state, on, u->active_state, u->sub_state, off, &a);
                         free(e);
 
-                        a -= strlen(on) + strlen(off);
+                        a -= strlen(on_loaded) + strlen(off_loaded);
+                        a -= strlen(on_active) + strlen(off_active);
 
                         if (u->job_id != 0)
-                                printf(" => %-12s%n", u->job_type, &b);
+                                printf(" %-15s%n", u->job_type, &b);
                         else
                                 b = 1 + 15;
 
-                        if (a + b + 2 < columns()) {
+                        if (a + b + 1 < columns()) {
                                 if (u->job_id == 0)
                                         printf("                ");
 
-                                printf(" %.*s", columns() - a - b - 2, u->description);
+                                if (arg_full)
+                                        printf(" %s", u->description);
+                                else
+                                        printf(" %.*s", columns() - a - b - 1, u->description);
                         }
 
                         fputs("\n", stdout);
@@ -664,7 +684,8 @@ static int list_jobs(DBusConnection *bus, char **args, unsigned n) {
 
         dbus_message_iter_recurse(&iter, &sub);
 
-        printf("%4s %-45s %-17s %-7s\n", "JOB", "UNIT", "TYPE", "STATE");
+        if (isatty(STDOUT_FILENO))
+                printf("%4s %-25s %-15s %-7s\n", "JOB", "UNIT", "TYPE", "STATE");
 
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
                 const char *name, *type, *state, *job_path, *unit_path;
@@ -690,8 +711,8 @@ static int list_jobs(DBusConnection *bus, char **args, unsigned n) {
                         goto finish;
                 }
 
-                e = arg_full ? NULL : ellipsize(name, 45, 33);
-                printf("%4u %-45s %-17s %-7s\n", id, e ? e : name, type, state);
+                e = arg_full ? NULL : ellipsize(name, 25, 33);
+                printf("%4u %-25s %-15s %-7s\n", id, e ? e : name, type, state);
                 free(e);
 
                 k++;
@@ -699,7 +720,9 @@ static int list_jobs(DBusConnection *bus, char **args, unsigned n) {
                 dbus_message_iter_next(&sub);
         }
 
-        printf("\n%u jobs listed.\n", k);
+        if (isatty(STDOUT_FILENO))
+                printf("\n%u jobs listed.\n", k);
+
         r = 0;
 
 finish:
@@ -1557,7 +1580,7 @@ static void print_status_info(UnitStatusInfo *i) {
 
         ss = streq_ptr(i->active_state, i->sub_state) ? NULL : i->sub_state;
 
-        if (streq_ptr(i->active_state, "maintenance")) {
+        if (streq_ptr(i->active_state, "failed")) {
                 on = ansi_highlight(true);
                 off = ansi_highlight(false);
         } else if (streq_ptr(i->active_state, "active") || streq_ptr(i->active_state, "reloading")) {
@@ -1581,7 +1604,7 @@ static void print_status_info(UnitStatusInfo *i) {
         timestamp = (streq_ptr(i->active_state, "active")      ||
                      streq_ptr(i->active_state, "reloading"))   ? i->active_enter_timestamp :
                     (streq_ptr(i->active_state, "inactive")    ||
-                     streq_ptr(i->active_state, "maintenance")) ? i->inactive_enter_timestamp :
+                     streq_ptr(i->active_state, "failed"))      ? i->inactive_enter_timestamp :
                     streq_ptr(i->active_state, "activating")    ? i->inactive_exit_timestamp :
                                                                   i->active_exit_timestamp;
 
@@ -2864,7 +2887,7 @@ static int daemon_reload(DBusConnection *bus, char **args, unsigned n) {
                         streq(args[0], "clear-jobs")        ||
                         streq(args[0], "cancel")            ? "ClearJobs" :
                         streq(args[0], "daemon-reexec")     ? "Reexecute" :
-                        streq(args[0], "reset-maintenance") ? "ResetMaintenance" :
+                        streq(args[0], "reset-failed")      ? "ResetFailed" :
                         streq(args[0], "daemon-exit")       ? "Exit" :
                                                               "Reload";
         }
@@ -2906,7 +2929,7 @@ finish:
         return r;
 }
 
-static int reset_maintenance(DBusConnection *bus, char **args, unsigned n) {
+static int reset_failed(DBusConnection *bus, char **args, unsigned n) {
         DBusMessage *m = NULL, *reply = NULL;
         unsigned i;
         int r;
@@ -2924,7 +2947,7 @@ static int reset_maintenance(DBusConnection *bus, char **args, unsigned n) {
                                       "org.freedesktop.systemd1",
                                       "/org/freedesktop/systemd1",
                                       "org.freedesktop.systemd1.Manager",
-                                      "ResetMaintenanceUnit"))) {
+                                      "ResetFailedUnit"))) {
                         log_error("Could not allocate message.");
                         r = -ENOMEM;
                         goto finish;
@@ -3834,8 +3857,8 @@ static int systemctl_help(void) {
                "  status [NAME...|PID...]         Show runtime status of one or more units\n"
                "  show [NAME...|JOB...]           Show properties of one or more\n"
                "                                  units/jobs or the manager\n"
-               "  reset-maintenance [NAME...]     Reset maintenance state for all, one,\n"
-               "                                  or more units\n"
+               "  reset-failed [NAME...]          Reset failed state for all, one, or more\n"
+               "                                  units\n"
                "  enable [NAME...]                Enable one or more unit files\n"
                "  disable [NAME...]               Disable one or more unit files\n"
                "  is-enabled [NAME...]            Check whether unit files are enabled\n"
@@ -4677,7 +4700,7 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
                 { "default",               EQUAL, 1, start_special     },
                 { "rescue",                EQUAL, 1, start_special     },
                 { "emergency",             EQUAL, 1, start_special     },
-                { "reset-maintenance",     MORE,  1, reset_maintenance },
+                { "reset-failed",          MORE,  1, reset_failed      },
                 { "enable",                MORE,  2, enable_unit       },
                 { "disable",               MORE,  2, enable_unit       },
                 { "is-enabled",            MORE,  2, enable_unit       }
@@ -4862,7 +4885,7 @@ static int halt_main(DBusConnection *bus) {
         int r;
 
         if (geteuid() != 0) {
-                log_error("Must to be root.");
+                log_error("Must be root.");
                 return -EPERM;
         }