From ac528367815bb48b9d1385d25e5fbf2d32d3020c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 19 Feb 2018 13:05:45 +0100 Subject: fsck: cleanup find_fsck() * remove static variable * return 0 or 1 * optionally return allocated path to the program Signed-off-by: Karel Zak --- disk-utils/fsck.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'disk-utils') diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c index 354f1309d..3afc88600 100644 --- a/disk-utils/fsck.c +++ b/disk-utils/fsck.c @@ -540,12 +540,13 @@ static struct libmnt_fs *lookup(char *path) } /* Find fsck program for a given fs type. */ -static char *find_fsck(const char *type) +static int find_fsck(const char *type, char **progpath) { char *s; const char *tpl; - static char *prog = NULL; + char *prog = NULL; char *p = xstrdup(fsck_path); + int rc; /* Are we looking for a program or just a type? */ tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s"); @@ -559,7 +560,14 @@ static char *find_fsck(const char *type) } free(p); - return prog; + rc = prog ? 1 : 0; + + if (progpath) + *progpath = prog; + else + free(prog); + + return rc; } static int progress_active(void) @@ -905,8 +913,8 @@ static int fsck_device(struct libmnt_fs *fs, int interactive) type = DEFAULT_FSTYPE; xasprintf(&progname, "fsck.%s", type); - progpath = find_fsck(progname); - if (progpath == NULL) { + + if (!find_fsck(progname, &progpath)) { free(progname); if (fs_check_required(type)) { retval = ENOENT; @@ -1153,7 +1161,7 @@ static int ignore(struct libmnt_fs *fs) /* See if the program is available. */ - if (find_fsck(type) == NULL) { + if (!find_fsck(type, NULL)) { if (fs_check_required(type)) warnx(_("cannot check %s: fsck.%s not found"), fs_get_device(fs), type); -- cgit v1.2.3-55-g7522