summaryrefslogtreecommitdiff
path: root/src/core/mount.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-01-09 16:58:29 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-01-11 23:41:41 -0500
commitd15d0333be6a1ca7fdd99a1881d967b6be8f387a (patch)
tree488ce214314613658c5eda3b0a94deec31353de7 /src/core/mount.c
parent1e39ff926f815d241721ed9486945cf599ef8c2f (diff)
Add new function to filter fstab options
This fixes parsing of options in shared/generator.c. Existing code had some issues: - it would treate whitespace and semicolons as seperators. fstab(5) is pretty clear that only commas matter. And the syntax does not allow for spaces to be inserted in the field in fstab. Whitespace might be escaped, but then it should not seperate options. Treat whitespace and semicolons as any other character. - it assumed that x-systemd.device-timeout would always be followed by "=". But this is not guaranteed, hasmntopt will return this option even if there's no value. Uninitialized memory could be read. - some error paths would log, and inconsistently, some would just return an error code. Filtering is split out to a separate function and tests are added. Similar code paths in other places are adjusted to use the new function.
Diffstat (limited to 'src/core/mount.c')
-rw-r--r--src/core/mount.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/core/mount.c b/src/core/mount.c
index 13c634807b..a551235f13 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -44,6 +44,7 @@
#include "bus-common-errors.h"
#include "exit-status.h"
#include "def.h"
+#include "fstab-util.h"
#define RETRY_UMOUNT_MAX 32
@@ -70,7 +71,7 @@ static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *user
static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
static bool mount_needs_network(const char *options, const char *fstype) {
- if (mount_test_option(options, "_netdev"))
+ if (fstab_test_option(options, "_netdev\0"))
return true;
if (fstype && fstype_is_network(fstype))
@@ -88,16 +89,10 @@ static bool mount_is_network(const MountParameters *p) {
static bool mount_is_bind(const MountParameters *p) {
assert(p);
- if (mount_test_option(p->options, "bind"))
+ if (fstab_test_option(p->options, "bind\0" "rbind\0"))
return true;
- if (p->fstype && streq(p->fstype, "bind"))
- return true;
-
- if (mount_test_option(p->options, "rbind"))
- return true;
-
- if (p->fstype && streq(p->fstype, "rbind"))
+ if (p->fstype && STR_IN_SET(p->fstype, "bind", "rbind"))
return true;
return false;
@@ -106,7 +101,7 @@ static bool mount_is_bind(const MountParameters *p) {
static bool mount_is_auto(const MountParameters *p) {
assert(p);
- return !mount_test_option(p->options, "noauto");
+ return !fstab_test_option(p->options, "noauto\0");
}
static bool needs_quota(const MountParameters *p) {
@@ -118,11 +113,8 @@ static bool needs_quota(const MountParameters *p) {
if (mount_is_bind(p))
return false;
- return mount_test_option(p->options, "usrquota") ||
- mount_test_option(p->options, "grpquota") ||
- mount_test_option(p->options, "quota") ||
- mount_test_option(p->options, "usrjquota") ||
- mount_test_option(p->options, "grpjquota");
+ return fstab_test_option(p->options,
+ "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
}
static void mount_init(Unit *u) {
@@ -369,7 +361,7 @@ static bool should_umount(Mount *m) {
return false;
p = get_mount_parameters(m);
- if (p && mount_test_option(p->options, "x-initrd.mount") &&
+ if (p && fstab_test_option(p->options, "x-initrd.mount\0") &&
!in_initrd())
return false;