Thanks for the hints and explanations.

Here is an updated patch.

Thomas

--- ash.c.orig	2011-02-03 11:06:35.000000000 +0100
+++ ash.c	2011-02-03 11:14:20.000000000 +0100
@@ -182,6 +182,14 @@
 //config:	  This option recreates the prompt string from the environment
 //config:	  variable each time it is displayed.
 //config:
+//config:config ASH_IDLE_TIMEOUT
+//config:	bool "Idle timeout"
+//config:	default n
+//config:	depends on ASH
+//config:	help
+//config:	  Enables bash-like auto-logout after "$TMOUT" seconds of idle
+//config:	  time. The default value of "$TMOUT" is 300 seconds.
+//config:
 
 //usage:#define ash_trivial_usage NOUSAGE_STR
 //usage:#define ash_full_usage ""
@@ -12045,6 +12053,19 @@
 	return exitstatus;
 }
 
+#if ENABLE_ASH_IDLE_TIMEOUT
+static volatile int timed_out;
+
+static void alrm_catcher(int sig UNUSED_PARAM)
+{
+    int e = errno;
+    fdprintf(2, "\007timed out waiting for input: auto-logout\n");
+    errno = e;
+	timed_out = 1;
+	return;
+}
+#endif
+
 /*
  * Read and execute commands.
  * "Top" is nonzero for the top level command loop;
@@ -12057,11 +12078,28 @@
 	struct stackmark smark;
 	int inter;
 	int numeof = 0;
+#if ENABLE_ASH_IDLE_TIMEOUT
+	int tmout_len;
+	const char *tmout_var;	/* timeout value for auto-logout */
+#endif
 
 	TRACE(("cmdloop(%d) called\n", top));
 	for (;;) {
 		int skip;
 
+#if ENABLE_ASH_IDLE_TIMEOUT
+		timed_out = 0;
+		tmout_var = NULL;
+		tmout_len = 0;
+		if (iflag) {
+			if ((tmout_var = lookupvar("TMOUT")) != NULL
+					&& (tmout_len = atoi(tmout_var)) > 0) {
+				signal(SIGALRM, alrm_catcher);
+				alarm(tmout_len);
+			}
+		}
+#endif
+
 		setstackmark(&smark);
 #if JOBS
 		if (doing_jobctl)
@@ -12075,6 +12113,12 @@
 #endif
 		}
 		n = parsecmd(inter);
+#if ENABLE_ASH_IDLE_TIMEOUT
+		if (timed_out)
+			break;
+		if (tmout_len > 0)
+			alarm(0);
+#endif
 #if DEBUG
 		if (DEBUG > 2 && debug && (n != NODE_EOF))
 			showtree(n);
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to