FILE *procmnt;
struct mntent mntent;
char mntbuf[1024];
- int ret = -1;
- char **mounts = NULL;
+ g_auto(GStrv) mounts = NULL;
size_t nmounts = 0;
size_t i;
VIR_APPEND_ELEMENT(mounts, nmounts, tmp);
}
- if (!mounts) {
- ret = 0;
- goto cleanup;
- }
+ endmntent(procmnt);
+
+ if (!mounts)
+ return 0;
+
+ qsort(mounts, nmounts, sizeof(mounts[0]), virStringSortRevCompare);
- qsort(mounts, nmounts, sizeof(mounts[0]),
- virStringSortRevCompare);
+ /* turn 'mounts' into a proper GStrv */
+ VIR_EXPAND_N(mounts, nmounts, 1);
+ nmounts--;
for (i = 0; i < nmounts; i++) {
VIR_DEBUG("Bind readonly %s", mounts[i]);
virReportSystemError(errno,
_("Failed to make mount %s readonly"),
mounts[i]);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
- cleanup:
- virStringListFreeCount(mounts, nmounts);
- endmntent(procmnt);
- return ret;
-
+ return 0;
}