2
* Copyright RedHat Inc. 2008
4
* Authors: Vivek Goyal <vgoyal@redhat.com>
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms of version 2.1 of the GNU Lesser General Public License
8
* as published by the Free Software Foundation.
10
* This program is distributed in the hope that it would be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
#include <libcgroup.h>
27
#include <sys/mount.h>
29
#include <sys/types.h>
31
#include "tools-common.h"
33
static struct option longopts[] = {
34
{"sticky", no_argument, NULL, 's'},
38
int main(int argc, char *argv[])
47
struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
50
fprintf(stderr, "Usage is %s"
51
" [-g <list of controllers>:<relative path to cgroup>]"
52
" [--sticky] command [arguments] \n",
57
memset(cgroup_list, 0, sizeof(cgroup_list));
59
while ((c = getopt_long(argc, argv, "+g:s", longopts, NULL)) > 0) {
62
if (parse_cgroup_spec(cgroup_list, optarg)) {
63
fprintf(stderr, "cgroup controller and path"
70
flag_child |= CGROUP_DAEMON_UNCHANGE_CHILDREN;
73
fprintf(stderr, "Invalid command line option\n");
81
fprintf(stderr, "No command specified\n");
85
/* Initialize libcg */
88
fprintf(stderr, "libcgroup initialization failed: %s\n",
89
cgroup_strerror(ret));
97
ret = cgroup_register_unchanged_process(pid, flag_child);
99
fprintf(stderr, "registration of process failed\n");
104
* 'cgexec' command file needs the root privilege for executing
105
* a cgroup_register_unchanged_process() by using unix domain
106
* socket, and an euid should be changed to the executing user
110
fprintf(stderr, "%s", strerror(errno));
115
* User has specified the list of control group and
118
for (i = 0; i < CG_HIER_MAX; i++) {
122
ret = cgroup_change_cgroup_path(cgroup_list[i]->path,
124
cgroup_list[i]->controllers);
127
"cgroup change of group failed\n");
133
/* Change the cgroup by determining the rules based on uid */
134
ret = cgroup_change_cgroup_flags(uid, gid,
135
argv[optind], pid, 0);
137
fprintf(stderr, "cgroup change of group failed\n");
142
/* Now exec the new process */
143
ret = execvp(argv[optind], &argv[optind]);
145
fprintf(stderr, "%s", strerror(errno));