]>
git.ipfire.org Git - thirdparty/systemd.git/blob - mount-setup.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 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 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/mount.h>
30 #include "mount-setup.h"
35 typedef struct MountPoint
{
44 static const MountPoint mount_table
[] = {
45 { "proc", "/proc", "proc", NULL
, MS_NOSUID
|MS_NOEXEC
|MS_NODEV
, true },
46 { "sysfs", "/sys", "sysfs", NULL
, MS_NOSUID
|MS_NOEXEC
|MS_NODEV
, true },
47 { "devtmps", "/dev", "devtmpfs", "mode=755", MS_NOSUID
, true },
48 { "tmpfs", "/dev/shm", "tmpfs", "mode=1777", MS_NOSUID
|MS_NOEXEC
|MS_NODEV
, true },
49 { "devpts", "/dev/pts", "devpts", NULL
, MS_NOSUID
|MS_NOEXEC
|MS_NODEV
, false },
50 { "cgroup", "/cgroup/debug", "cgroup", "debug", MS_NOSUID
|MS_NOEXEC
|MS_NODEV
, true },
51 { "debugfs", "/sys/kernel/debug", "debugfs", NULL
, MS_NOSUID
|MS_NOEXEC
|MS_NODEV
, false }
54 bool mount_point_is_api(const char *path
) {
57 /* Checks if this mount point is considered "API", and hence
58 * should be ignored */
60 for (i
= 0; i
< ELEMENTSOF(mount_table
); i
++)
61 if (path_startswith(path
, mount_table
[i
].where
))
67 static int mount_one(const MountPoint
*p
) {
72 if ((r
= path_is_mount_point(p
->where
)) < 0)
78 /* The access mode here doesn't really matter too much, since
79 * the mounted file system will take precedence anyway. */
80 mkdir_p(p
->where
, 0755);
82 log_debug("Mounting %s to %s of type %s with options %s.",
93 log_error("Failed to mount %s: %s", p
->where
, strerror(errno
));
94 return p
->fatal
? -errno
: 0;
100 static int mount_cgroup_controllers(void) {
105 /* Mount all available cgroup controllers. */
107 if (!(f
= fopen("/proc/cgroups", "re")))
110 /* Ignore the header line */
111 fgets(buf
, sizeof(buf
), f
);
115 char *controller
, *where
;
117 if (fscanf(f
, "%ms %*i %*i %*i", &controller
) != 1) {
122 log_error("Failed to parse /proc/cgroups.");
127 if (asprintf(&where
, "/cgroup/%s", controller
) < 0) {
137 p
.options
= controller
;
138 p
.flags
= MS_NOSUID
|MS_NOEXEC
|MS_NODEV
;
157 int mount_setup(void) {
161 for (i
= 0; i
< ELEMENTSOF(mount_table
); i
++)
162 if ((r
= mount_one(mount_table
+i
)) < 0)
165 return mount_cgroup_controllers();