Lines 22-27
Link Here
|
22 |
#include <ftw.h> |
22 |
#include <ftw.h> |
23 |
#include <stdlib.h> |
23 |
#include <stdlib.h> |
24 |
#include <sys/mount.h> |
24 |
#include <sys/mount.h> |
|
|
25 |
#include <sys/statvfs.h> |
25 |
#include <unistd.h> |
26 |
#include <unistd.h> |
26 |
|
27 |
|
27 |
#include "alloc-util.h" |
28 |
#include "alloc-util.h" |
Lines 387-392
static int nftw_cb(
Link Here
|
387 |
|
388 |
|
388 |
return FTW_CONTINUE; |
389 |
return FTW_CONTINUE; |
389 |
}; |
390 |
}; |
|
|
391 |
|
392 |
static int relabel_cgroup_filesystems(void) { |
393 |
int r; |
394 |
struct statfs st; |
395 |
|
396 |
r = cg_all_unified(); |
397 |
if (r == 0) { |
398 |
/* Temporarily remount the root cgroup filesystem to give it a proper label. Do this |
399 |
only when the filesystem has been already populated by a previous instance of systemd |
400 |
running from initrd. Otherwise don't remount anything and leave the filesystem read-write |
401 |
for the cgroup filesystems to be mounted inside. */ |
402 |
r = statfs("/sys/fs/cgroup", &st); |
403 |
if (r < 0) { |
404 |
return log_error_errno(errno, "Failed to determine mount flags for /sys/fs/cgroup: %m"); |
405 |
} |
406 |
|
407 |
if (st.f_flags & ST_RDONLY) |
408 |
(void) mount(NULL, "/sys/fs/cgroup", NULL, MS_REMOUNT, NULL); |
409 |
|
410 |
(void) label_fix("/sys/fs/cgroup", false, false); |
411 |
nftw("/sys/fs/cgroup", nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL); |
412 |
|
413 |
if (st.f_flags & ST_RDONLY) |
414 |
(void) mount(NULL, "/sys/fs/cgroup", NULL, MS_REMOUNT|MS_RDONLY, NULL); |
415 |
} else if (r < 0) |
416 |
return log_error_errno(r, "Failed to determine whether we are in all unified mode: %m"); |
417 |
|
418 |
return 0; |
419 |
} |
390 |
#endif |
420 |
#endif |
391 |
|
421 |
|
392 |
int mount_setup(bool loaded_policy) { |
422 |
int mount_setup(bool loaded_policy) { |
Lines 411-425
int mount_setup(bool loaded_policy) {
Link Here
|
411 |
nftw("/dev/shm", nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL); |
441 |
nftw("/dev/shm", nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL); |
412 |
nftw("/run", nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL); |
442 |
nftw("/run", nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL); |
413 |
|
443 |
|
414 |
/* Temporarily remount the root cgroup filesystem to give it a proper label. */ |
444 |
r = relabel_cgroup_filesystems(); |
415 |
r = cg_all_unified(); |
445 |
if (r < 0) |
416 |
if (r == 0) { |
446 |
return r; |
417 |
(void) mount(NULL, "/sys/fs/cgroup", NULL, MS_REMOUNT, NULL); |
|
|
418 |
label_fix("/sys/fs/cgroup", false, false); |
419 |
nftw("/sys/fs/cgroup", nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL); |
420 |
(void) mount(NULL, "/sys/fs/cgroup", NULL, MS_REMOUNT|MS_RDONLY, NULL); |
421 |
} else if (r < 0) |
422 |
return log_error_errno(r, "Failed to determine whether we are in all unified mode: %m"); |
423 |
|
447 |
|
424 |
after_relabel = now(CLOCK_MONOTONIC); |
448 |
after_relabel = now(CLOCK_MONOTONIC); |
425 |
|
449 |
|