1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 01:27:11 +03:00

fstab-util: fix priority parsing and add test

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2015-01-11 23:40:46 -05:00
parent 7f76961982
commit a75f4e2a02
2 changed files with 21 additions and 2 deletions

View File

@ -133,8 +133,10 @@ int fstab_find_pri(const char *options, int *ret) {
assert(ret); assert(ret);
r = fstab_filter_options(options, "pri\0", NULL, &opt, NULL); r = fstab_filter_options(options, "pri\0", NULL, &opt, NULL);
if (r <= 0) if (r < 0)
return r; return r;
if (r == 0 || !opt)
return 0;
r = safe_atou(opt, &pri); r = safe_atou(opt, &pri);
if (r < 0) if (r < 0)
@ -143,6 +145,6 @@ int fstab_find_pri(const char *options, int *ret) {
if ((int) pri < 0) if ((int) pri < 0)
return -ERANGE; return -ERANGE;
*ret = (int) r; *ret = (int) pri;
return 1; return 1;
} }

View File

@ -107,6 +107,22 @@ static void test_fstab_filter_options(void) {
do_fstab_filter_options("", "opt\0", 0, NULL, NULL, ""); do_fstab_filter_options("", "opt\0", 0, NULL, NULL, "");
} }
static void test_fstab_find_pri(void) {
int pri = -1;
assert_se(fstab_find_pri("pri", &pri) == 0);
assert_se(pri == -1);
assert_se(fstab_find_pri("pri=11", &pri) == 1);
assert_se(pri == 11);
assert_se(fstab_find_pri("opt,pri=12,opt", &pri) == 1);
assert_se(pri == 12);
assert_se(fstab_find_pri("opt,opt,pri=12,pri=13", &pri) == 1);
assert_se(pri == 13);
}
static void test_fstab_yes_no_option(void) { 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,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("nofail,nofail,fail", "nofail\0fail\0") == false);
@ -117,5 +133,6 @@ static void test_fstab_yes_no_option(void) {
int main(void) { int main(void) {
test_fstab_filter_options(); test_fstab_filter_options();
test_fstab_find_pri();
test_fstab_yes_no_option(); test_fstab_yes_no_option();
} }