1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Zbigniew Jędrzejewski-Szmek
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/socket.h>
25 #include "namespace.h"
28 static void test_tmpdir(const char *id, const char *A, const char *B) {
29 _cleanup_free_ char *a, *b;
33 assert_se(setup_tmp_dirs(id, &a, &b) == 0);
34 assert_se(startswith(a, A));
35 assert_se(startswith(b, B));
37 assert_se(stat(a, &x) >= 0);
38 assert_se(stat(b, &y) >= 0);
40 assert_se(S_ISDIR(x.st_mode));
41 assert_se(S_ISDIR(y.st_mode));
43 assert_se((x.st_mode & 01777) == 0700);
44 assert_se((y.st_mode & 01777) == 0700);
46 c = strappenda(a, "/tmp");
47 d = strappenda(b, "/tmp");
49 assert_se(stat(c, &x) >= 0);
50 assert_se(stat(d, &y) >= 0);
52 assert_se(S_ISDIR(x.st_mode));
53 assert_se(S_ISDIR(y.st_mode));
55 assert_se((x.st_mode & 01777) == 01777);
56 assert_se((y.st_mode & 01777) == 01777);
58 assert_se(rmdir(c) >= 0);
59 assert_se(rmdir(d) >= 0);
61 assert_se(rmdir(a) >= 0);
62 assert_se(rmdir(b) >= 0);
65 static void test_netns(void) {
66 _cleanup_close_pipe_ int s[2] = { -1, -1 };
67 pid_t pid1, pid2, pid3;
74 assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, s) >= 0);
103 r = wait_for_terminate(pid1, &si);
105 assert_se(si.si_code == CLD_EXITED);
108 r = wait_for_terminate(pid2, &si);
110 assert_se(si.si_code == CLD_EXITED);
113 r = wait_for_terminate(pid3, &si);
115 assert_se(si.si_code == CLD_EXITED);
121 int main(int argc, char *argv[]) {
122 test_tmpdir("abcd.service",
123 "/tmp/systemd-abcd.service-",
124 "/var/tmp/systemd-abcd.service-");
126 test_tmpdir("sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device",
127 "/tmp/systemd-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-",
128 "/var/tmp/systemd-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");