X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsystemctl.c;h=03143379030cf2d7e10213a6fc071dfe8d530262;hb=4627d39661ffcdd11e814650dfcc9ac3d0d0ec0b;hp=081f34bcfd17b493f0c8893b15f98dc1d72a4d02;hpb=f4579ce704b9db0358b90c282da9536410a4df5a;p=elogind.git diff --git a/src/systemctl.c b/src/systemctl.c index 081f34bcf..031433790 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -42,6 +42,7 @@ #include "initreq.h" #include "strv.h" #include "dbus-common.h" +#include "cgroup-show.h" static const char *arg_type = NULL; static const char *arg_property = NULL; @@ -109,31 +110,6 @@ static int bus_iter_get_basic_and_next(DBusMessageIter *iter, int type, void *da return 0; } -static int columns(void) { - static int parsed_columns = 0; - const char *e; - - if (parsed_columns > 0) - return parsed_columns; - - if ((e = getenv("COLUMNS"))) - parsed_columns = atoi(e); - - if (parsed_columns <= 0) { - struct winsize ws; - zero(ws); - - if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) >= 0) - parsed_columns = ws.ws_col; - } - - if (parsed_columns <= 0) - parsed_columns = 80; - - return parsed_columns; - -} - static void warn_wall(enum action action) { static const char *table[_ACTION_MAX] = { [ACTION_HALT] = "The system is going down for system halt NOW!", @@ -239,20 +215,26 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) { int a = 0, b = 0; + if (streq(active_state, "maintenance")) + fputs(ANSI_HIGHLIGHT_ON, stdout); + printf("%-45s %-6s %-12s %-12s%n", id, load_state, active_state, sub_state, &a); if (job_id != 0) printf(" %-15s%n", job_type, &b); else - b = 1 + 16; + b = 1 + 15; if (a + b + 2 < columns()) { if (job_id == 0) printf(" "); - printf("%.*s", columns() - a - b - 2, description); + printf(" %.*s", columns() - a - b - 2, description); } + if (streq(active_state, "maintenance")) + fputs(ANSI_HIGHLIGHT_OFF, stdout); + fputs("\n", stdout); k++; } @@ -523,10 +505,10 @@ static DBusHandlerResult wait_filter(DBusConnection *connection, DBusMessage *me dbus_error_init(&error); - /* log_debug("Got D-Bus request: %s.%s() on %s", */ - /* dbus_message_get_interface(message), */ - /* dbus_message_get_member(message), */ - /* dbus_message_get_path(message)); */ + log_debug("Got D-Bus request: %s.%s() on %s", + dbus_message_get_interface(message), + dbus_message_get_member(message), + dbus_message_get_path(message)); if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) { log_error("Warning! D-Bus connection terminated."); @@ -940,53 +922,6 @@ finish: return r; } -static void show_cgroup(const char *name) { - char *fn; - FILE *f; - pid_t last = 0; - - if (!startswith(name, "name=systemd:")) - return; - - if (asprintf(&fn, "/cgroup/systemd/%s/tasks", name + 13) < 0) - return; - - f = fopen(fn, "r"); - free(fn); - - if (!f) - return; - - while (!feof(f)) { - unsigned long ul; - - if (fscanf(f, "%lu", &ul) != 1) - break; - - if (ul <= 0) - continue; - - if (last > 0) { - char *t = NULL; - get_process_cmdline(last, 60, &t); - printf("\t\t \342\224\234 %lu %s\n", (unsigned long) last, strna(t)); - free(t); - } else - printf("\t\t \342\224\202\n"); - - last = (pid_t) ul; - } - - if (last > 0) { - char *t = NULL; - get_process_cmdline(last, 60, &t); - printf("\t\t \342\224\224 %lu %s\n", (unsigned long) last, strna(t)); - free(t); - } - - fclose(f); -} - typedef struct UnitStatusInfo { const char *id; const char *load_state; @@ -1108,8 +1043,16 @@ static void print_status_info(UnitStatusInfo *i) { } if (i->default_control_group) { + unsigned c; + printf("\t CGroup: %s\n", i->default_control_group); - show_cgroup(i->default_control_group); + + if ((c = columns()) > 18) + c -= 18; + else + c = 0; + + show_cgroup_recursive(i->default_control_group, "\t\t ", c); } } @@ -1725,10 +1668,10 @@ static DBusHandlerResult monitor_filter(DBusConnection *connection, DBusMessage dbus_error_init(&error); - /* log_debug("Got D-Bus request: %s.%s() on %s", */ - /* dbus_message_get_interface(message), */ - /* dbus_message_get_member(message), */ - /* dbus_message_get_path(message)); */ + log_debug("Got D-Bus request: %s.%s() on %s", + dbus_message_get_interface(message), + dbus_message_get_member(message), + dbus_message_get_path(message)); if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) { log_error("Warning! D-Bus connection terminated."); @@ -3101,7 +3044,7 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[]) { { "reboot", EQUAL, 1, start_special }, { "default", EQUAL, 1, start_special }, { "rescue", EQUAL, 1, start_special }, - { "emergency", EQUAL, 1, start_special }, + { "emergency", EQUAL, 1, start_special } }; int left; @@ -3213,7 +3156,12 @@ static int start_with_fallback(DBusConnection *bus) { static int halt_main(DBusConnection *bus) { int r; - if (!arg_immediate) + if (geteuid() != 0) { + log_error("Must to be root."); + return -EPERM; + } + + if (!arg_dry && !arg_immediate) return start_with_fallback(bus); if (!arg_no_wtmp)