Question: Returning values from kernel FIFO to userspace

From: Maciej Zenczykowski
Date: Fri Nov 07 2003 - 18:19:24 EST


Hi,
I have a kernel FIFO for special keyboard events (considered asynchronous
to normal keypresses) and a userspace script (invoked by keyboard_signal
from init) which reads them (one at a time).

And no, these keys can't be handled like normal extended keys as they use
_a very_ different route to reach the kernel -- and neither would I want
to - they're of the: lock keyboard, turn off screen, disk, sleep,
hibernate, etc variety.

Currently, I'm using a mangled proc interface (which is very much a
hack: reading /proc/special_keycode returns the current value at the head
of the FIFO, and if the seek offset was 0 then it pops the FIFO. This
last part is due to 'cat /proc/file' doing two reads, the first for the
data with a 1K buffer and the second to determine we're at EOF, both call
the proc read interface. nb. this means that if proc exports a value that
is variable length (like jiffies), it is possible for cat /proc/file to
return junk (at the end of the file) if the proc file length increases
between first and second read invocation (unlikely, but possible...) -
perhaps this should be fixed more globally - but how? by cacheing?
remembering a given proc fd has already EOF'ed and not invoking the
proc read procedure a second time?).

What would be considered 'the right way' to return an integer
from a 30-value integer FIFO in the kernel to a userspace script (and
pop the FIFO at the same time).
This is called very very rarely (once a couple minutes, sometimes
even hours) as it only happens when the user actually presses some
unusual key-combination. However a FIFO is necessary because a single
keypress combination usually results in 2-3 events.

Thanks,
MaZe.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/