return r;
}
+static void show_cgroup(const char *name) {
+ char *fn, *pids;
+ int r;
+ char *p;
+
+ if (!startswith(name, "name=systemd:"))
+ return;
+
+ if (asprintf(&fn, "/cgroup/systemd/%s/tasks", name + 13) < 0)
+ return;
+
+ r = read_one_line_file(fn, &pids);
+ free(fn);
+
+ if (r < 0)
+ return;
+
+ p = pids;
+ while (p[0]) {
+ unsigned long ul;
+ char *t = NULL;
+
+ p += strspn(p, WHITESPACE);
+
+ errno = 0;
+ ul = strtoul(p, &p, 0);
+ if (errno != 0 || ul <= 0)
+ break;
+
+ get_process_cmdline((pid_t) ul, 60, &t);
+ printf("\t\t%lu %s\n", ul, strna(t));
+ free(t);
+ }
+
+ free(pids);
+}
+
typedef struct UnitStatusInfo {
const char *id;
const char *load_state;
printf("\n");
}
- if (i->default_control_group)
+ if (i->default_control_group) {
printf("\t CGroup: %s\n", i->default_control_group);
+ show_cgroup(i->default_control_group);
+ }
}
static int status_property(const char *name, DBusMessageIter *iter, UnitStatusInfo *i) {
return 0;
}
+int get_process_cmdline(pid_t pid, size_t max_length, char **line) {
+ char *p, *r, *k;
+ int c;
+ bool space = false;
+ size_t left;
+ FILE *f;
+
+ assert(pid >= 1);
+ assert(max_length > 0);
+ assert(line);
+
+ if (asprintf(&p, "/proc/%lu/cmdline", (unsigned long) pid) < 0)
+ return -ENOMEM;
+
+ f = fopen(p, "r");
+ free(p);
+
+ if (!f)
+ return -errno;
+
+ if (!(r = new(char, max_length))) {
+ fclose(f);
+ return -ENOMEM;
+ }
+
+ k = r;
+ left = max_length;
+ while ((c = getc(f)) != EOF) {
+
+ if (isprint(c)) {
+ if (space) {
+ if (left <= 4)
+ break;
+
+ *(k++) = ' ';
+ space = false;
+ }
+
+ if (left <= 4)
+ break;
+
+ *(k++) = (char) c;
+ } else
+ space = true;
+ }
+
+ if (left <= 4) {
+ size_t n = MIN(left-1, 3U);
+ memcpy(k, "...", n);
+ k[n] = 0;
+ } else
+ *k = 0;
+
+ fclose(f);
+
+ *line = r;
+ return 0;
+}
+
char *strappend(const char *s, const char *suffix) {
size_t a, b;
char *r;
int rmdir_parents(const char *path, const char *stop);
int get_process_name(pid_t pid, char **name);
+int get_process_cmdline(pid_t pid, size_t max_length, char **line);
char hexchar(int x);
int unhexchar(char c);