summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cryptsetup/cryptsetup-generator.c4
-rw-r--r--src/cryptsetup/cryptsetup.c2
-rw-r--r--src/fstab-generator/fstab-generator.c21
-rw-r--r--src/shared/fstab-util.h14
-rw-r--r--src/test/test-fstab-util.c9
5 files changed, 35 insertions, 15 deletions
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 3657890df4..27b2360d24 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -67,8 +67,8 @@ static int create_disk(
assert(name);
assert(device);
- noauto = fstab_test_option(options, "noauto\0");
- nofail = fstab_test_option(options, "nofail\0");
+ noauto = fstab_test_yes_no_option(options, "noauto\0" "auto\0");
+ nofail = fstab_test_yes_no_option(options, "nofail\0" "fail\0");
tmp = fstab_test_option(options, "tmp\0");
swap = fstab_test_option(options, "swap\0");
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 15dea7b65b..e6b37acb86 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -69,7 +69,7 @@ static int parse_one_option(const char *option) {
assert(option);
/* Handled outside of this tool */
- if (streq(option, "noauto") || streq(option, "nofail"))
+ if (STR_IN_SET(option, "noauto", "auto", "nofail", "fail"))
return 0;
if (startswith(option, "cipher=")) {
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 64eed49523..bc4c1556ca 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -135,17 +135,15 @@ static int add_swap(
static bool mount_is_network(struct mntent *me) {
assert(me);
- return
- hasmntopt(me, "_netdev") ||
- fstype_is_network(me->mnt_type);
+ return fstab_test_option(me->mnt_opts, "_netdev\0") ||
+ fstype_is_network(me->mnt_type);
}
static bool mount_in_initrd(struct mntent *me) {
assert(me);
- return
- hasmntopt(me, "x-initrd.mount") ||
- streq(me->mnt_dir, "/usr");
+ return fstab_test_option(me->mnt_opts, "x-initrd.mount\0") ||
+ streq(me->mnt_dir, "/usr");
}
static int add_mount(
@@ -344,8 +342,8 @@ static int parse_fstab(bool initrd) {
if (is_path(where))
path_kill_slashes(where);
- noauto = !!hasmntopt(me, "noauto");
- nofail = !!hasmntopt(me, "nofail");
+ noauto = fstab_test_yes_no_option(me->mnt_opts, "noauto\0" "auto\0");
+ nofail = fstab_test_yes_no_option(me->mnt_opts, "nofail\0" "fail\0");
log_debug("Found entry what=%s where=%s type=%s nofail=%s noauto=%s",
what, where, me->mnt_type,
yes_no(noauto), yes_no(nofail));
@@ -356,10 +354,9 @@ static int parse_fstab(bool initrd) {
bool automount;
const char *post;
- automount =
- hasmntopt(me, "comment=systemd.automount") ||
- hasmntopt(me, "x-systemd.automount");
-
+ automount = fstab_test_option(me->mnt_opts,
+ "comment=systemd.automount\0"
+ "x-systemd.automount\0");
if (initrd)
post = SPECIAL_INITRD_FS_TARGET;
else if (mount_in_initrd(me))
diff --git a/src/shared/fstab-util.h b/src/shared/fstab-util.h
index 39ddb71ef4..9f6b32eaf4 100644
--- a/src/shared/fstab-util.h
+++ b/src/shared/fstab-util.h
@@ -23,6 +23,7 @@
#include <stdbool.h>
#include <stddef.h>
+#include "macro.h"
int fstab_filter_options(const char *opts, const char *names,
const char **namefound, char **value, char **filtered);
@@ -32,3 +33,16 @@ static inline bool fstab_test_option(const char *opts, const char *names) {
}
int fstab_find_pri(const char *options, int *ret);
+
+static inline bool fstab_test_yes_no_option(const char *opts, const char *yes_no) {
+ int r;
+ const char *opt;
+
+ /* If first name given is last, return 1.
+ * If second name given is last or neither is found, return 0. */
+
+ r = fstab_filter_options(opts, yes_no, &opt, NULL, NULL);
+ assert(r >= 0);
+
+ return opt == yes_no;
+}
diff --git a/src/test/test-fstab-util.c b/src/test/test-fstab-util.c
index ddf965dde5..284484d656 100644
--- a/src/test/test-fstab-util.c
+++ b/src/test/test-fstab-util.c
@@ -107,6 +107,15 @@ static void test_fstab_filter_options(void) {
do_fstab_filter_options("", "opt\0", 0, NULL, NULL, "");
}
+static void test_fstab_yes_no_option(void) {
+ assert_se(fstab_test_yes_no_option("nofail,fail,nofail", "nofail\0fail\0") == true);
+ assert_se(fstab_test_yes_no_option("nofail,nofail,fail", "nofail\0fail\0") == false);
+ assert_se(fstab_test_yes_no_option("abc,cde,afail", "nofail\0fail\0") == false);
+ assert_se(fstab_test_yes_no_option("nofail,fail=0,nofail=0", "nofail\0fail\0") == true);
+ assert_se(fstab_test_yes_no_option("nofail,nofail=0,fail=0", "nofail\0fail\0") == false);
+}
+
int main(void) {
test_fstab_filter_options();
+ test_fstab_yes_no_option();
}