chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
72f9570
)
systemctl: fix parsing of cgroup contents
author
Lennart Poettering
<lennart@poettering.net>
Tue, 6 Jul 2010 03:38:12 +0000
(
05:38
+0200)
committer
Lennart Poettering
<lennart@poettering.net>
Tue, 6 Jul 2010 03:38:12 +0000
(
05:38
+0200)
src/systemctl.c
patch
|
blob
|
history
diff --git
a/src/systemctl.c
b/src/systemctl.c
index 73b0fc48cc1d0fc93cd652b0cd13c0c1e36ea110..6977f85b3f7d0daeceeb3b15de6dcefce94e8b48 100644
(file)
--- a/
src/systemctl.c
+++ b/
src/systemctl.c
@@
-935,9
+935,9
@@
finish:
}
static void show_cgroup(const char *name) {
}
static void show_cgroup(const char *name) {
- char *fn
, *pids
;
-
int r
;
-
char *p
;
+ char *fn;
+
FILE *f
;
+
pid_t last = 0
;
if (!startswith(name, "name=systemd:"))
return;
if (!startswith(name, "name=systemd:"))
return;
@@
-945,30
+945,41
@@
static void show_cgroup(const char *name) {
if (asprintf(&fn, "/cgroup/systemd/%s/tasks", name + 13) < 0)
return;
if (asprintf(&fn, "/cgroup/systemd/%s/tasks", name + 13) < 0)
return;
-
r = read_one_line_file(fn, &pids
);
+
f = fopen(fn, "r"
);
free(fn);
free(fn);
- if (
r < 0
)
+ if (
!f
)
return;
return;
- p = pids;
- while (p[0]) {
- unsigned long ul;
- char *t = NULL;
+ printf("\t\t │\n");
- p += strspn(p, WHITESPACE);
+ while (!feof(f)) {
+ unsigned long ul;
- errno = 0;
- ul = strtoul(p, &p, 0);
- if (errno != 0 || ul <= 0)
+ if (fscanf(f, "%lu", &ul) != 1)
break;
break;
- get_process_cmdline((pid_t) ul, 60, &t);
- printf("\t\t%lu %s\n", ul, strna(t));
+ if (ul <= 0)
+ continue;
+
+ if (last > 0) {
+ char *t = NULL;
+ get_process_cmdline(last, 60, &t);
+ printf("\t\t ├ %lu %s\n", (unsigned long) last, strna(t));
+ free(t);
+ }
+
+ last = (pid_t) ul;
+ }
+
+ if (last > 0) {
+ char *t = NULL;
+ get_process_cmdline(last, 60, &t);
+ printf("\t\t └ %lu %s\n", (unsigned long) last, strna(t));
free(t);
}
free(t);
}
- f
ree(pids
);
+ f
close(f
);
}
typedef struct UnitStatusInfo {
}
typedef struct UnitStatusInfo {