diff --git a/plugins/modprobe.c b/plugins/modprobe.c index fdfcb815..cb4b0ccb 100644 --- a/plugins/modprobe.c +++ b/plugins/modprobe.c @@ -48,7 +48,7 @@ #include "config.h" #include "finit.h" -#include "helpers.h" +#include "util.h" #include "plugin.h" struct module { diff --git a/src/helpers.c b/src/helpers.c index 78b32d53..4acd7bdb 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -564,55 +564,6 @@ void endfsent(void) } #endif /* HAVE_GETFSENT */ -static int hasopt(char *opts, char *opt) -{ - char buf[strlen(opts) + 1]; - char *ptr; - - memcpy(buf, opts, sizeof(buf)); - ptr = strtok(buf, ","); - while (ptr) { - if (!strcmp(ptr, opt)) - return 1; - - ptr = strtok(NULL, ","); - } - - return 0; -} - -int ismnt(char *file, char *dir, char *mode) -{ - struct mntent *mnt; - int found = 0; - FILE *fp; - - fp = setmntent(file, "r"); - if (!fp) - return 0; /* Dunno, maybe not */ - - while ((mnt = getmntent(fp))) { - if (!strcmp(mnt->mnt_dir, dir)) { - if (mode) { - if (hasopt(mnt->mnt_opts, mode)) - found = 1; - } else - found = 1; - - break; - } - } - endmntent(fp); - - return found; -} - -/* Requires /proc to be mounted */ -int fismnt(char *dir) -{ - return ismnt("/proc/mounts", dir, NULL); -} - /** * Local Variables: * indent-tabs-mode: t diff --git a/src/helpers.h b/src/helpers.h index 83840463..07b70d02 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -130,9 +130,6 @@ static inline int dprint(int fd, const char *s, size_t len) return rc; } -int ismnt (char *file, char *dir, char *mode); -int fismnt (char *dir); - #endif /* FINIT_HELPERS_H_ */ /** diff --git a/src/util.c b/src/util.c index 28f4c921..f612a981 100644 --- a/src/util.c +++ b/src/util.c @@ -24,6 +24,7 @@ #include "config.h" #include /* isprint() */ #include +#include #include #include #include @@ -398,6 +399,55 @@ char *sanitize(char *arg, size_t len) return arg; } +static int hasopt(char *opts, char *opt) +{ + char buf[strlen(opts) + 1]; + char *ptr; + + memcpy(buf, opts, sizeof(buf)); + ptr = strtok(buf, ","); + while (ptr) { + if (!strcmp(ptr, opt)) + return 1; + + ptr = strtok(NULL, ","); + } + + return 0; +} + +int ismnt(char *file, char *dir, char *mode) +{ + struct mntent *mnt; + int found = 0; + FILE *fp; + + fp = setmntent(file, "r"); + if (!fp) + return 0; /* Dunno, maybe not */ + + while ((mnt = getmntent(fp))) { + if (!strcmp(mnt->mnt_dir, dir)) { + if (mode) { + if (hasopt(mnt->mnt_opts, mode)) + found = 1; + } else + found = 1; + + break; + } + } + endmntent(fp); + + return found; +} + +/* Requires /proc to be mounted */ +int fismnt(char *dir) +{ + return ismnt("/proc/mounts", dir, NULL); +} + #ifdef HAVE_TERMIOS_H /* * Called by initctl, and by finit at boot and shutdown, to diff --git a/src/util.h b/src/util.h index a6826f00..a65b2aad 100644 --- a/src/util.h +++ b/src/util.h @@ -70,6 +70,9 @@ char *memsz (uint64_t sz, char *buf, size_t len); char *sanitize (char *arg, size_t len); +int ismnt (char *file, char *dir, char *mode); +int fismnt (char *dir); + #ifdef HAVE_TERMIOS_H int ttinit (void); int ttraw (void);