]> git.proxmox.com Git - mirror_lxc.git/commitdiff
Add a command line to setup/retrieve value of cgroup subsystem, lxc-cgroup -n <contai...
authordlezcano <dlezcano>
Tue, 7 Oct 2008 14:24:56 +0000 (14:24 +0000)
committerdlezcano <dlezcano>
Tue, 7 Oct 2008 14:24:56 +0000 (14:24 +0000)
src/lxc/lxc_cgroup.c

index 8a91566039aaa1dc3f76fa6b6743354b97582767..5a412cadb5366421ee3214bdab9df5766f4489cd 100644 (file)
  */
 
 #include <stdio.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <sys/types.h>
+
 #include <lxc/lxc.h>
 
+void usage(char *cmd)
+{
+       fprintf(stderr, "%s <subsystem> [value]\n", basename(cmd));
+       fprintf(stderr, "\t -n <name>   : name of the container\n");
+       _exit(1);
+}
+
 int main(int argc, char *argv[])
 {
+       char opt;
+       char *name = NULL, *subsystem = NULL, *value = NULL;
+       int nbargs = 0;
+
+       while ((opt = getopt(argc, argv, "n:")) != -1) {
+               switch (opt) {
+               case 'n':
+                       name = optarg;
+                       break;
+               }
+
+               nbargs++;
+       }
+
+       if (!name || argc < 4)
+               usage(argv[0]);
+
+       if (argc >= 5)
+               value = argv[4];
+
+       subsystem = argv[3];
+
+       if (value) {
+               if (lxc_cgroup_set(name, subsystem, value)) {
+                       fprintf(stderr, "failed to assign '%s' value to '%s' for '%s'\n",
+                               value, subsystem, name);
+                       return 1;
+               }
+       } else {
+               const unsigned long len = 4096;
+               char buffer[len];
+               if (lxc_cgroup_get(name, subsystem, buffer, len)) {
+                       fprintf(stderr, "failed to retrieve value of '%s' for '%s'\n",
+                               subsystem, name);
+                       return 1;
+               }
+
+               printf("%s", buffer);
+       }
+
        return 0;
 }