lib/tst_mkfs: Exit with TCONF on missing mkfs.foo
When mkfs.foo is not installed the tst_mkfs() exits the test with TBROK
which is not correct as the return should be TCONF instead.
To make it exit with TCONF we have to:
* Use mkfs.foo directly instead of the deprecated mkfs wrapper
- since the wrapper always exits with 1 in case of any failure
- we do that in the shell test.sh already anyway
* Check for the return value from tst_run_cmd()
- it exits with 255 on ENOENT and with 254 for the rest of the exec
failures
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
diff --git a/lib/tst_mkfs.c b/lib/tst_mkfs.c
index 7d9c924..734cf9b 100644
--- a/lib/tst_mkfs.c
+++ b/lib/tst_mkfs.c
@@ -25,8 +25,9 @@
const char *fs_type, const char *const fs_opts[],
const char *extra_opt)
{
- int i, pos = 3;
- const char *argv[OPTS_MAX] = {"mkfs", "-t", fs_type};
+ int i, pos = 1, ret;
+ char mkfs[64];
+ const char *argv[OPTS_MAX] = {mkfs};
char fs_opts_str[1024] = "";
if (!dev)
@@ -35,6 +36,8 @@
if (!fs_type)
tst_brkm(TBROK, cleanup_fn, "No fs_type specified");
+ snprintf(mkfs, sizeof(mkfs), "mkfs.%s", fs_type);
+
if (fs_opts) {
for (i = 0; fs_opts[i]; i++) {
argv[pos++] = fs_opts[i];
@@ -65,7 +68,18 @@
tst_resm(TINFO, "Formatting %s with %s opts='%s' extra opts='%s'",
dev, fs_type, fs_opts_str, extra_opt ? extra_opt : "");
- tst_run_cmd(cleanup_fn, argv, "/dev/null", NULL, 0);
+ ret = tst_run_cmd(cleanup_fn, argv, "/dev/null", NULL, 1);
+
+ switch (ret) {
+ case 0:
+ break;
+ case 255:
+ tst_brkm(TCONF, cleanup_fn,
+ "%s not found in $PATH", mkfs);
+ default:
+ tst_brkm(TBROK, cleanup_fn,
+ "%s failed with %i", mkfs, ret);
+ }
}
const char *tst_dev_fs_type(void)