mirror of
https://github.com/troglobit/finit.git
synced 2026-10-04 23:04:12 +07:00
Relocate ismnt() and fismnt() to util.c, for sharing with initctl
initctl cannot link with helpers.c, so let's relocate these helper functions to util.c instead. Need them to probe for cgroup support. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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_ */
|
||||
|
||||
/**
|
||||
|
||||
+50
@@ -24,6 +24,7 @@
|
||||
#include "config.h"
|
||||
#include <ctype.h> /* isprint() */
|
||||
#include <errno.h>
|
||||
#include <mntent.h>
|
||||
#include <regex.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user