#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;
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!",
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;
/* Socket */
unsigned n_accepted;
unsigned n_connections;
+ bool accept;
/* Device */
const char *sysfs_path;
if (i->status_text)
printf("\t Status: \"%s\"\n", i->status_text);
- if (i->id && endswith(i->id, ".socket"))
+ if (i->accept)
printf("\tAccepted: %u; Connected: %u\n", i->n_accepted, i->n_connections);
if (i->main_pid > 0 || i->control_pid > 0) {
}
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);
}
}
break;
}
+ case DBUS_TYPE_BOOLEAN: {
+ dbus_bool_t b;
+
+ dbus_message_iter_get_basic(iter, &b);
+
+ if (streq(name, "Accept"))
+ i->accept = b;
+
+ break;
+ }
+
case DBUS_TYPE_UINT32: {
uint32_t u;
{ "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;
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)