aboutsummaryrefslogtreecommitdiffstats
path: root/src/getkey.c
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2000-07-02 02:13:12 +0000
committerBill Nottingham <notting@redhat.com>2000-07-02 02:13:12 +0000
commit670813badd4ff32c28f47e7c6c71765d6c2511a6 (patch)
treece15ddafdd1703711db0ca23a90509ff522b13bf /src/getkey.c
parenta7f9998b5ffb2945ef970ae9a40e88e1ecaaae93 (diff)
downloadinitscripts-670813badd4ff32c28f47e7c6c71765d6c2511a6.tar
initscripts-670813badd4ff32c28f47e7c6c71765d6c2511a6.tar.gz
initscripts-670813badd4ff32c28f47e7c6c71765d6c2511a6.tar.bz2
initscripts-670813badd4ff32c28f47e7c6c71765d6c2511a6.tar.xz
initscripts-670813badd4ff32c28f47e7c6c71765d6c2511a6.zip
add support for a timeout argument
Diffstat (limited to 'src/getkey.c')
-rw-r--r--src/getkey.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/getkey.c b/src/getkey.c
index b17558a3..8f1cc1f6 100644
--- a/src/getkey.c
+++ b/src/getkey.c
@@ -1,6 +1,7 @@
#include <ctype.h>
#include <signal.h>
+#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
@@ -16,14 +17,24 @@ void reset_term(int x) {
int main(int argc, char **argv) {
char foo[2];
+ char *list;
+ int alarmlen=0;
int tp_if,tp_of,tp_lf;
int x;
if (argc>1) {
- for (x=0;argv[1][x];x++) argv[1][x]=toupper(argv[1][x]);
+ if (argv[1][0]=='-' && isdigit(argv[1][1])) {
+ alarmlen = atoi(argv[1]+1);
+ list = argv[2];
+ } else {
+ list = argv[1];
+ }
+ for (x=0;list[x];x++) list[x]=toupper(list[x]);
}
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;
@@ -40,7 +51,7 @@ int main(int argc, char **argv) {
foo[0]=toupper(foo[0]);
/* Die if we get a control-c or control-d */
if (foo[0]==3 || foo[0]==4) reset_term(1);
- if ((!argv[1]) || strstr(argv[1],foo)) {
+ if ((!list) || strstr(list,foo)) {
reset_term(0);
}
}