aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xrc.d/rc.sysinit19
-rw-r--r--src/getkey.c54
2 files changed, 49 insertions, 24 deletions
diff --git a/rc.d/rc.sysinit b/rc.d/rc.sysinit
index 537c2901..2a366b59 100755
--- a/rc.d/rc.sysinit
+++ b/rc.d/rc.sysinit
@@ -218,31 +218,16 @@ elif [ -f /.autofsck ]; then
fi
if [ "$PROMPT" != "no" ]; then
- (
- while [ "$AUTOFSCK_TIMEOUT" -gt 0 ]; do
- if [ "$AUTOFSCK_DEF_CHECK" = "yes" ] ; then
- echo -ne $"\rPress N within $AUTOFSCK_TIMEOUT seconds to not force filesystem check..."
- else
- echo -ne $"\rPress Y within $AUTOFSCK_TIMEOUT seconds to force filesystem check..."
- fi
- sleep 1
- AUTOFSCK_TIMEOUT=$(($AUTOFSCK_TIMEOUT-1))
- done
- kill -TERM `/sbin/pidof getkey` >/dev/null 2>&1
- ) &
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ] ; then
- if /sbin/getkey n ; then
- kill %%
+ if /sbin/getkey -c $AUTOFSCK_TIMEOUT -m $"Press N within %d seconds to not force file system integrity check..." n ; then
AUTOFSCK_OPT=
fi
else
- if /sbin/getkey y ; then
- kill %%
+ if /sbin/getkey -c $AUTOFSCK_TIMEOUT -m $"Press Y within %d seconds to force file system integrity check..." y ; then
AUTOFSCK_OPT=-f
fi
fi
echo
- wait
else
# PROMPT not allowed
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ] ; then
diff --git a/src/getkey.c b/src/getkey.c
index 1305fff9..0aa60921 100644
--- a/src/getkey.c
+++ b/src/getkey.c
@@ -1,10 +1,13 @@
#include <ctype.h>
+#include <errno.h>
#include <signal.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
+#include <sys/poll.h>
/* A very simple keygrabber. */
@@ -18,23 +21,39 @@ void reset_term(int x) {
int main(int argc, char **argv) {
char foo[2];
char *list = NULL;
+ char *waitmessage = NULL;
+ char *waitprint, *waitsprint;
+ int waitseconds=0;
int alarmlen=0;
int tp_if,tp_of,tp_lf;
- int x;
+ int x, r;
+ struct pollfd ufds; /* only one, no need for an array... */
- if (argc>1) {
- if (argv[1][0]=='-' && isdigit(argv[1][1])) {
- alarmlen = atoi(argv[1]+1);
- list = argv[2];
- } else {
- list = argv[1];
+ for (++argv, --argc; argc; argc--, argv++) {
+ if (argv[0][0]=='-') {
+ if (argv[0][1]=='c') {
+ argc--; argv++;
+ waitseconds = atoi(argv[0]);
+ } else if (argv[0][1]=='m') {
+ argc--; argv++;
+ waitmessage=argv[0];
+ } else if (isdigit(argv[0][1])) {
+ waitseconds = atoi(argv[0]);
}
+ } else {
+ list = argv[0];
for (x=0;list[x];x++) list[x]=toupper(list[x]);
+ }
+ }
+ if (waitseconds) {
+ alarmlen = waitseconds;
}
foo[0]=foo[1]='\0';
+
signal(SIGTERM,reset_term);
alarm(alarmlen);
signal(SIGALRM,reset_term);
+
tcgetattr(0,&tp);
tp_if=tp.c_iflag;
tp_of=tp.c_oflag;
@@ -46,7 +65,27 @@ int main(int argc, char **argv) {
tp.c_iflag=tp_if;
tp.c_oflag=tp_of;
tp.c_lflag=tp_lf;
+
+ ufds.events = POLLIN;
+ ufds.fd = 0;
+
+ if (waitseconds && waitmessage) {
+ waitprint = alloca (strlen(waitmessage)+15); /* long enough */
+ waitprint[0] = '\r';
+ waitsprint = waitprint + 1;
+ }
+
while (1) {
+ if (waitseconds) {
+ sprintf (waitsprint, waitmessage, waitseconds);
+ write (1, waitprint, strlen(waitprint));
+ }
+ r = poll(&ufds, 1, alarmlen ? 1000 : -1);
+ if (r == 0) {
+ /* we have waited a whole second with no keystroke... */
+ waitseconds--;
+ }
+ if (r > 0) {
read(0,foo,1);
foo[0]=toupper(foo[0]);
/* Die if we get a control-c or control-d */
@@ -54,5 +93,6 @@ int main(int argc, char **argv) {
if ((!list) || strstr(list,foo)) {
reset_term(0);
}
+ }
}
}