aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-02-04 17:53:59 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-04 17:53:59 +0100
commit046341e8bd91a2a2c0d44b40217fa1c5ce1dd949 (patch)
tree855422f962f9aab6727f96559c2cc3e52b2b397d /shell/ash.c
parent8c52f803976c79812a75b9317107cc0a8fb94c7f (diff)
downloadbusybox-w32-046341e8bd91a2a2c0d44b40217fa1c5ce1dd949.tar.gz
busybox-w32-046341e8bd91a2a2c0d44b40217fa1c5ce1dd949.tar.bz2
busybox-w32-046341e8bd91a2a2c0d44b40217fa1c5ce1dd949.zip
ash: optional support for $TMOUT variable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 0e27a073c..bdc64790c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -97,6 +97,14 @@
97//config: help 97//config: help
98//config: Enable bash-compatible extensions. 98//config: Enable bash-compatible extensions.
99//config: 99//config:
100//config:config ASH_IDLE_TIMEOUT
101//config: bool "Idle timeout variable"
102//config: default n
103//config: depends on ASH
104//config: help
105//config: Enables bash-like auto-logout after "$TMOUT" seconds
106//config: of idle time.
107//config:
100//config:config ASH_JOB_CONTROL 108//config:config ASH_JOB_CONTROL
101//config: bool "Job control" 109//config: bool "Job control"
102//config: default y 110//config: default y
@@ -12048,6 +12056,23 @@ evalcmd(int argc UNUSED_PARAM, char **argv)
12048 return exitstatus; 12056 return exitstatus;
12049} 12057}
12050 12058
12059#if ENABLE_ASH_IDLE_TIMEOUT
12060static smallint timed_out;
12061
12062static void alrm_sighandler(int sig UNUSED_PARAM)
12063{
12064 /* Close stdin, making interactive command reading stop.
12065 * Otherwise, timeout doesn't trigger until <Enter> is pressed.
12066 */
12067 int sv = errno;
12068 close(0);
12069 open("/dev/null", O_RDONLY);
12070 errno = sv;
12071
12072 timed_out = 1;
12073}
12074#endif
12075
12051/* 12076/*
12052 * Read and execute commands. 12077 * Read and execute commands.
12053 * "Top" is nonzero for the top level command loop; 12078 * "Top" is nonzero for the top level command loop;
@@ -12064,6 +12089,20 @@ cmdloop(int top)
12064 TRACE(("cmdloop(%d) called\n", top)); 12089 TRACE(("cmdloop(%d) called\n", top));
12065 for (;;) { 12090 for (;;) {
12066 int skip; 12091 int skip;
12092#if ENABLE_ASH_IDLE_TIMEOUT
12093 int tmout_seconds = 0;
12094
12095 if (top && iflag) {
12096 const char *tmout_var = lookupvar("TMOUT");
12097 if (tmout_var) {
12098 tmout_seconds = atoi(tmout_var);
12099 if (tmout_seconds > 0) {
12100 signal(SIGALRM, alrm_sighandler);
12101 alarm(tmout_seconds);
12102 }
12103 }
12104 }
12105#endif
12067 12106
12068 setstackmark(&smark); 12107 setstackmark(&smark);
12069#if JOBS 12108#if JOBS
@@ -12076,6 +12115,14 @@ cmdloop(int top)
12076 chkmail(); 12115 chkmail();
12077 } 12116 }
12078 n = parsecmd(inter); 12117 n = parsecmd(inter);
12118#if ENABLE_ASH_IDLE_TIMEOUT
12119 if (timed_out) {
12120 printf("\007timed out waiting for input: auto-logout\n");
12121 break;
12122 }
12123 if (tmout_seconds > 0)
12124 alarm(0);
12125#endif
12079#if DEBUG 12126#if DEBUG
12080 if (DEBUG > 2 && debug && (n != NODE_EOF)) 12127 if (DEBUG > 2 && debug && (n != NODE_EOF))
12081 showtree(n); 12128 showtree(n);