]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
lssubsys: new option -a,--all
authorIvana Hutarova Varekova <varekova@redhat.com>
Thu, 10 Dec 2009 12:25:21 +0000 (13:25 +0100)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Wed, 16 Dec 2009 08:33:20 +0000 (14:03 +0530)
This patch adds new option to lssubsys command
lssubsys with this option displays moreover controllers which are
not mounted
The patch change the behavior of lssubsys a bit - there is no
error message if controllers are not mounted and lssubsys is called.

Example:
$  ./lssubsys -a
devices
cpuset,cpuacct
ns
cpu

$  ./lssubsys -am
devices /mnt/cgroups/devices
cpuset,cpuacct /mnt/cgroups/cpuset
ns
cpu

$  ./lssubsys

Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
doc/man/lssubsys.1
src/tools/lssubsys.c

index 9ea97d6f183d3362b01e66dd7c3e3b2668fbdf71..2b62f1df0a21f35c6bff3235cacd43843310d9d2 100644 (file)
@@ -7,7 +7,7 @@
 lssubsys \- list hierarchies containing given subsystem
 
 .SH SYNOPSIS
-\fBlssubsys\fR  [\fB-m|--mount-points\fR] [\fIcontroller\fR] [...]
+\fBlssubsys\fR  [\fB-m|--mount-points\fR] [\fB-a|--all\fR] [\fIcontroller\fR] [...]
 .br
 \fBlssubsys\fR  [\fB-h|--help\fR]
 
@@ -26,6 +26,10 @@ list all subsystems which are present.
 .B -m, --mount-points
 Display mount points.
 
+.TP
+.B -a, --all
+Display not mounted subsystems.
+
 .TP
 .B -h, --help
 Display help and exit.
index 959b9bfc89057c4658024c76a18bbcafe338070d..22999221a59efe8d300c12f83b069b96d149d60c 100644 (file)
@@ -19,8 +19,9 @@
 #include <libcgroup.h>
 
 enum flag{
-    FL_MOUNT = 1,
-    FL_LIST = 2
+    FL_MOUNT = 1,      /* show the mount points */
+    FL_LIST = 2,
+    FL_ALL = 4         /* show all subsystems - not mounted too */
 };
 
 typedef char cont_name_t[FILENAME_MAX];
@@ -37,6 +38,8 @@ void usage(int status, char *program_name)
                fprintf(stdout, "list all sybsystems of given controller\n");
                fprintf(stdout, "  -h, --help           Display this help\n");
                fprintf(stdout, "  -m, --mount-points   Display mount points\n");
+               fprintf(stdout, "  -a, --all            ");
+               fprintf(stdout, "Display all not mounted subsystems\n");
        }
 }
 
@@ -119,10 +122,13 @@ int cgroup_list_controllers(char *tname,
 
        /* initialize libcgroup */
        ret = cgroup_init();
+
        if (ret) {
-               fprintf(stderr, "controllers can't be listed: %s\n",
-                       cgroup_strerror(ret));
-               return ret;
+               if (flags & FL_ALL) {
+                       return 0;
+               } else {
+                       return ret;
+               }
        }
 
        if ((flags & FL_LIST) == 0) {
@@ -156,6 +162,32 @@ int cgroup_list_controllers(char *tname,
        return final_ret;
 }
 
+int cgroup_list_all_controllers(char *tname)
+{
+       int ret = 0;
+       void *handle;
+       struct controller_data info;
+
+       ret = cgroup_get_all_controller_begin(&handle, &info);
+
+       while (ret != ECGEOF) {
+               if (info.hierarchy == 0)
+                       printf("%s\n", info.name);
+               ret = cgroup_get_all_controller_next(&handle, &info);
+               if (ret && ret != ECGEOF) {
+                       fprintf(stderr,
+                               "%s: cgroup_get_controller_next failed (%s)\n",
+                               tname, cgroup_strerror(ret));
+                       return ret;
+               }
+       }
+
+       ret = cgroup_get_all_controller_end(&handle);
+
+       return ret;
+
+}
+
 int main(int argc, char *argv[])
 {
 
@@ -171,6 +203,7 @@ int main(int argc, char *argv[])
        static struct option options[] = {
                {"help", 0, 0, 'h'},
                {"mount-points", 0, 0, 'm'},
+               {"all", 0, 0, 'a'},
                {0, 0, 0, 0}
        };
 
@@ -178,7 +211,7 @@ int main(int argc, char *argv[])
                cont_name[i][0] = '\0';
 
        /* parse arguments */
-       while ((c = getopt_long(argc, argv, "mh", options, NULL)) > 0) {
+       while ((c = getopt_long(argc, argv, "mha", options, NULL)) > 0) {
                switch (c) {
                case 'h':
                        usage(0, argv[0]);
@@ -186,6 +219,9 @@ int main(int argc, char *argv[])
                case 'm':
                        flags |= FL_MOUNT;
                        break;
+               case 'a':
+                       flags |= FL_ALL;
+                       break;
                default:
                        usage(1, argv[0]);
                        return -1;
@@ -211,6 +247,11 @@ int main(int argc, char *argv[])
         * based on list of input controllers and flags
         */
        ret = cgroup_list_controllers(argv[0], cont_name, flags);
+       if (ret)
+               return ret;
+
+       if (flags & FL_ALL)
+               ret = cgroup_list_all_controllers(argv[0]);
 
        return ret;
 }