Mailing List Archive

[PATCH] console alertness - notifying of console activities
Hello.
I always wanted the console to be able to alert me when something happened it
it. So I started writing a patch to allow me to set a virtual console so that
it gets switched to whenever it beeps. I then expanded it so that now you
can:
- have the vc switched to when it beeps,
- have the vc switched to when anything is written to it,
- have the vc beep whenever anything is written to it
- do nothing of the above. 8-)
See the documentation file at the end of the patch for details. And tell me
if you feel such functionality is desired.
The patch applies cleanly with 2.2.12 and 2.3.18, it was originally made for
2.2.10.
(Is this mail enough for the patch to get into the main kernel or what should
I do if I get positive responses about it?)
Jacek Kopecky
E-mail: jacek.kopecky(at)upol.cz (ISO Latin 2 encoding gladly accepted)
WWW: http://www.inf.upol.cz/~kopeckyj ICQ: 49514837
Finger kopeckyj@alpha.inf.upol.cz for Geek Code.
The patch:
----------------------------------------------------------
diff -u --recursive linux-2.2.12/drivers/char/console.c linux/drivers/char/console.c
--- linux-2.2.12/drivers/char/console.c Thu Mar 11 01:51:35 1999
+++ linux/drivers/char/console.c Thu Jul 15 11:55:38 1999
@@ -66,6 +66,8 @@
*
* Resurrected character buffers in videoram plus lots of other trickery
* by Martin Mares <mj@atrey.karlin.mff.cuni.cz>, July 1998
+ *
+ * Console alertness by Jacek Kopecky <jacek@unforgettable.com>, July 1999
*/

#include <linux/module.h>
@@ -1263,6 +1265,10 @@
case 14: /* set vesa powerdown interval */
vesa_off_interval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ;
break;
+ case 15: /* set console alertness:
+ 1 beep on write, 2 switch on beep , 3 switch on write*/
+ alert = (par[1] > 2) ? 3 : par[1];
+ break;
}
}

@@ -1402,6 +1408,8 @@
save_cur(currcons);
if (do_clear)
csi_J(currcons,2);
+
+ alert = 0;
}

static void do_con_trol(struct tty_struct *tty, unsigned int currcons, int c)
@@ -1416,6 +1424,9 @@
case 7:
if (bell_duration)
kd_mksound(bell_pitch, bell_duration);
+ /* switch console if alertness on beep */
+ if ((alert == 2) && (currcons != fg_console))
+ change_console(currcons);
return;
case 8:
bs(currcons);
@@ -1927,6 +1938,16 @@
}
FLUSH
enable_bh(CONSOLE_BH);
+
+ /* Switch to this console if alertness is 3
+ * or beep if alertness is 1
+ */
+ if (alert && (currcons != fg_console)) {
+ if (alert == 3) change_console(currcons);
+ else if ((alert == 1) && bell_duration)
+ kd_mksound(bell_pitch, bell_duration);
+ }
+
return n;
#undef FLUSH
}
diff -u --recursive linux-2.2.12/drivers/char/console_macros.h linux/drivers/char/console_macros.h
--- linux-2.2.12/drivers/char/console_macros.h Thu Sep 17 18:35:03 1998
+++ linux/drivers/char/console_macros.h Wed Jun 30 20:50:00 1999
@@ -64,6 +64,7 @@
#define complement_mask (vc_cons[currcons].d->vc_complement_mask)
#define s_complement_mask (vc_cons[currcons].d->vc_s_complement_mask)
#define hi_font_mask (vc_cons[currcons].d->vc_hi_font_mask)
+#define alert (vc_cons[currcons].d->vc_alert)

#define vcmode (vt_cons[currcons]->vc_mode)

diff -u --recursive linux-2.2.12/include/linux/console_struct.h linux/include/linux/console_struct.h
--- linux-2.2.12/include/linux/console_struct.h Thu Sep 17 18:35:04 1998
+++ linux/include/linux/console_struct.h Wed Jun 30 22:45:11 1999
@@ -65,6 +65,7 @@
unsigned int vc_can_do_color : 1;
unsigned int vc_report_mouse : 2;
unsigned int vc_kmalloced : 1;
+ unsigned int vc_alert : 2; /* Switch to this console on write or beep */
unsigned char vc_utf : 1; /* Unicode UTF-8 encoding */
unsigned char vc_utf_count;
int vc_utf_char;
diff -u --recursive --new-file linux-2.2.12/Documentation/console-alertness linux/Documentation/console-alertness
--- linux-2.2.12/Documentation/console-alertness Thu Jan 1 01:00:00 1970
+++ linux/Documentation/console-alertness Fri Aug 6 22:45:45 1999
@@ -0,0 +1,31 @@
+This file describes the console alertness function of linux virtual consoles
+as implemented by Jacek Kopecky (jacek@unforgettable.com) in July 1999.
+
+First, what does console alertness mean anyway?
+In cases when you want to be warned when something changes or only beeps on a
+virtual console other than the one that's active at the moment (so that you
+don't see the changes yourself), you can use the following escape sequences
+to set the console-alertness-level to get some warnings:
+
+echo -ne "\033[15;0]" > /dev/ttyX alertnes off ("beep on beep")
+echo -ne "\033[15;1]" > /dev/ttyX beep on write to the console
+echo -ne "\033[15;2]" > /dev/ttyX switch to the console on beep
+echo -ne "\033[15;3]" > /dev/ttyX switch to the console on write
+
+At the level 1 the virtual console /dev/ttyX beeps whenever anything is
+written to it but only if the console is not currently the foreground console.
+The level 2 makes the console get switched to whenever it beeps. On the highest
+level the console gets switched to on each write to it.
+
+A side-effect of setting beep-on-write (1) or switch-on-write (3) on another
+console is that the other console beeps or is switched to, this comes handy
+as a test it's working. 8-)
+The sequence for setting the switch-on-beep (2) level can be enhanced to give
+the same kind of test:
+
+echo -ne "\033[15;2]\a" > /dev/ttyX
+
+The setting sequences may seem to be a little too user-unfriendly so I'm
+planning to try to incorporate alertness setting into the setterm package.
+
+Enjoy. 8-)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] console alertness - notifying of console activities [ In reply to ]
An interesting patch.
I expect that the next one will include options for setting
the pitch and duration of the beep issued by the kernel when
there is a beep on a different console.
But really, if you want to know when messages appear on a log console,
then something like
#!/bin/sh
# call: chvt_on_event N
N=$1
VT=/dev/vcs$N
OLD=/tmp/.chvtoe$$
NEW=/tmp/.chvtoe$$x
cat $VT > $OLD
while true; do
sleep 1
cat $VT > $NEW
if ! cmp -s $OLD $NEW ; then
mv $NEW $OLD
chvt $N
fi
done
would do.
Add parameter checking and removal of temp files on exit.
Replace the chvt $N by an echo ^G if you only want a beep.
A C version would be a single page of code.
Andries
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/