All of lore.kernel.org
 help / color / mirror / Atom feed
* user space program from keyboard driver
@ 2005-02-28 15:54 Payasam Manohar
  2005-02-28 16:35 ` linux-os
  2005-02-28 21:21 ` Lee Revell
  0 siblings, 2 replies; 6+ messages in thread
From: Payasam Manohar @ 2005-02-28 15:54 UTC (permalink / raw)
  To: linux-kernel

hai all,
    I am a newbie to kernel, I want to work on linux kernel modules.
My task is to call a user program from keyboard driver under certain 
conditions. I know that we can call user program using 
call_usermodehelper(), but we can not call it direcly from driver as it is 
a interrupt context. So we need to call using schedule_work(). But I need 
more clarification on these points. How to call user program from the 
keyboard driver. Please give ur ideas for doing this.

Any small help is appreciated.


Please cc ur replies to my mail id.


   Thanks&Regards,

   P.Manohar,



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: user space program from keyboard driver
  2005-02-28 15:54 user space program from keyboard driver Payasam Manohar
@ 2005-02-28 16:35 ` linux-os
  2005-03-01 15:08   ` Payasam Manohar
  2005-02-28 21:21 ` Lee Revell
  1 sibling, 1 reply; 6+ messages in thread
From: linux-os @ 2005-02-28 16:35 UTC (permalink / raw)
  To: Payasam Manohar; +Cc: Linux kernel

On Mon, 28 Feb 2005, Payasam Manohar wrote:

> hai all,
>   I am a newbie to kernel, I want to work on linux kernel modules.
> My task is to call a user program from keyboard driver under certain 
> conditions. I know that we can call user program using call_usermodehelper(), 
> but we can not call it direcly from driver as it is a interrupt context. So 
> we need to call using schedule_work(). But I need more clarification on these 
> points. How to call user program from the keyboard driver. Please give ur 
> ideas for doing this.
>
> Any small help is appreciated.
>

You don't call a user-mode program from a driver period. It is
possible to screw with kernel internals in such as way to do this,
then unscrew what you've screwed up (sometimes) then state; "See
it can be done.....!". Wrong! Learn that the kernel is designed
to perform tasks on behalf of a user-mode caller. That's what it's
designed for. The kernel doesn't have its own context which is
needed to open files, etc. It has to steal somebody else's context
to do that. It results in a very precarious situation where the
stolen task's context can exit at any time and leave the kernel
in a mess or one steals the context of `init` assuming that
it's not going to quit. The result is a kludge which is
filthy with races.

You should NEVER design anything that runs in the kernel that
expects to call user-mode code. The usermodehelper() code
was used ONLY to get a module for automatic loading of modules.
Even that shouldn't exist and it doesn't need to exist for
the purpose being used. It creates a 'child' of the kernel-
event daemon. If that code was done correctly, none of that
bloat would be in the kernel and fewer persons might expect
to make calls to user-mode code.

The CORRECT design for a user-mode helper requires a user-mode
task called a daemon. That daemon normally sleeps. You can
usually see a lot of such daemons when you execute `ps lae`.
So, you write a program that waits for a signal to wake it
up, perhaps using select() or poll(). It has opened your
driver that exists in the kernel. When your driver wants
your user-mode helper to do something it wakes it up, perhaps
using wake_up_interruptible() or other such kernel functions.
The user-mode helper might make an ioctl() call to find out
what the driver wants done (like reading/writing file data).
The data goes across the driver/user I/O interface like
read() write() or ioctl(). The actual file is open/created/
read/write/closed by the user-mode daemon.

You can wake up a user-mode task from within an interrupt.
However, it only starts executing when it's safe to do
so. In other words, you will NEVER do anything with files
inside an interrupt-service routine.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.10 on an i686 machine (5537.79 BogoMips).
  Notice : All mail here is now cached for review by Dictator Bush.
                  98.36% of all statistics are fiction.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: user space program from keyboard driver
  2005-02-28 15:54 user space program from keyboard driver Payasam Manohar
  2005-02-28 16:35 ` linux-os
@ 2005-02-28 21:21 ` Lee Revell
  2005-03-01  3:41   ` Payasam Manohar
  1 sibling, 1 reply; 6+ messages in thread
From: Lee Revell @ 2005-02-28 21:21 UTC (permalink / raw)
  To: Payasam Manohar; +Cc: linux-kernel

On Mon, 2005-02-28 at 21:24 +0530, Payasam Manohar wrote:
> hai all,
>     I am a newbie to kernel, I want to work on linux kernel modules.
> My task is to call a user program from keyboard driver under certain 
> conditions. I know that we can call user program using 
> call_usermodehelper(), but we can not call it direcly from driver as it is 
> a interrupt context. So we need to call using schedule_work(). But I need 
> more clarification on these points. How to call user program from the 
> keyboard driver. Please give ur ideas for doing this.
> 

Are you just trying to write a keystroke logger?

Lee


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: user space program from keyboard driver
  2005-02-28 21:21 ` Lee Revell
@ 2005-03-01  3:41   ` Payasam Manohar
  0 siblings, 0 replies; 6+ messages in thread
From: Payasam Manohar @ 2005-03-01  3:41 UTC (permalink / raw)
  To: Lee Revell; +Cc: linux-kernel


Thanks.My work is not writing keystroke logger, I know about it, but I 
want to call some other program which will run in bash ,and get some data 
from user mode and return to kernel mode on demand,
which can be called from keyboard driver.





   Thanks&Regards,

   P.Manohar,


On Mon, 28 Feb 2005, Lee Revell wrote:

