]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-namespace.c
systemd: use unit name in PrivateTmp directories
[thirdparty/systemd.git] / src / test / test-namespace.c
CommitLineData
d8c9d3a4
ZJS
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Zbigniew Jędrzejewski-Szmek
7
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.
12
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.
17
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/>.
20***/
21
22#include <libgen.h>
23
24#include "namespace.h"
25#include "util.h"
26
27static void test_tmpdir(const char *id, const char *A, const char *B) {
28 _cleanup_free_ char *a, *b;
29
30 assert_se(setup_tmpdirs(id, &a, &b) == 0);
31 assert(startswith(a, A));
32 assert(startswith(b, B));
33 assert(access(a, F_OK) == 0);
34 assert(access(b, F_OK) == 0);
35
36 assert_se(rmdir(a) == 0);
37 assert_se(rmdir(b) == 0);
38
39 assert(endswith(a, "/tmp"));
40 assert(endswith(b, "/tmp"));
41
42 assert_se(rmdir(dirname(a)) == 0);
43 assert_se(rmdir(dirname(b)) == 0);
44}
45
46int main(int argc, char *argv[]) {
47 test_tmpdir("abcd.service",
48 "/tmp/systemd-abcd.service-",
49 "/var/tmp/systemd-abcd.service-");
50
51 test_tmpdir("sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device",
52 "/tmp/systemd-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-",
53 "/var/tmp/systemd-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
54
55 return 0;
56}