test-namespace.c revision 6b46ea73e3b1d8a1e65f58ac04772821bd4a72fb
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Zbigniew Jędrzejewski-Szmek
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <libgen.h>
#include "namespace.h"
#include "util.h"
static void test_tmpdir(const char *id, const char *A, const char *B) {
_cleanup_free_ char *a, *b;
struct stat x, y;
char *c, *d;
assert_se(startswith(a, A));
assert_se(startswith(b, B));
c = strappenda(a, "/tmp");
d = strappenda(b, "/tmp");
}
static void test_netns(void) {
int r, n = 0;
if (geteuid() > 0)
return;
if (pid1 == 0) {
r = setup_netns(s);
assert_se(r >= 0);
_exit(r);
}
if (pid2 == 0) {
r = setup_netns(s);
assert_se(r >= 0);
exit(r);
}
if (pid3 == 0) {
r = setup_netns(s);
assert_se(r >= 0);
exit(r);
}
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(r >= 0);
assert_se(n == 1);
}
char boot_id[SD_ID128_STRING_MAX];
assert_se(x && y);
test_tmpdir("abcd.service", x, y);
z = strjoin("/tmp/systemd-private-", boot_id, "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-", NULL);
zz = strjoin("/var/tmp/systemd-private-", boot_id, "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-", NULL);
test_tmpdir("sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device", z, zz);
test_netns();
return 0;
}