]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/cgroup-show.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / shared / cgroup-show.c
index d1132779aaf1a16fcd3d172f36c3e7156eac6332..57b7aeb228216b990ef1c32284f680402059c8fe 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdio.h>
-#include <string.h>
 #include <dirent.h>
 #include <errno.h>
+#include <stdio.h>
+#include <string.h>
 
-#include "util.h"
+#include "cgroup-util.h"
+#include "formats-util.h"
 #include "macro.h"
 #include "path-util.h"
-#include "cgroup-util.h"
+#include "process-util.h"
+#include "string-util.h"
+#include "terminal-util.h"
+#include "util.h"
 #include "cgroup-show.h"
 
 static int compare(const void *a, const void *b) {
@@ -43,7 +47,7 @@ static int compare(const void *a, const void *b) {
 static void show_pid_array(pid_t pids[], unsigned n_pids, const char *prefix, unsigned n_columns, bool extra, bool more, bool kernel_threads, OutputFlags flags) {
         unsigned i, j, pid_width;
 
-        if (n_pids <= 0)
+        if (n_pids == 0)
                 return;
 
         qsort(pids, n_pids, sizeof(pid_t), compare);
@@ -93,7 +97,7 @@ static int show_cgroup_one_by_path(const char *path, const char *prefix, unsigne
         if (r < 0)
                 return r;
 
-        fn = strappenda(p, "/cgroup.procs");
+        fn = strjoina(p, "/cgroup.procs");
         f = fopen(fn, "re");
         if (!f)
                 return -errno;
@@ -113,8 +117,7 @@ static int show_cgroup_one_by_path(const char *path, const char *prefix, unsigne
         if (r < 0)
                 return r;
 
-        if (n > 0)
-                show_pid_array(pids, n, prefix, n_columns, false, more, kernel_threads, flags);
+        show_pid_array(pids, n, prefix, n_columns, false, more, kernel_threads, flags);
 
         return 0;
 }
@@ -150,7 +153,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
                 if (!k)
                         return -ENOMEM;
 
-                if (!(flags & OUTPUT_SHOW_ALL) && cg_is_empty_recursive(NULL, k, false) > 0)
+                if (!(flags & OUTPUT_SHOW_ALL) && cg_is_empty_recursive(NULL, k) > 0)
                         continue;
 
                 if (!shown_pids) {
@@ -159,8 +162,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
                 }
 
                 if (last) {
-                        printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_BRANCH),
-                                           basename(last));
+                        printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_BRANCH), cg_unescape(basename(last)));
 
                         if (!p1) {
                                 p1 = strappend(prefix, draw_special_char(DRAW_TREE_VERTICAL));
@@ -183,8 +185,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
                 show_cgroup_one_by_path(path, prefix, n_columns, !!last, kernel_threads, flags);
 
         if (last) {
-                printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_RIGHT),
-                                   basename(last));
+                printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_RIGHT), cg_unescape(basename(last)));
 
                 if (!p2) {
                         p2 = strappend(prefix, "  ");