lxc_cgroup.c revision ab1bf971d2db43777cbf3892fb887bf71ce7d155
2ronwalf/*
2ronwalf * lxc: linux Container library
2ronwalf *
2ronwalf * (C) Copyright IBM Corp. 2007, 2008
2ronwalf *
2ronwalf * Authors:
2ronwalf * Daniel Lezcano <daniel.lezcano at free.fr>
2ronwalf *
2ronwalf * This library is free software; you can redistribute it and/or
2ronwalf * modify it under the terms of the GNU Lesser General Public
2ronwalf * License as published by the Free Software Foundation; either
2ronwalf * version 2.1 of the License, or (at your option) any later version.
2ronwalf *
2ronwalf * This library is distributed in the hope that it will be useful,
2ronwalf * but WITHOUT ANY WARRANTY; without even the implied warranty of
2ronwalf * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2ronwalf * Lesser General Public License for more details.
2ronwalf *
2ronwalf * You should have received a copy of the GNU Lesser General Public
2ronwalf * License along with this library; if not, write to the Free Software
2ronwalf * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2ronwalf */
2ronwalf
2ronwalf#include <stdio.h>
2ronwalf#include <unistd.h>
2ronwalf#include <libgen.h>
2ronwalf#include <sys/types.h>
2ronwalf
38daenzerorama#include <lxc/lxc.h>
2ronwalf#include <lxc/log.h>
2ronwalf
2ronwalf#include "arguments.h"
38daenzerorama
2ronwalflxc_log_define(lxc_cgroup_ui, lxc_cgroup);
2ronwalf
38daenzeroramastatic int my_checker(const struct lxc_arguments* args)
38daenzerorama{
38daenzerorama if (!args->argc) {
38daenzerorama lxc_error(args, "missing state object");
38daenzerorama return -1;
2ronwalf }
38daenzerorama return 0;
38daenzerorama}
38daenzerorama
38daenzeroramastatic const struct option my_longopts[] = {
38daenzerorama LXC_COMMON_OPTIONS
2ronwalf};
2ronwalf
38daenzeroramastatic struct lxc_arguments my_args = {
38daenzerorama .progname = "lxc-cgroup",
38daenzerorama .help = "\
38daenzerorama--name=NAME state-object [value]\n\
38daenzerorama\n\
2ronwalfGet or set the value of a state object (for example, 'cpuset.cpus')\n\
38daenzeroramain the container's cgroup for the corresponding subsystem.\n\
38daenzerorama\n\
38daenzeroramaOptions :\n\
38daenzerorama -n, --name=NAME container name",
38daenzerorama .options = my_longopts,
38daenzerorama .parser = NULL,
2ronwalf .checker = my_checker,
38daenzerorama};
38daenzerorama
38daenzeroramaint main(int argc, char *argv[])
38daenzerorama{
38daenzerorama char *state_object = NULL, *value = NULL;
38daenzerorama
38daenzerorama if (lxc_arguments_parse(&my_args, argc, argv))
38daenzerorama return -1;
38daenzerorama
38daenzerorama if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
2ronwalf my_args.progname, my_args.quiet, my_args.lxcpath))
return -1;
state_object = my_args.argv[0];
if ((argc) > 1)
value = my_args.argv[1];
if (value) {
if (lxc_cgroup_set(my_args.name, state_object, value, my_args.lxcpath)) {
ERROR("failed to assign '%s' value to '%s' for '%s'",
value, state_object, my_args.name);
return -1;
}
} else {
const unsigned long len = 4096;
int ret;
char buffer[len];
ret = lxc_cgroup_get(my_args.name, state_object, buffer, len, my_args.lxcpath);
if (ret < 0) {
ERROR("failed to retrieve value of '%s' for '%s'",
state_object, my_args.name);
return -1;
}
printf("%*s", ret, buffer);
}
return 0;
}