diff options
author | Mike Gilbert <floppym@gentoo.org> | 2014-04-12 16:07:45 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-04-12 17:23:13 -0400 |
commit | eb66db55fc4b342e4253065886e0cc0419c45a07 (patch) | |
tree | ba9a5862de90e86b3ebeb662a7746cc740618eeb /src/shared | |
parent | b189101727e80a09864c5e5880663ef565467f19 (diff) |
fsck: Search for fsck.type in PATH
Modifies find_binary() to accept NULL in the second argument.
fsck.type lookup logic moved to new fsck_exists() function, with a test.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/generator.c | 12 | ||||
-rw-r--r-- | src/shared/path-util.c | 39 | ||||
-rw-r--r-- | src/shared/path-util.h | 2 |
3 files changed, 31 insertions, 22 deletions
diff --git a/src/shared/generator.c b/src/shared/generator.c index 61103031db..5ac7b5f02f 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -19,6 +19,7 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include <string.h> #include <unistd.h> #include "util.h" @@ -26,6 +27,7 @@ #include "mkdir.h" #include "unit-name.h" #include "generator.h" +#include "path-util.h" int generator_write_fsck_deps( FILE *f, @@ -45,16 +47,12 @@ int generator_write_fsck_deps( } if (!isempty(fstype) && !streq(fstype, "auto")) { - const char *checker; int r; - - checker = strappenda("/sbin/fsck.", fstype); - r = access(checker, X_OK); + r = fsck_exists(fstype); if (r < 0) { - log_warning("Checking was requested for %s, but %s cannot be used: %m", what, checker); - + log_warning("Checking was requested for %s, but fsck.%s cannot be used: %s", what, fstype, strerror(-r)); /* treat missing check as essentially OK */ - return errno == ENOENT ? 0 : -errno; + return r == -ENOENT ? 0 : r; } } diff --git a/src/shared/path-util.c b/src/shared/path-util.c index bdc54a9aa5..1ad1084b2d 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -425,19 +425,20 @@ int path_is_os_tree(const char *path) { int find_binary(const char *name, char **filename) { assert(name); - assert(filename); if (strchr(name, '/')) { - char *p; + if (filename) { + char *p; - if (path_is_absolute(name)) - p = strdup(name); - else - p = path_make_absolute_cwd(name); - if (!p) - return -ENOMEM; + if (path_is_absolute(name)) + p = strdup(name); + else + p = path_make_absolute_cwd(name); + if (!p) + return -ENOMEM; + *filename = p; + } - *filename = p; return 0; } else { const char *path; @@ -453,18 +454,19 @@ int find_binary(const char *name, char **filename) { path = DEFAULT_PATH; FOREACH_WORD_SEPARATOR(w, l, path, ":", state) { - char *p; + _cleanup_free_ char *p = NULL; if (asprintf(&p, "%.*s/%s", (int) l, w, name) < 0) return -ENOMEM; - if (access(p, X_OK) < 0) { - free(p); + if (access(p, X_OK) < 0) continue; - } - path_kill_slashes(p); - *filename = p; + if (filename) { + path_kill_slashes(p); + *filename = p; + p = NULL; + } return 0; } @@ -507,3 +509,10 @@ bool paths_check_timestamp(const char* const* paths, usec_t *timestamp, bool upd return changed; } + +int fsck_exists(const char *fstype) { + const char *checker; + + checker = strappenda("fsck.", fstype); + return find_binary(checker, NULL); +} diff --git a/src/shared/path-util.h b/src/shared/path-util.h index 2b8ea0260e..fdf1f6b000 100644 --- a/src/shared/path-util.h +++ b/src/shared/path-util.h @@ -57,6 +57,8 @@ int find_binary(const char *name, char **filename); bool paths_check_timestamp(const char* const* paths, usec_t *paths_ts_usec, bool update); +int fsck_exists(const char *fstype); + /* Iterates through the path prefixes of the specified path, going up * the tree, to root. Also returns "" (and not "/"!) for the root * directory. Excludes the specified directory itself */ |