cgpath.c revision ae5c8b8ed5feb9a47c5007c986ce01ea39b5075f
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen * Copyright � 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
739125f23e3312045e620014812fe2249a309cc4Timo Sirainen * Copyright � 2012 Canonical Ltd.
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen * This program is free software; you can redistribute it and/or modify
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen * it under the terms of the GNU General Public License version 2, as
98c2cac72e2032f223050a4edd229993c1d5c1f0Aki Tuomi * published by the Free Software Foundation.
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen * This program is distributed in the hope that it will be useful,
3faa1040e5a3f9f35ffad29110216094ab2f5880Timo Sirainen * but WITHOUT ANY WARRANTY; without even the implied warranty of
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b4d850a0ffd519c1c745557568daf7d48e18c820Timo Sirainen * GNU General Public License for more details.
b4d850a0ffd519c1c745557568daf7d48e18c820Timo Sirainen * You should have received a copy of the GNU General Public License along
cb999a76f51081a4c5d7f7ac411de3fe6cff6c15Timo Sirainen * with this program; if not, write to the Free Software Foundation, Inc.,
cb999a76f51081a4c5d7f7ac411de3fe6cff6c15Timo Sirainen * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
af4cf954021adac7e021262bf6ae3cc3cec3ba54Timo Sirainen#define TSTERR(x) do { \
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen /* won't require privilege necessarily once users are classified by
20905b89a05e27f0d1c6606a6b49b33dc23a1323Timo Sirainen * pam_cgroup */
20905b89a05e27f0d1c6606a6b49b33dc23a1323Timo Sirainen if (geteuid() != 0) {
ba1c847d0af4afe4787ed470d0c818e948e184e2Timo Sirainen TSTERR("zero result from lxc_cgroup_path_create");
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen TSTERR("lxc_cgroup_path_create NULL lxctest1");
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen TSTERR("zero result from lxc_cgroup_path_create");
ba1c847d0af4afe4787ed470d0c818e948e184e2Timo Sirainen if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
9f7ba3807f77209a65e0faa56cac8545b06cd116Aki Tuomi c->set_config_item(c, "lxc.network.type", "empty");
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen printf("first container passed. Now two containers...\n");
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = lxc_cgroup_path_get(&nsgroup, "freezer", MYNAME, c->get_config_path(c));
3faa1040e5a3f9f35ffad29110216094ab2f5880Timo Sirainen if (ret < 0 || !strstr(nsgroup, "lxc/" MYNAME)) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen TSTERR("getting first cgroup path from lxc_command");
b4d850a0ffd519c1c745557568daf7d48e18c820Timo Sirainen /* start second container */
b4d850a0ffd519c1c745557568daf7d48e18c820Timo Sirainen if ((c2 = lxc_container_new(MYNAME2, ALTBASE)) == NULL) {
b4d850a0ffd519c1c745557568daf7d48e18c820Timo Sirainen c2->set_config_item(c2, "lxc.network.type", "empty");
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = lxc_cgroup_path_get(&nsgroup, "freezer", MYNAME2, c2->get_config_path(c2));
095481fee84040436ce2dccca472c9bb1df4d5bbTimo Sirainen if (ret < 0 || !strstr(nsgroup, "lxc/" MYNAME2)) {
71b60849a773dd68bdc015cb6a8ea1664d16b359Timo Sirainen TSTERR("getting second cgroup path from lxc_command");
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (lxc_get_cgpath(&dirpath, NULL, c2->name, c2->config_path) < 0) {