> On Mon, 2005-02-28 at 21:24 +0530, Payasam Manohar wrote:
>> hai all,
>>     I am a newbie to kernel, I want to work on linux kernel modules.
>> My task is to call a user program from keyboard driver under certain
>> conditions. I know that we can call user program using
>> call_usermodehelper(), but we can not call it direcly from driver as it is
>> a interrupt context. So we need to call using schedule_work(). But I need
>> more clarification on these points. How to call user program from the
>> keyboard driver. Please give ur ideas for doing this.
>>
>
> Are you just trying to write a keystroke logger?
>
> Lee
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: user space program from keyboard driver
  2005-02-28 16:35 ` linux-os
@ 2005-03-01 15:08   ` Payasam Manohar
  2005-03-02 19:44     ` Helge Hafting
  0 siblings, 1 reply; 6+ messages in thread
From: Payasam Manohar @ 2005-03-01 15:08 UTC (permalink / raw)
  To: linux-os; +Cc: linux-kernel



>> hai all,
>>   I am a newbie to kernel, I want to work on linux kernel modules.
>> My task is to call a user program from keyboard driver under certain 
>> conditions. I know that we can call user program using 
>> call_usermodehelper(), but we can not call it direcly from driver as it is 
>> a interrupt context. So we need to call using schedule_work(). But I need 
>> more clarification on these points. How to call user program from the 
>> keyboard driver. Please give ur ideas for doing this.
>> 
>> Any small help is appreciated.
>> 
>
> You don't call a user-mode program from a driver period. It is
> possible to screw with kernel internals in such as way to do this,
> then unscrew what you've screwed up (sometimes) then state; "See
> it can be done.....!". Wrong! Learn that the kernel is designed
> to perform tasks on behalf of a user-mode caller. That's what it's
> designed for. The kernel doesn't have its own context which is
> needed to open files, etc. It has to steal somebody else's context
> to do that. It results in a very precarious situation where the
> stolen task's context can exit at any time and leave the kernel
> in a mess or one steals the context of `init` assuming that
> it's not going to quit. The result is a kludge which is
> filthy with races.
>
> You should NEVER design anything that runs in the kernel that
> expects to call user-mode code. The usermodehelper() code
> was used ONLY to get a module for automatic loading of modules.
> Even that shouldn't exist and it doesn't need to exist for
> the purpose being used. It creates a 'child' of the kernel-
> event daemon. If that code was done correctly, none of that
> bloat would be in the kernel and fewer persons might expect
> to make calls to user-mode code.
>
> The CORRECT design for a user-mode helper requires a user-mode
> task called a daemon. That daemon normally sleeps. You can
> usually see a lot of such daemons when you execute `ps lae`.
> So, you write a program that waits for a signal to wake it
> up, perhaps using select() or poll(). It has opened your
> driver that exists in the kernel. When your driver wants
> your user-mode helper to do something it wakes it up, perhaps
> using wake_up_interruptible() or other such kernel functions.
> The user-mode helper might make an ioctl() call to find out
> what the driver wants done (like reading/writing file data).
> The data goes across the driver/user I/O interface like
> read() write() or ioctl(). The actual file is open/created/
> read/write/closed by the user-mode daemon.
>

Hai thank u for ur information. If possible can u please give some 
reference for the above task of creating a daemon and waking up in demand.

Is it possible to call a daemon from keyboard driver on pressing certain 
key, if so how to kill the daemon from the driver itself with some other 
condition.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: user space program from keyboard driver
  2005-03-01 15:08   ` Payasam Manohar
@ 2005-03-02 19:44     ` Helge Hafting
  0 siblings, 0 replies; 6+ messages in thread
From: Helge Hafting @ 2005-03-02 19:44 UTC (permalink / raw)
  To: Payasam Manohar; +Cc: linux-os, linux-kernel

On Tue, Mar 01, 2005 at 08:38:01PM +0530, Payasam Manohar wrote:
> 
> 
> Hai thank u for ur information. If possible can u please give some 
> reference for the above task of creating a daemon and waking up in demand.
> 
> Is it possible to call a daemon from keyboard driver on pressing certain 
> key, if so how to kill the daemon from the driver itself with some other 
> condition.

I don't know exactly what you want to do, but there is asimple
interface for kernelspace to userspace communication, and that is
to make a character device driver.

You needed to have the kernel ask userspace something and have
userspace report back an answer?  Simple:

1. Userspace program opens your "kernel communication" device
2. The program, or daemon, tries to read from the device.
3. The program will block, because the kernel doesn't have data for
   it at the moment.
4. When the kernel needs data, it writes something to the device.
   If you need to pass information to the daemon program, use thie
   opportunity to write that information.
5. The daemon wakes up because it got data.  It interprets the data,
   and does whatever you want it to do.  When the program have an
   answer to the kernel, it writes the answer into the device.
6. The kernel code gets the answer, in the form of a call into
   the part of the device driver that handles writes from userspace.
   Now the kernel can utilize the information.
7. The daemon can run in a loop, issuing a new read from the device in case
   its services will be needed again.

Thare are variations on this theme.  You may not want to create a new
device if the kernel code that needs this daemnon service is a device 
driver already, for example.  In that case you may want to use an ioctl 
interface for  that device instead.  Note that ioctl's isn't all that 
popular though.

Helge Hafting 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-03-02 19:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-28 15:54 user space program from keyboard driver Payasam Manohar
2005-02-28 16:35 ` linux-os
2005-03-01 15:08   ` Payasam Manohar
2005-03-02 19:44     ` Helge Hafting
2005-02-28 21:21 ` Lee Revell
2005-03-01  3:41   ` Payasam Manohar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.