mirror of
https://github.com/systemd/systemd.git
synced 2026-07-17 04:50:47 +00:00
Merge pull request #7908 from yuwata/rfe-7895
core: add TemporaryFileSystem= setting and 'tmpfs' option to ProtectHome=
This commit is contained in:
@@ -317,6 +317,7 @@ libbasic = static_library(
|
||||
dependencies : [threads,
|
||||
libcap,
|
||||
libblkid,
|
||||
libmount,
|
||||
libselinux],
|
||||
c_args : ['-fvisibility=default'],
|
||||
install : false)
|
||||
|
||||
@@ -27,8 +27,12 @@
|
||||
#include <sys/statvfs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Include later */
|
||||
#include <libmount.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "escape.h"
|
||||
#include "extract-word.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
@@ -810,29 +814,37 @@ int mount_verbose(
|
||||
unsigned long flags,
|
||||
const char *options) {
|
||||
|
||||
_cleanup_free_ char *fl = NULL;
|
||||
_cleanup_free_ char *fl = NULL, *o = NULL;
|
||||
unsigned long f;
|
||||
int r;
|
||||
|
||||
fl = mount_flags_to_string(flags);
|
||||
r = mount_option_mangle(options, flags, &f, &o);
|
||||
if (r < 0)
|
||||
return log_full_errno(error_log_level, r,
|
||||
"Failed to mangle mount options %s: %m",
|
||||
strempty(options));
|
||||
|
||||
if ((flags & MS_REMOUNT) && !what && !type)
|
||||
fl = mount_flags_to_string(f);
|
||||
|
||||
if ((f & MS_REMOUNT) && !what && !type)
|
||||
log_debug("Remounting %s (%s \"%s\")...",
|
||||
where, strnull(fl), strempty(options));
|
||||
where, strnull(fl), strempty(o));
|
||||
else if (!what && !type)
|
||||
log_debug("Mounting %s (%s \"%s\")...",
|
||||
where, strnull(fl), strempty(options));
|
||||
else if ((flags & MS_BIND) && !type)
|
||||
where, strnull(fl), strempty(o));
|
||||
else if ((f & MS_BIND) && !type)
|
||||
log_debug("Bind-mounting %s on %s (%s \"%s\")...",
|
||||
what, where, strnull(fl), strempty(options));
|
||||
else if (flags & MS_MOVE)
|
||||
what, where, strnull(fl), strempty(o));
|
||||
else if (f & MS_MOVE)
|
||||
log_debug("Moving mount %s → %s (%s \"%s\")...",
|
||||
what, where, strnull(fl), strempty(options));
|
||||
what, where, strnull(fl), strempty(o));
|
||||
else
|
||||
log_debug("Mounting %s on %s (%s \"%s\")...",
|
||||
strna(type), where, strnull(fl), strempty(options));
|
||||
if (mount(what, where, type, flags, options) < 0)
|
||||
strna(type), where, strnull(fl), strempty(o));
|
||||
if (mount(what, where, type, f, o) < 0)
|
||||
return log_full_errno(error_log_level, errno,
|
||||
"Failed to mount %s on %s (%s \"%s\"): %m",
|
||||
strna(type), where, strnull(fl), strempty(options));
|
||||
strna(type), where, strnull(fl), strempty(o));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -874,3 +886,73 @@ int mount_propagation_flags_from_string(const char *name, unsigned long *ret) {
|
||||
return -EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mount_option_mangle(
|
||||
const char *options,
|
||||
unsigned long mount_flags,
|
||||
unsigned long *ret_mount_flags,
|
||||
char **ret_remaining_options) {
|
||||
|
||||
const struct libmnt_optmap *map;
|
||||
_cleanup_free_ char *ret = NULL;
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
/* This extracts mount flags from the mount options, and store
|
||||
* non-mount-flag options to '*ret_remaining_options'.
|
||||
* E.g.,
|
||||
* "rw,nosuid,nodev,relatime,size=1630748k,mode=700,uid=1000,gid=1000"
|
||||
* is split to MS_NOSUID|MS_NODEV|MS_RELATIME and
|
||||
* "size=1630748k,mode=700,uid=1000,gid=1000".
|
||||
* See more examples in test-mount-utils.c.
|
||||
*
|
||||
* Note that if 'options' does not contain any non-mount-flag options,
|
||||
* then '*ret_remaining_options' is set to NULL instread of empty string.
|
||||
* Note that this does not check validity of options stored in
|
||||
* '*ret_remaining_options'.
|
||||
* Note that if 'options' is NULL, then this just copies 'mount_flags'
|
||||
* to '*ret_mount_flags'. */
|
||||
|
||||
assert(ret_mount_flags);
|
||||
assert(ret_remaining_options);
|
||||
|
||||
map = mnt_get_builtin_optmap(MNT_LINUX_MAP);
|
||||
if (!map)
|
||||
return -EINVAL;
|
||||
|
||||
p = options;
|
||||
for (;;) {
|
||||
_cleanup_free_ char *word = NULL;
|
||||
const struct libmnt_optmap *ent;
|
||||
|
||||
r = extract_first_word(&p, &word, ",", EXTRACT_QUOTES);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
for (ent = map; ent->name; ent++) {
|
||||
/* All entries in MNT_LINUX_MAP do not take any argument.
|
||||
* Thus, ent->name does not contain "=" or "[=]". */
|
||||
if (!streq(word, ent->name))
|
||||
continue;
|
||||
|
||||
if (!(ent->mask & MNT_INVERT))
|
||||
mount_flags |= ent->id;
|
||||
else if (mount_flags & ent->id)
|
||||
mount_flags ^= ent->id;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
/* If 'word' is not a mount flag, then store it in '*ret_remaining_options'. */
|
||||
if (!ent->name && !strextend_with_separator(&ret, ",", word, NULL))
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*ret_mount_flags = mount_flags;
|
||||
*ret_remaining_options = ret;
|
||||
ret = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -67,3 +67,9 @@ int umount_verbose(const char *where);
|
||||
|
||||
const char *mount_propagation_flags_to_string(unsigned long flags);
|
||||
int mount_propagation_flags_from_string(const char *name, unsigned long *ret);
|
||||
|
||||
int mount_option_mangle(
|
||||
const char *options,
|
||||
unsigned long mount_flags,
|
||||
unsigned long *ret_mount_flags,
|
||||
char **ret_remaining_options);
|
||||
|
||||
Reference in New Issue
Block a user