hug getopt_long some more
This commit is contained in:
parent
6dde29a0c9
commit
876bd89f4b
@ -22,7 +22,7 @@ do_mtab() {
|
||||
local mnt= mnts="$(mountinfo | sed -e "s/^/'/g" -e "s/$/'/g")"
|
||||
eval set -- ${mnts}
|
||||
for mnt in "$@" ; do
|
||||
if fstabinfo --mount-cmd "${mnt}" >/dev/null ; then
|
||||
if fstabinfo --mountcmd "${mnt}" >/dev/null ; then
|
||||
mount -f -o remount "${mnt}"
|
||||
fi
|
||||
done
|
||||
|
@ -31,7 +31,7 @@ single_user() {
|
||||
mount_svcdir() {
|
||||
local fs= fsopts="-o rw,noexec,nodev,nosuid" devdir="none" devtmp="none" x=
|
||||
local svcsize=${svcsize:-1024}
|
||||
local mntcmd=$(fstabinfo --mount-cmd "${RC_LIBDIR}")
|
||||
local mntcmd=$(fstabinfo --mountcmd "${RC_LIBDIR}")
|
||||
|
||||
if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems ; then
|
||||
fs="tmpfs"
|
||||
@ -117,7 +117,7 @@ if [ ! -e /proc/self/stat ] ; then
|
||||
procfs="proc"
|
||||
[ "${RC_UNAME}" = "GNU/kFreeBSD" ] && proc="linprocfs"
|
||||
ebegin "Mounting ${procfs} at /proc"
|
||||
mntcmd="$(fstabinfo --mount-cmd /proc)"
|
||||
mntcmd="$(fstabinfo --mountcmd /proc)"
|
||||
try mount -n ${mntcmd:--t ${procfs} -o noexec,nosuid,nodev proc /proc}
|
||||
eend $?
|
||||
fi
|
||||
@ -136,7 +136,7 @@ K26=$?
|
||||
if [ "${RC_UNAME}" != "GNU/kFreeBSD" -a "${RC_NAME}" != "VPS" -a "${K26}" = "0" ] ; then
|
||||
if [ -d /sys ] ; then
|
||||
ebegin "Mounting sysfs at /sys"
|
||||
mntcmd="$(fstabinfo --mount-cmd /sys)"
|
||||
mntcmd="$(fstabinfo --mountcmd /sys)"
|
||||
try mount -n ${mntcmd:--t sysfs -o noexec,nosuid,nodev sysfs /sys}
|
||||
eend $?
|
||||
else
|
||||
@ -231,7 +231,7 @@ if [ "${RC_UNAME}" != "GNU/kFreeBSD" -a "${K26}" = "0" ] ; then
|
||||
|
||||
if [ -d /dev/pts ] ; then
|
||||
ebegin "Mounting devpts at /dev/pts"
|
||||
mntcmd="$(fstabinfo --mount-cmd /dev/pts)"
|
||||
mntcmd="$(fstabinfo --mountcmd /dev/pts)"
|
||||
try mount -n ${mntcmd:--t devpts -o gid=5,mode=0620,noexec,nosuid devpts /dev/pts}
|
||||
eend $?
|
||||
fi
|
||||
|
@ -1,8 +1,6 @@
|
||||
env-update.o: env-update.c einfo.h rc.h rc-misc.h strlist.h
|
||||
fstabinfo.o: fstabinfo.c einfo.h
|
||||
libeinfo.o: libeinfo.c einfo.h rc.h rc-misc.h hidden-visibility.h
|
||||
librc.o: librc.c librc.h einfo.h rc.h rc-misc.h strlist.h \
|
||||
hidden-visibility.h
|
||||
librc-daemon.o: librc-daemon.c librc.h einfo.h rc.h rc-misc.h strlist.h \
|
||||
hidden-visibility.h
|
||||
librc-depend.o: librc-depend.c librc.h einfo.h rc.h rc-misc.h strlist.h \
|
||||
@ -11,11 +9,13 @@ librc-misc.o: librc-misc.c librc.h einfo.h rc.h rc-misc.h strlist.h \
|
||||
hidden-visibility.h
|
||||
librc-strlist.o: librc-strlist.c librc.h einfo.h rc.h rc-misc.h strlist.h \
|
||||
hidden-visibility.h
|
||||
librc.o: librc.c librc.h einfo.h rc.h rc-misc.h strlist.h \
|
||||
hidden-visibility.h
|
||||
mountinfo.o: mountinfo.c einfo.h rc.h rc-misc.h strlist.h
|
||||
rc.o: rc.c einfo.h rc.h rc-misc.h rc-plugin.h strlist.h
|
||||
rc-depend.o: rc-depend.c einfo.h rc.h rc-misc.h strlist.h
|
||||
rc-plugin.o: rc-plugin.c einfo.h rc.h rc-misc.h rc-plugin.h strlist.h
|
||||
rc-status.o: rc-status.c einfo.h rc.h rc-misc.h strlist.h
|
||||
rc-update.o: rc-update.c einfo.h rc.h rc-misc.h strlist.h
|
||||
rc.o: rc.c einfo.h rc.h rc-misc.h rc-plugin.h strlist.h
|
||||
runscript.o: runscript.c einfo.h rc.h rc-misc.h rc-plugin.h strlist.h
|
||||
start-stop-daemon.o: start-stop-daemon.c einfo.h rc.h rc-misc.h strlist.h
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -55,7 +56,6 @@ static struct mntent *getmntfile (FILE *fp, const char *file)
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
#ifdef HAVE_GETMNTENT
|
||||
FILE *fp;
|
||||
struct mntent *ent;
|
||||
@ -63,74 +63,85 @@ int main (int argc, char **argv)
|
||||
struct fstab *ent;
|
||||
#endif
|
||||
int result = EXIT_FAILURE;
|
||||
char *p;
|
||||
char *token;
|
||||
int n = 0;
|
||||
char c;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
static struct option longopts[] = {
|
||||
{ "fstype", 1, NULL, 'f'},
|
||||
{ "mountcmd", 1, NULL, 'm'},
|
||||
{ "opts", 1, NULL, 'o'},
|
||||
{ "passno", 1, NULL, 'p'},
|
||||
{ NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
while ((c = getopt_long (argc, argv, "f:m:o:p:",
|
||||
longopts, (int *) 0)) != -1)
|
||||
{
|
||||
#ifdef HAVE_GETMNTENT
|
||||
fp = setmntent ("/etc/fstab", "r");
|
||||
#endif
|
||||
switch (c) {
|
||||
case 'f':
|
||||
while ((token = strsep (&optarg, ",")))
|
||||
while ((ent = GET_ENT))
|
||||
if (strcmp (token, ENT_TYPE (ent)) == 0)
|
||||
printf ("%s\n", ENT_FILE (ent));
|
||||
result = EXIT_SUCCESS;
|
||||
break;
|
||||
|
||||
if (strcmp (argv[i], "--fstype") == 0 && i + 1 < argc) {
|
||||
i++;
|
||||
p = argv[i];
|
||||
while ((token = strsep (&p, ",")))
|
||||
while ((ent = GET_ENT))
|
||||
if (strcmp (token, ENT_TYPE (ent)) == 0)
|
||||
printf ("%s\n", ENT_FILE (ent));
|
||||
result = EXIT_SUCCESS;
|
||||
}
|
||||
case 'm':
|
||||
if ((ent = GET_ENT_FILE (optarg))) {
|
||||
printf ("-o %s -t %s %s %s\n", ENT_OPTS (ent), ENT_TYPE (ent),
|
||||
ENT_DEVICE (ent), ENT_FILE (ent));
|
||||
result = EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
||||
if (strcmp (argv[i], "--mount-cmd") == 0 && i + 1 < argc) {
|
||||
i++;
|
||||
if ((ent = GET_ENT_FILE (argv[i])) == NULL)
|
||||
continue;
|
||||
printf ("-o %s -t %s %s %s\n", ENT_OPTS (ent), ENT_TYPE (ent),
|
||||
ENT_DEVICE (ent), ENT_FILE (ent));
|
||||
result = EXIT_SUCCESS;
|
||||
}
|
||||
case 'o':
|
||||
if ((ent = GET_ENT_FILE (optarg))) {
|
||||
printf ("%s\n", ENT_OPTS (ent));
|
||||
result = EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
||||
if (strcmp (argv[i], "--opts") == 0 && i + 1 < argc) {
|
||||
i++;
|
||||
if ((ent = GET_ENT_FILE (argv[i])) == NULL)
|
||||
continue;
|
||||
printf ("%s\n", ENT_OPTS (ent));
|
||||
result = EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (strcmp (argv[i], "--passno") == 0 && i + 1 < argc) {
|
||||
i++;
|
||||
switch (argv[i][0]) {
|
||||
case 'p':
|
||||
switch (optarg[0]) {
|
||||
case '=':
|
||||
case '<':
|
||||
case '>':
|
||||
if (sscanf (argv[i] + 1, "%d", &n) != 1)
|
||||
eerrorx ("%s: invalid passno %s", argv[0], argv[i] + 1);
|
||||
if (sscanf (optarg + 1, "%d", &n) != 1)
|
||||
eerrorx ("%s: invalid passno %s", argv[0], optarg + 1);
|
||||
|
||||
while ((ent = GET_ENT)) {
|
||||
if (((argv[i][0] == '=' && n == ENT_PASS (ent)) ||
|
||||
(argv[i][0] == '<' && n > ENT_PASS (ent)) ||
|
||||
(argv[i][0] == '>' && n < ENT_PASS (ent))) &&
|
||||
if (((optarg[0] == '=' && n == ENT_PASS (ent)) ||
|
||||
(optarg[0] == '<' && n > ENT_PASS (ent)) ||
|
||||
(optarg[0] == '>' && n < ENT_PASS (ent))) &&
|
||||
strcmp (ENT_FILE (ent), "none") != 0)
|
||||
{
|
||||
printf ("%s\n", ENT_FILE (ent));
|
||||
result = EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if ((ent = GET_ENT_FILE (argv[i])) == NULL)
|
||||
continue;
|
||||
printf ("%d\n", ENT_PASS (ent));
|
||||
result = EXIT_SUCCESS;
|
||||
if ((ent = GET_ENT_FILE (optarg))) {
|
||||
printf ("%d\n", ENT_PASS (ent));
|
||||
result = EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
END_ENT;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
END_ENT;
|
||||
|
||||
if (result != EXIT_SUCCESS) {
|
||||
eerror ("%s: unknown option `%s'", basename (argv[0]), argv[i]);
|
||||
if (result != EXIT_SUCCESS)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exit (result);
|
||||
|
Loading…
Reference in New Issue
Block a user