From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: udev rule, when RUN script is invoked?
Date: Thu, 22 Feb 2018 18:05:13 +0100 [thread overview]
Message-ID: <20180222170513.GA16232@kroah.com> (raw)
In-Reply-To: <1519317860.808906.1279875184.77F93080@webmail.messagingengine.com>
On Thu, Feb 22, 2018 at 08:44:20AM -0800, Alexander Ivanov wrote:
> Greg,
>
> On Thu, 22 Feb 2018 08:56 +0100, Greg KH <greg@kroah.com> wrote:
> > On Wed, Feb 21, 2018 at 03:36:44PM -0800, Alexander Ivanov wrote:
> > > Hi All,
> > >
> > > I have udev rule defined on a
> > >
> > > DEVPATH="/dev/mydev0",..., ACTION="remove", ..., RUN+="/path/to/script"
> > >
> > > When does /path/to/script is executed in respect to module's remove() and exit() ?
> >
> > A module's lifecycle is different from a device's lifecycle, right?
> >
> Sure. However, in this particular case, only one device for the module
> can exist and user-land calls insmod/rmmod, Thus, on rmmod both
> device's remove() and module's exit() are getting called.
What type of crazy "device" is this? Have a pointer to the source code
anywhere?
> > There is no remove() call for a module, only for a driver subsystem, so
> > be careful as to what exactly you are referring to here.
> >
> > Hopefully, all devices "owned" by the module should be removed from the
> > kernel before the module is unloaded, so that should help you out here.
> >
> > Also note that modules are never automatically unloaded, so that is
> > never a normal operation in the system.
> >
> > what exactly are you trying to do here with your udev script?
>
> On action=="remove", I'd like to call device's close(), it was open()ed by action=="add"
> It looks like device is removed before RUN gets a chance to execute..
Of course it is, because when the module is removed, you already removed
the device, right?
> Basically, I need to start reading from device as soon as it appears
> in the system, and stop it right before it get removed.
"right before" is hard if you don't tell your userspace program you are
going to remove the module :)
Your program should be able to handle the device node being removed
underneath it anyway, there's no need to have to "stop" the program, it
can easily detect if the device goes away.
So there's no real need for the udev rule here.
hope this helps,
greg k-h
next prev parent reply other threads:[~2018-02-22 17:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-21 23:36 udev rule, when RUN script is invoked? Alexander Ivanov
2018-02-22 7:56 ` Greg KH
2018-02-22 16:44 ` Alexander Ivanov
2018-02-22 17:05 ` Greg KH [this message]
2018-02-22 17:35 ` Alexander Ivanov
2018-02-23 7:50 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180222170513.GA16232@kroah.com \
--to=greg@kroah.com \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).