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