]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-ns.c
treewide: use log_*_errno whenever %m is in the format string
[thirdparty/systemd.git] / src / test / test-ns.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
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 <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <sys/mount.h>
26 #include <linux/fs.h>
27
28 #include "namespace.h"
29 #include "execute.h"
30 #include "log.h"
31
32 int main(int argc, char *argv[]) {
33 const char * const writable[] = {
34 "/home",
35 NULL
36 };
37
38 const char * const readonly[] = {
39 "/",
40 "/usr",
41 "/boot",
42 NULL
43 };
44
45 const char * const inaccessible[] = {
46 "/home/lennart/projects",
47 NULL
48 };
49
50 int r;
51 char tmp_dir[] = "/tmp/systemd-private-XXXXXX",
52 var_tmp_dir[] = "/var/tmp/systemd-private-XXXXXX";
53
54 assert_se(mkdtemp(tmp_dir));
55 assert_se(mkdtemp(var_tmp_dir));
56
57 r = setup_namespace((char **) writable,
58 (char **) readonly,
59 (char **) inaccessible,
60 tmp_dir,
61 var_tmp_dir,
62 NULL,
63 true,
64 PROTECT_HOME_NO,
65 PROTECT_SYSTEM_NO,
66 0);
67 if (r < 0) {
68 log_error_errno(r, "Failed to setup namespace: %m");
69 return 1;
70 }
71
72 execl("/bin/sh", "/bin/sh", NULL);
73 log_error_errno(errno, "execl(): %m");
74
75 return 1;
76 }