- if (comp_field(buf, mdata->mount_root, 3) == 0 && comp_field(buf, mdata->mount_point, 4) == 0) {
- char *buf2 = strchr(buf, '-');
- if (comp_field(buf2, mdata->fstype, 1) == 0 && comp_field(buf2, mdata->mount_source, 2) == 0) {
- fclose(f);
- fprintf(stderr, "PRESENT\n");
- if (mdata->should_be_present)
- _exit(EXIT_SUCCESS);
- _exit(EXIT_FAILURE);
- }
- }
+ char *buf2;
+
+ /* checking mount_root is tricky since it will be prefixed with
+ * whatever path was the source of the mount in the original
+ * mount namespace. So only verify it when we know that root is
+ * in fact "/".
+ */
+ if (mdata->mount_root && comp_field(buf, mdata->mount_root, 3) != 0)
+ continue;
+
+ if (comp_field(buf, mdata->mount_point, 4) != 0)
+ continue;
+
+ if (!mdata->fstype || !mdata->mount_source)
+ goto on_success;
+
+ buf2 = strchr(buf, '-');
+ if (comp_field(buf2, mdata->fstype, 1) != 0 ||
+ comp_field(buf2, mdata->mount_source, 2) != 0)
+ continue;
+
+ on_success:
+ fclose(f);
+ fprintf(stderr, "PRESENT\n");
+ if (mdata->should_be_present)
+ _exit(EXIT_SUCCESS);
+
+ _exit(EXIT_FAILURE);