27
27
#include <sys/types.h>
29
29
#include <lxc/lxc.h>
30
#include "arguments.h"
32
lxc_log_define(lxc_cgroup, lxc);
34
static int my_checker(const struct lxc_arguments* args)
33
fprintf(stderr, "%s <subsystem> [value]\n", basename(cmd));
34
fprintf(stderr, "\t -n <name> : name of the container\n");
37
lxc_error(args, "missing cgroup subsystem");
43
static const struct option my_longopts[] = {
47
static struct lxc_arguments my_args = {
48
.progname = "lxc-cgroup",
50
--name=NAME subsystem [value]\n\
52
lxc-cgroup get or set subsystem value of cgroup\n\
53
associated with the NAME container\n\
56
-n, --name=NAME NAME for name of the container",
57
.options = my_longopts,
59
.checker = my_checker,
38
62
int main(int argc, char *argv[])
41
char *name = NULL, *subsystem = NULL, *value = NULL;
44
while ((opt = getopt(argc, argv, "n:")) != -1) {
54
if (!name || argc < 4)
64
char *subsystem = NULL, *value = NULL;
66
if (lxc_arguments_parse(&my_args, argc, argv))
69
if (lxc_log_init(my_args.log_file, my_args.log_priority,
70
my_args.progname, my_args.quiet))
73
subsystem = my_args.argv[0];
76
value = my_args.argv[1];
63
if (lxc_cgroup_set(name, subsystem, value)) {
64
fprintf(stderr, "failed to assign '%s' value to '%s' for '%s'\n",
65
value, subsystem, name);
79
if (lxc_cgroup_set(my_args.name, subsystem, value)) {
80
ERROR("failed to assign '%s' value to '%s' for '%s'",
81
value, subsystem, my_args.name);
69
85
const unsigned long len = 4096;
71
if (lxc_cgroup_get(name, subsystem, buffer, len)) {
72
fprintf(stderr, "failed to retrieve value of '%s' for '%s'\n",
87
if (lxc_cgroup_get(my_args.name, subsystem, buffer, len)) {
88
ERROR("failed to retrieve value of '%s' for '%s'",
89
subsystem, my_args.name);
77
93
printf("%s", buffer);