On Wed, Feb 2, 2011 at 5:22 PM, Thomas Geulig <[email protected]> wrote:
> Am Dienstag 01 Februar 2011, 19:38:58 schrieb Harald Becker:
>> In bash there exist a feature for auto-logout. Just set TMOUT variable
>> like:
>>
>> export TMOUT=60
>>
>> But I don't know if this feature is in busybox ash ... don't know what
>> happen to the following (got just from Google) ...
>>
>> http://www.mail-archive.com/[email protected]/msg02686.html
>
> Nothing happened to it, I'm still using it :-)
>
> But I haven't got any feedback on it, and so it never went into the main
> sources.
+static volatile int timed_out;
+
+static void alrm_catcher(int i)
+{
+ printf ("\007timed out waiting for input: auto-logout\n");
+ timed_out = 1;
+ return;
+}
(1) printf in signal handler is a bad idea.
(2) you need to save/restore errno around printf.
+#if ENABLE_ASH_IDLE_TIMEOUT
+ timed_out = 0;
+ tmout_var = NULL;
+ tmout_len = 0;
+ old_alrm = (void *)SIG_IGN;
+ 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 (jobctl)
@@ -10885,6 +10915,15 @@
#endif
}
n = parsecmd(inter);
+#if ENABLE_ASH_IDLE_TIMEOUT
+ if (iflag && timed_out)
+ break;
+ if (iflag && tmout_var && (tmout_len > 0))
Can be made simpler:
if (timed_out)
break;
if (tmout_len > 0) ...
+ {
+ alarm(0);
+ signal(SIGALRM, old_alrm);
(1) old_alrm is SIG_IGN, always. Can be eliminated.
(2) why SIG_IGN? I bet child processes aren't happy
having their SIGALRM ignored.
+ }
+#endif
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox