[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
/*
2009-06-04 03:44:04 +04:00
* Copyright ( C ) 2004 - 2009 Kay Sievers < kay . sievers @ vrfy . org >
[PATCH] convert udevsend/udevd to DGRAM and single-threaded
On Fri, Feb 06, 2004 at 01:08:24AM -0500, Chris Friesen wrote:
>
> Kay, you said "unless we can get rid of _all_ the threads or at least
> getting faster, I don't want to change it."
>
> Well how about we get rid of all the threads, *and* we get faster?
Yes, we are twice as fast now on my box :)
> This patch applies to current bk trees, and does the following:
>
> 1) Switch to DGRAM sockets rather than STREAM. This simplifies things
> as mentioned in the previous message.
>
> 2) Invalid sequence numbers are mapped to -1 rather than zero, since
> zero is a valid sequence number (I think). Also, this allows for real
> speed tests using scripts starting at a zero sequence number, since that
> is what the initial expected sequence number is.
>
> 3) Get rid of all threading. This is the biggie. Some highlights:
> a) timeout using setitimer() and SIGALRM
> b) async child death notification via SIGCHLD
> c) these two signal handlers do nothing but raise volatile flags,
> all the
> work is done in the main loop
> d) locking no longer required
I cleaned up the rest of the comments, the whitespace and a few names to match
the whole thing. Please recheck it. Test script is switched to work on subsystem
'test' to let udev ignore it.
2004-02-07 09:21:15 +03:00
* Copyright ( C ) 2004 Chris Friesen < chris_friesen @ sympatico . ca >
2009-03-10 16:00:16 +03:00
* Copyright ( C ) 2009 Canonical Ltd .
* Copyright ( C ) 2009 Scott James Remnant < scott @ netsplit . com >
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
*
2008-09-10 04:40:42 +04:00
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 2 of the License , or
* ( at your option ) any later version .
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
*
2008-09-10 04:40:42 +04:00
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
*
2008-09-10 04:40:42 +04:00
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
*/
2004-01-27 05:19:33 +03:00
# include <stddef.h>
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
# include <signal.h>
# include <unistd.h>
# include <errno.h>
# include <stdio.h>
# include <stdlib.h>
2009-07-13 05:33:15 +04:00
# include <stdbool.h>
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
# include <string.h>
2005-01-17 02:53:08 +03:00
# include <ctype.h>
# include <fcntl.h>
2005-11-07 04:22:44 +03:00
# include <time.h>
2006-09-08 13:27:03 +04:00
# include <getopt.h>
2008-11-06 19:43:12 +03:00
# include <dirent.h>
2009-07-17 15:24:37 +04:00
# include <sys/time.h>
2009-06-04 03:44:04 +04:00
# include <sys/prctl.h>
# include <sys/socket.h>
# include <sys/signalfd.h>
2005-03-10 02:58:01 +03:00
# include <sys/select.h>
2009-01-20 14:49:20 +03:00
# include <sys/poll.h>
2005-03-10 02:58:01 +03:00
# include <sys/wait.h>
2004-10-14 09:37:59 +04:00
# include <sys/stat.h>
2005-10-27 23:04:38 +04:00
# include <sys/ioctl.h>
2008-07-30 03:45:23 +04:00
# include <sys/inotify.h>
2010-05-20 19:09:04 +04:00
# include <sys/utsname.h>
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
# include "udev.h"
2008-09-08 19:59:00 +04:00
# define UDEVD_PRIORITY -4
# define UDEV_PRIORITY -2
2009-07-13 05:33:15 +04:00
static bool debug ;
2006-09-08 13:28:38 +04:00
2008-09-06 17:45:31 +04:00
static void log_fn ( struct udev * udev , int priority ,
const char * file , int line , const char * fn ,
const char * format , va_list args )
{
if ( debug ) {
2009-07-17 15:24:37 +04:00
char buf [ 1024 ] ;
struct timeval tv ;
struct timezone tz ;
vsnprintf ( buf , sizeof ( buf ) , format , args ) ;
gettimeofday ( & tv , & tz ) ;
fprintf ( stderr , " %llu.%06u [%u] %s: %s " ,
( unsigned long long ) tv . tv_sec , ( unsigned int ) tv . tv_usec ,
( int ) getpid ( ) , fn , buf ) ;
2008-09-06 17:45:31 +04:00
} else {
vsyslog ( priority , format , args ) ;
}
}
2008-10-18 17:02:01 +04:00
static struct udev_rules * rules ;
2009-05-22 00:22:37 +04:00
static struct udev_queue_export * udev_queue_export ;
2008-09-08 19:59:00 +04:00
static struct udev_ctrl * udev_ctrl ;
2009-06-04 03:44:04 +04:00
static struct udev_monitor * monitor ;
static int worker_watch [ 2 ] ;
static pid_t settle_pid ;
2009-07-13 05:33:15 +04:00
static bool stop_exec_queue ;
static bool reload_config ;
2010-05-27 19:27:56 +04:00
static int children ;
static int children_max ;
2010-05-28 14:07:27 +04:00
static int exec_delay ;
2009-09-05 11:48:23 +04:00
static sigset_t orig_sigmask ;
2008-10-29 19:32:13 +03:00
static struct udev_list_node event_list ;
2009-06-04 03:44:04 +04:00
static struct udev_list_node worker_list ;
2009-07-13 05:33:15 +04:00
static bool udev_exit ;
2009-06-04 03:44:04 +04:00
static volatile sig_atomic_t worker_exit ;
enum poll_fd {
FD_CONTROL ,
FD_NETLINK ,
FD_INOTIFY ,
FD_SIGNAL ,
FD_WORKER ,
} ;
static struct pollfd pfd [ ] = {
[ FD_NETLINK ] = { . events = POLLIN } ,
[ FD_WORKER ] = { . events = POLLIN } ,
[ FD_SIGNAL ] = { . events = POLLIN } ,
[ FD_INOTIFY ] = { . events = POLLIN } ,
[ FD_CONTROL ] = { . events = POLLIN } ,
} ;
enum event_state {
EVENT_UNDEF ,
EVENT_QUEUED ,
EVENT_RUNNING ,
} ;
struct event {
struct udev_list_node node ;
struct udev * udev ;
struct udev_device * dev ;
enum event_state state ;
int exitcode ;
unsigned long long int delaying_seqnum ;
unsigned long long int seqnum ;
const char * devpath ;
size_t devpath_len ;
const char * devpath_old ;
2009-10-08 02:06:23 +04:00
dev_t devnum ;
bool is_block ;
2009-06-04 03:44:04 +04:00
} ;
static struct event * node_to_event ( struct udev_list_node * node )
2008-10-17 20:59:27 +04:00
{
char * event ;
event = ( char * ) node ;
2009-06-04 03:44:04 +04:00
event - = offsetof ( struct event , node ) ;
return ( struct event * ) event ;
}
enum worker_state {
WORKER_UNDEF ,
WORKER_RUNNING ,
WORKER_IDLE ,
WORKER_KILLED ,
} ;
struct worker {
struct udev_list_node node ;
2009-07-13 05:09:05 +04:00
struct udev * udev ;
int refcount ;
2009-06-04 03:44:04 +04:00
pid_t pid ;
struct udev_monitor * monitor ;
enum worker_state state ;
struct event * event ;
} ;
/* passed from worker to main process */
struct worker_message {
pid_t pid ;
int exitcode ;
} ;
static struct worker * node_to_worker ( struct udev_list_node * node )
{
char * worker ;
worker = ( char * ) node ;
worker - = offsetof ( struct worker , node ) ;
return ( struct worker * ) worker ;
2008-10-17 20:59:27 +04:00
}
2009-06-04 03:44:04 +04:00
static void event_queue_delete ( struct event * event )
2005-11-07 16:10:09 +03:00
{
2008-10-17 20:59:27 +04:00
udev_list_node_remove ( & event - > node ) ;
2005-11-16 06:12:53 +03:00
2007-08-26 07:22:35 +04:00
/* mark as failed, if "add" event returns non-zero */
2010-04-12 18:52:41 +04:00
if ( event - > exitcode ! = 0 & & strcmp ( udev_device_get_action ( event - > dev ) , " remove " ) ! = 0 )
2009-05-22 00:22:37 +04:00
udev_queue_export_device_failed ( udev_queue_export , event - > dev ) ;
2005-11-16 06:12:53 +03:00
else
2009-05-22 00:22:37 +04:00
udev_queue_export_device_finished ( udev_queue_export , event - > dev ) ;
2008-10-16 19:16:58 +04:00
2009-06-08 19:16:48 +04:00
info ( event - > udev , " seq %llu done with %i \n " , udev_device_get_seqnum ( event - > dev ) , event - > exitcode ) ;
2008-10-16 19:16:58 +04:00
udev_device_unref ( event - > dev ) ;
2009-06-04 03:44:04 +04:00
free ( event ) ;
2008-10-16 19:16:58 +04:00
}
2005-11-16 06:12:53 +03:00
2009-05-05 04:39:16 +04:00
static void event_sig_handler ( int signum )
2008-10-16 19:16:58 +04:00
{
2009-06-04 03:44:04 +04:00
switch ( signum ) {
case SIGALRM :
2009-05-05 04:39:16 +04:00
_exit ( 1 ) ;
2009-06-04 03:44:04 +04:00
break ;
case SIGTERM :
2009-07-13 05:33:15 +04:00
worker_exit = true ;
2009-06-04 03:44:04 +04:00
break ;
}
}
2009-07-13 05:09:05 +04:00
static struct worker * worker_ref ( struct worker * worker )
{
worker - > refcount + + ;
return worker ;
}
2009-06-04 03:44:04 +04:00
static void worker_unref ( struct worker * worker )
{
2009-07-13 05:09:05 +04:00
worker - > refcount - - ;
if ( worker - > refcount > 0 )
return ;
udev_list_node_remove ( & worker - > node ) ;
2009-06-04 03:44:04 +04:00
udev_monitor_unref ( worker - > monitor ) ;
2010-05-27 19:27:56 +04:00
children - - ;
2009-07-13 05:09:05 +04:00
info ( worker - > udev , " worker [%u] cleaned up \n " , worker - > pid ) ;
2009-06-04 03:44:04 +04:00
free ( worker ) ;
2005-11-07 16:10:09 +03:00
}
2009-06-04 03:44:04 +04:00
static void worker_new ( struct event * event )
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
{
2009-06-04 03:44:04 +04:00
struct worker * worker ;
struct udev_monitor * worker_monitor ;
2004-01-23 15:01:09 +03:00
pid_t pid ;
2008-10-16 19:16:58 +04:00
struct sigaction act ;
2009-05-21 03:20:18 +04:00
2009-06-04 03:44:04 +04:00
/* listen for new events */
worker_monitor = udev_monitor_new_from_netlink ( event - > udev , NULL ) ;
if ( worker_monitor = = NULL )
return ;
/* allow the main daemon netlink address to send devices to the worker */
udev_monitor_allow_unicast_sender ( worker_monitor , monitor ) ;
udev_monitor_enable_receiving ( worker_monitor ) ;
worker = calloc ( 1 , sizeof ( struct worker ) ) ;
if ( worker = = NULL )
return ;
2009-07-13 05:09:05 +04:00
/* worker + event reference */
worker - > refcount = 2 ;
worker - > udev = event - > udev ;
2008-10-29 19:32:13 +03:00
2004-01-23 15:01:09 +03:00
pid = fork ( ) ;
switch ( pid ) {
2009-06-04 03:44:04 +04:00
case 0 : {
2009-07-11 20:21:26 +04:00
sigset_t sigmask ;
2009-06-04 03:44:04 +04:00
struct udev_device * dev ;
2009-07-11 20:21:26 +04:00
struct pollfd pmon = {
. fd = udev_monitor_get_fd ( worker_monitor ) ,
. events = POLLIN ,
} ;
2009-06-04 03:44:04 +04:00
2009-05-22 00:22:37 +04:00
udev_queue_export_unref ( udev_queue_export ) ;
2009-06-04 04:49:42 +04:00
udev_monitor_unref ( monitor ) ;
2008-09-08 19:59:00 +04:00
udev_ctrl_unref ( udev_ctrl ) ;
2009-06-04 03:44:04 +04:00
close ( pfd [ FD_SIGNAL ] . fd ) ;
close ( worker_watch [ READ_END ] ) ;
2009-06-10 00:47:48 +04:00
udev_log_close ( ) ;
udev_log_init ( " udevd-work " ) ;
2005-01-17 02:53:08 +03:00
setpriority ( PRIO_PROCESS , 0 , UDEV_PRIORITY ) ;
2006-07-25 16:45:09 +04:00
2008-10-16 19:16:58 +04:00
/* set signal handlers */
memset ( & act , 0x00 , sizeof ( act ) ) ;
2009-05-05 04:39:16 +04:00
act . sa_handler = event_sig_handler ;
2008-10-16 19:16:58 +04:00
sigemptyset ( & act . sa_mask ) ;
act . sa_flags = 0 ;
2009-06-04 03:44:04 +04:00
sigaction ( SIGTERM , & act , NULL ) ;
2008-10-16 19:16:58 +04:00
sigaction ( SIGALRM , & act , NULL ) ;
2009-07-11 20:21:26 +04:00
/* unblock SIGALRM */
sigfillset ( & sigmask ) ;
sigdelset ( & sigmask , SIGALRM ) ;
sigprocmask ( SIG_SETMASK , & sigmask , NULL ) ;
/* SIGTERM is unblocked in ppoll() */
sigdelset ( & sigmask , SIGTERM ) ;
2008-10-16 19:16:58 +04:00
2009-06-04 03:44:04 +04:00
/* request TERM signal if parent exits */
prctl ( PR_SET_PDEATHSIG , SIGTERM ) ;
2008-10-16 19:16:58 +04:00
2009-06-04 03:44:04 +04:00
/* initial device */
dev = event - > dev ;
2008-10-16 19:16:58 +04:00
2009-07-11 20:21:26 +04:00
do {
2009-06-04 03:44:04 +04:00
struct udev_event * udev_event ;
2009-08-06 18:16:26 +04:00
struct worker_message msg = { } ;
2009-06-04 03:44:04 +04:00
int err ;
2009-08-06 18:16:26 +04:00
int failed = 0 ;
2008-10-16 19:16:58 +04:00
2009-07-17 15:24:37 +04:00
info ( event - > udev , " seq %llu running \n " , udev_device_get_seqnum ( dev ) ) ;
2009-06-04 03:44:04 +04:00
udev_event = udev_event_new ( dev ) ;
if ( udev_event = = NULL )
_exit ( 3 ) ;
2008-10-29 19:32:13 +03:00
2009-06-04 03:44:04 +04:00
/* set timeout to prevent hanging processes */
alarm ( UDEV_EVENT_TIMEOUT ) ;
2010-05-28 14:07:27 +04:00
if ( exec_delay > 0 )
udev_event - > exec_delay = exec_delay ;
2009-06-04 03:44:04 +04:00
/* apply rules, create node, symlinks */
err = udev_event_execute_rules ( udev_event , rules ) ;
/* rules may change/disable the timeout */
if ( udev_device_get_event_timeout ( dev ) > = 0 )
alarm ( udev_device_get_event_timeout ( dev ) ) ;
2009-12-25 17:23:45 +03:00
if ( err = = 0 )
failed = udev_event_execute_run ( udev_event , & orig_sigmask ) ;
2009-06-04 03:44:04 +04:00
alarm ( 0 ) ;
/* apply/restore inotify watch */
if ( err = = 0 & & udev_event - > inotify_watch ) {
udev_watch_begin ( udev_event - > udev , dev ) ;
udev_device_update_db ( dev ) ;
}
2009-02-23 20:17:20 +03:00
2009-06-04 03:44:04 +04:00
/* send processed event back to libudev listeners */
udev_monitor_send_device ( worker_monitor , NULL , dev ) ;
2009-03-29 06:24:39 +04:00
2009-12-25 17:23:45 +03:00
/* send udevd the result of the event execution */
2009-08-06 18:16:26 +04:00
if ( err ! = 0 )
msg . exitcode = err ;
else if ( failed ! = 0 )
msg . exitcode = failed ;
2009-06-04 03:44:04 +04:00
msg . pid = getpid ( ) ;
send ( worker_watch [ WRITE_END ] , & msg , sizeof ( struct worker_message ) , 0 ) ;
2009-07-11 20:21:26 +04:00
info ( event - > udev , " seq %llu processed with %i \n " , udev_device_get_seqnum ( dev ) , err ) ;
udev_event_unref ( udev_event ) ;
udev_device_unref ( dev ) ;
dev = NULL ;
/* wait for more device messages or signal from udevd */
while ( ! worker_exit ) {
int fdcount ;
fdcount = ppoll ( & pmon , 1 , NULL , & sigmask ) ;
if ( fdcount < 0 )
continue ;
if ( pmon . revents & POLLIN ) {
dev = udev_monitor_receive_device ( worker_monitor ) ;
if ( dev ! = NULL )
break ;
}
}
} while ( dev ! = NULL ) ;
2009-06-04 03:44:04 +04:00
udev_monitor_unref ( worker_monitor ) ;
2009-06-10 00:47:48 +04:00
udev_log_close ( ) ;
2005-10-27 23:04:38 +04:00
exit ( 0 ) ;
2009-06-04 03:44:04 +04:00
}
2004-01-23 15:01:09 +03:00
case - 1 :
2009-06-04 03:44:04 +04:00
udev_monitor_unref ( worker_monitor ) ;
event - > state = EVENT_QUEUED ;
free ( worker ) ;
2008-10-16 19:16:58 +04:00
err ( event - > udev , " fork of child failed: %m \n " ) ;
[PATCH] convert udevsend/udevd to DGRAM and single-threaded
On Fri, Feb 06, 2004 at 01:08:24AM -0500, Chris Friesen wrote:
>
> Kay, you said "unless we can get rid of _all_ the threads or at least
> getting faster, I don't want to change it."
>
> Well how about we get rid of all the threads, *and* we get faster?
Yes, we are twice as fast now on my box :)
> This patch applies to current bk trees, and does the following:
>
> 1) Switch to DGRAM sockets rather than STREAM. This simplifies things
> as mentioned in the previous message.
>
> 2) Invalid sequence numbers are mapped to -1 rather than zero, since
> zero is a valid sequence number (I think). Also, this allows for real
> speed tests using scripts starting at a zero sequence number, since that
> is what the initial expected sequence number is.
>
> 3) Get rid of all threading. This is the biggie. Some highlights:
> a) timeout using setitimer() and SIGALRM
> b) async child death notification via SIGCHLD
> c) these two signal handlers do nothing but raise volatile flags,
> all the
> work is done in the main loop
> d) locking no longer required
I cleaned up the rest of the comments, the whitespace and a few names to match
the whole thing. Please recheck it. Test script is switched to work on subsystem
'test' to let udev ignore it.
2004-02-07 09:21:15 +03:00
break ;
2004-01-23 15:01:09 +03:00
default :
2009-06-04 03:44:04 +04:00
/* close monitor, but keep address around */
udev_monitor_disconnect ( worker_monitor ) ;
worker - > monitor = worker_monitor ;
worker - > pid = pid ;
worker - > state = WORKER_RUNNING ;
worker - > event = event ;
event - > state = EVENT_RUNNING ;
udev_list_node_append ( & worker - > node , & worker_list ) ;
2010-05-27 19:27:56 +04:00
children + + ;
2009-06-09 20:31:14 +04:00
info ( event - > udev , " seq %llu forked new worker [%u] \n " , udev_device_get_seqnum ( event - > dev ) , pid ) ;
2009-06-04 03:44:04 +04:00
break ;
2004-01-23 15:01:09 +03:00
}
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
}
2010-04-26 14:21:16 +04:00
static void event_run ( struct event * event , bool force )
2005-11-07 16:10:09 +03:00
{
2009-06-04 03:44:04 +04:00
struct udev_list_node * loop ;
udev_list_node_foreach ( loop , & worker_list ) {
struct worker * worker = node_to_worker ( loop ) ;
ssize_t count ;
2006-04-05 02:08:10 +04:00
2009-06-04 03:44:04 +04:00
if ( worker - > state ! = WORKER_IDLE )
continue ;
2008-05-30 11:43:58 +04:00
2009-06-04 03:44:04 +04:00
count = udev_monitor_send_device ( monitor , worker - > monitor , event - > dev ) ;
if ( count < 0 ) {
2009-07-08 16:13:20 +04:00
err ( event - > udev , " worker [%u] did not accept message %zi (%m), kill it \n " , worker - > pid , count ) ;
2009-06-04 03:44:04 +04:00
kill ( worker - > pid , SIGKILL ) ;
2009-07-13 05:09:05 +04:00
worker - > state = WORKER_KILLED ;
2009-06-04 03:44:04 +04:00
continue ;
}
2009-07-13 05:09:05 +04:00
worker_ref ( worker ) ;
worker - > event = event ;
worker - > state = WORKER_RUNNING ;
event - > state = EVENT_RUNNING ;
2009-06-04 03:44:04 +04:00
return ;
}
2010-05-27 19:27:56 +04:00
if ( ! force & & children > = children_max ) {
2010-05-28 14:07:27 +04:00
if ( children_max > 1 )
info ( event - > udev , " maximum number (%i) of children reached \n " , children ) ;
2009-06-04 03:44:04 +04:00
return ;
}
/* start new worker and pass initial device */
worker_new ( event ) ;
}
static void event_queue_insert ( struct udev_device * dev )
{
struct event * event ;
event = calloc ( 1 , sizeof ( struct event ) ) ;
if ( event = = NULL )
return ;
event - > udev = udev_device_get_udev ( dev ) ;
event - > dev = dev ;
event - > seqnum = udev_device_get_seqnum ( dev ) ;
event - > devpath = udev_device_get_devpath ( dev ) ;
event - > devpath_len = strlen ( event - > devpath ) ;
event - > devpath_old = udev_device_get_devpath_old ( dev ) ;
2009-10-08 02:06:23 +04:00
event - > devnum = udev_device_get_devnum ( dev ) ;
event - > is_block = ( strcmp ( " block " , udev_device_get_subsystem ( dev ) ) = = 0 ) ;
2009-06-04 03:44:04 +04:00
udev_queue_export_device_queued ( udev_queue_export , dev ) ;
info ( event - > udev , " seq %llu queued, '%s' '%s' \n " , udev_device_get_seqnum ( dev ) ,
udev_device_get_action ( dev ) , udev_device_get_subsystem ( dev ) ) ;
event - > state = EVENT_QUEUED ;
2008-10-29 19:32:13 +03:00
udev_list_node_append ( & event - > node , & event_list ) ;
2006-09-08 13:30:00 +04:00
2005-11-07 16:10:09 +03:00
/* run all events with a timeout set immediately */
2009-06-04 03:44:04 +04:00
if ( udev_device_get_timeout ( dev ) > 0 ) {
2010-04-26 14:21:16 +04:00
event_run ( event , true ) ;
2005-11-07 16:10:09 +03:00
return ;
}
}
2009-07-11 20:21:26 +04:00
static void worker_kill ( struct udev * udev , int retain )
2009-06-04 03:44:04 +04:00
{
struct udev_list_node * loop ;
int max ;
2010-05-27 19:27:56 +04:00
if ( children < = retain )
2009-06-04 03:44:04 +04:00
return ;
2010-05-27 19:27:56 +04:00
max = children - retain ;
2009-06-04 03:44:04 +04:00
udev_list_node_foreach ( loop , & worker_list ) {
struct worker * worker = node_to_worker ( loop ) ;
if ( max - - < = 0 )
break ;
if ( worker - > state = = WORKER_KILLED )
continue ;
worker - > state = WORKER_KILLED ;
kill ( worker - > pid , SIGTERM ) ;
}
}
2009-05-05 00:08:05 +04:00
/* lookup event for identical, parent, child device */
2009-10-08 02:06:23 +04:00
static bool is_devpath_busy ( struct event * event )
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
{
2008-10-17 20:59:27 +04:00
struct udev_list_node * loop ;
2009-06-04 03:44:04 +04:00
size_t common ;
2005-01-05 07:35:24 +03:00
2008-10-29 19:32:13 +03:00
/* check if queue contains events we depend on */
udev_list_node_foreach ( loop , & event_list ) {
2009-06-04 03:44:04 +04:00
struct event * loop_event = node_to_event ( loop ) ;
2008-10-17 20:59:27 +04:00
2008-10-29 19:32:13 +03:00
/* we already found a later event, earlier can not block us, no need to check again */
2009-06-04 03:44:04 +04:00
if ( loop_event - > seqnum < event - > delaying_seqnum )
2008-10-29 19:32:13 +03:00
continue ;
/* event we checked earlier still exists, no need to check again */
2009-06-04 03:44:04 +04:00
if ( loop_event - > seqnum = = event - > delaying_seqnum )
2009-10-08 02:06:23 +04:00
return true ;
2008-10-29 19:32:13 +03:00
/* found ourself, no later event can block us */
2009-06-04 03:44:04 +04:00
if ( loop_event - > seqnum > = event - > seqnum )
2007-04-20 00:21:05 +04:00
break ;
2009-10-08 02:06:23 +04:00
/* check major/minor */
if ( major ( event - > devnum ) ! = 0 & & event - > devnum = = loop_event - > devnum & & event - > is_block = = loop_event - > is_block )
return true ;
2007-08-26 07:22:35 +04:00
/* check our old name */
2009-10-08 02:06:23 +04:00
if ( event - > devpath_old ! = NULL & & strcmp ( loop_event - > devpath , event - > devpath_old ) = = 0 ) {
event - > delaying_seqnum = loop_event - > seqnum ;
return true ;
}
2007-08-26 07:22:35 +04:00
2009-06-04 03:44:04 +04:00
/* compare devpath */
common = MIN ( loop_event - > devpath_len , event - > devpath_len ) ;
/* one devpath is contained in the other? */
if ( memcmp ( loop_event - > devpath , event - > devpath , common ) ! = 0 )
continue ;
/* identical device event found */
if ( loop_event - > devpath_len = = event - > devpath_len ) {
event - > delaying_seqnum = loop_event - > seqnum ;
2009-10-08 02:06:23 +04:00
return true ;
2008-04-02 06:32:17 +04:00
}
2009-06-04 03:44:04 +04:00
/* parent device event found */
if ( event - > devpath [ common ] = = ' / ' ) {
event - > delaying_seqnum = loop_event - > seqnum ;
2009-10-08 02:06:23 +04:00
return true ;
2009-06-04 03:44:04 +04:00
}
/* child device event found */
if ( loop_event - > devpath [ common ] = = ' / ' ) {
event - > delaying_seqnum = loop_event - > seqnum ;
2009-10-08 02:06:23 +04:00
return true ;
2009-06-04 03:44:04 +04:00
}
/* no matching device */
continue ;
2004-11-19 05:49:13 +03:00
}
2009-06-04 03:44:04 +04:00
2009-10-08 02:06:23 +04:00
return false ;
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
}
2009-06-04 03:44:04 +04:00
static void events_start ( struct udev * udev )
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
{
2008-10-17 20:59:27 +04:00
struct udev_list_node * loop ;
2005-06-16 03:58:47 +04:00
2009-06-04 03:44:04 +04:00
udev_list_node_foreach ( loop , & event_list ) {
struct event * event = node_to_event ( loop ) ;
2008-10-29 19:32:13 +03:00
2009-06-04 03:44:04 +04:00
if ( event - > state ! = EVENT_QUEUED )
2008-10-29 19:32:13 +03:00
continue ;
/* do not start event if parent or child event is still running */
2009-10-08 02:06:23 +04:00
if ( is_devpath_busy ( event ) ) {
2009-06-04 03:44:04 +04:00
dbg ( udev , " delay seq %llu (%s) \n " , event - > seqnum , event - > devpath ) ;
2005-11-07 16:10:09 +03:00
continue ;
}
2010-04-26 14:21:16 +04:00
event_run ( event , false ) ;
2009-06-04 03:44:04 +04:00
}
}
static void worker_returned ( void )
{
2010-05-27 17:11:00 +04:00
for ( ; ; ) {
2009-06-04 03:44:04 +04:00
struct worker_message msg ;
ssize_t size ;
struct udev_list_node * loop ;
size = recv ( pfd [ FD_WORKER ] . fd , & msg , sizeof ( struct worker_message ) , MSG_DONTWAIT ) ;
if ( size ! = sizeof ( struct worker_message ) )
break ;
/* lookup worker who sent the signal */
udev_list_node_foreach ( loop , & worker_list ) {
struct worker * worker = node_to_worker ( loop ) ;
2009-01-21 13:17:11 +03:00
2009-06-04 03:44:04 +04:00
if ( worker - > pid ! = msg . pid )
continue ;
/* worker returned */
worker - > event - > exitcode = msg . exitcode ;
event_queue_delete ( worker - > event ) ;
worker - > event = NULL ;
2009-07-11 20:21:26 +04:00
if ( worker - > state ! = WORKER_KILLED )
worker - > state = WORKER_IDLE ;
2009-07-13 05:09:05 +04:00
worker_unref ( worker ) ;
2009-06-04 03:44:04 +04:00
break ;
2009-01-21 13:17:11 +03:00
}
2005-11-16 02:13:28 +03:00
}
2005-06-05 06:38:10 +04:00
}
2005-06-05 06:41:09 +04:00
/* receive the udevd message from userspace */
2008-09-08 19:59:00 +04:00
static void handle_ctrl_msg ( struct udev_ctrl * uctrl )
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
{
2008-09-08 19:59:00 +04:00
struct udev * udev = udev_ctrl_get_udev ( uctrl ) ;
struct udev_ctrl_msg * ctrl_msg ;
const char * str ;
int i ;
2004-02-12 12:23:59 +03:00
2008-09-08 19:59:00 +04:00
ctrl_msg = udev_ctrl_receive_msg ( uctrl ) ;
if ( ctrl_msg = = NULL )
2006-07-25 16:45:09 +04:00
return ;
2004-11-06 16:30:15 +03:00
2008-09-08 19:59:00 +04:00
i = udev_ctrl_get_set_log_level ( ctrl_msg ) ;
if ( i > = 0 ) {
info ( udev , " udevd message (SET_LOG_PRIORITY) received, log_priority=%i \n " , i ) ;
udev_set_log_priority ( udev , i ) ;
2009-07-11 20:21:26 +04:00
worker_kill ( udev , 0 ) ;
2004-02-12 09:32:11 +03:00
}
2008-09-08 19:59:00 +04:00
if ( udev_ctrl_get_stop_exec_queue ( ctrl_msg ) > 0 ) {
2008-09-06 17:45:31 +04:00
info ( udev , " udevd message (STOP_EXEC_QUEUE) received \n " ) ;
2009-07-13 05:33:15 +04:00
stop_exec_queue = true ;
2008-09-08 19:59:00 +04:00
}
if ( udev_ctrl_get_start_exec_queue ( ctrl_msg ) > 0 ) {
2008-09-06 17:45:31 +04:00
info ( udev , " udevd message (START_EXEC_QUEUE) received \n " ) ;
2009-07-13 05:33:15 +04:00
stop_exec_queue = false ;
2008-09-08 19:59:00 +04:00
}
if ( udev_ctrl_get_reload_rules ( ctrl_msg ) > 0 ) {
2008-09-06 17:45:31 +04:00
info ( udev , " udevd message (RELOAD_RULES) received \n " ) ;
2009-07-13 05:33:15 +04:00
reload_config = true ;
2005-06-05 06:41:09 +04:00
}
2008-09-08 19:59:00 +04:00
str = udev_ctrl_get_set_env ( ctrl_msg ) ;
if ( str ! = NULL ) {
2008-10-16 19:16:58 +04:00
char * key ;
key = strdup ( str ) ;
if ( key ! = NULL ) {
char * val ;
val = strchr ( key , ' = ' ) ;
if ( val ! = NULL ) {
val [ 0 ] = ' \0 ' ;
val = & val [ 1 ] ;
if ( val [ 0 ] = = ' \0 ' ) {
info ( udev , " udevd message (ENV) received, unset '%s' \n " , key ) ;
udev_add_property ( udev , key , NULL ) ;
} else {
info ( udev , " udevd message (ENV) received, set '%s=%s' \n " , key , val ) ;
udev_add_property ( udev , key , val ) ;
}
2008-09-08 19:59:00 +04:00
} else {
2008-10-16 19:16:58 +04:00
err ( udev , " wrong key format '%s' \n " , key ) ;
2008-09-08 19:59:00 +04:00
}
2008-10-16 19:16:58 +04:00
free ( key ) ;
2008-09-08 19:59:00 +04:00
}
2009-07-11 20:21:26 +04:00
worker_kill ( udev , 0 ) ;
2008-09-08 19:59:00 +04:00
}
2010-05-27 19:27:56 +04:00
i = udev_ctrl_get_set_children_max ( ctrl_msg ) ;
2008-09-08 19:59:00 +04:00
if ( i > = 0 ) {
2010-05-27 19:27:56 +04:00
info ( udev , " udevd message (SET_MAX_CHILDREN) received, children_max=%i \n " , i ) ;
children_max = i ;
2008-09-08 19:59:00 +04:00
}
2009-03-10 16:00:16 +03:00
settle_pid = udev_ctrl_get_settle ( ctrl_msg ) ;
if ( settle_pid > 0 ) {
info ( udev , " udevd message (SETTLE) received \n " ) ;
2009-06-04 03:44:04 +04:00
kill ( settle_pid , SIGUSR1 ) ;
settle_pid = 0 ;
2009-03-10 16:00:16 +03:00
}
2008-09-08 19:59:00 +04:00
udev_ctrl_msg_unref ( ctrl_msg ) ;
2005-06-05 06:38:10 +04:00
}
2004-11-06 16:30:15 +03:00
2009-02-11 20:38:56 +03:00
/* read inotify messages */
static int handle_inotify ( struct udev * udev )
{
2009-09-24 21:51:12 +04:00
int nbytes , pos ;
2009-02-11 20:38:56 +03:00
char * buf ;
struct inotify_event * ev ;
2009-06-04 03:44:04 +04:00
if ( ( ioctl ( pfd [ FD_INOTIFY ] . fd , FIONREAD , & nbytes ) < 0 ) | | ( nbytes < = 0 ) )
2009-02-11 20:38:56 +03:00
return 0 ;
buf = malloc ( nbytes ) ;
if ( buf = = NULL ) {
2009-06-08 19:16:48 +04:00
err ( udev , " error getting buffer for inotify \n " ) ;
2009-06-04 03:44:04 +04:00
return - 1 ;
2009-02-11 20:38:56 +03:00
}
2009-06-04 03:44:04 +04:00
nbytes = read ( pfd [ FD_INOTIFY ] . fd , buf , nbytes ) ;
2009-02-11 20:38:56 +03:00
2009-02-23 21:33:49 +03:00
for ( pos = 0 ; pos < nbytes ; pos + = sizeof ( struct inotify_event ) + ev - > len ) {
2009-02-23 20:43:53 +03:00
struct udev_device * dev ;
2009-02-11 20:38:56 +03:00
2009-02-23 21:33:49 +03:00
ev = ( struct inotify_event * ) ( buf + pos ) ;
2009-02-23 20:59:01 +03:00
if ( ev - > len ) {
2010-05-12 00:59:09 +04:00
const char * s ;
info ( udev , " inotify event: %x for %s \n " , ev - > mask , ev - > name ) ;
s = strstr ( ev - > name , " .rules " ) ;
if ( s = = NULL )
continue ;
if ( strlen ( s ) ! = strlen ( " .rules " ) )
continue ;
2009-07-13 05:33:15 +04:00
reload_config = true ;
2009-02-23 20:59:01 +03:00
continue ;
}
2009-02-23 20:43:53 +03:00
dev = udev_watch_lookup ( udev , ev - > wd ) ;
if ( dev ! = NULL ) {
2010-05-12 00:59:09 +04:00
info ( udev , " inotify event: %x for %s \n " , ev - > mask , udev_device_get_devnode ( dev ) ) ;
2009-02-11 20:38:56 +03:00
if ( ev - > mask & IN_CLOSE_WRITE ) {
char filename [ UTIL_PATH_SIZE ] ;
int fd ;
2009-02-23 20:43:53 +03:00
info ( udev , " device %s closed, synthesising 'change' \n " , udev_device_get_devnode ( dev ) ) ;
2009-05-20 19:57:52 +04:00
util_strscpyl ( filename , sizeof ( filename ) , udev_device_get_syspath ( dev ) , " /uevent " , NULL ) ;
2009-02-11 20:38:56 +03:00
fd = open ( filename , O_WRONLY ) ;
if ( fd < 0 | | write ( fd , " change " , 6 ) < 0 )
info ( udev , " error writing uevent: %m \n " ) ;
close ( fd ) ;
}
if ( ev - > mask & IN_IGNORED )
2009-02-23 20:43:53 +03:00
udev_watch_end ( udev , dev ) ;
udev_device_unref ( dev ) ;
2009-02-11 20:38:56 +03:00
}
2009-02-23 20:59:01 +03:00
2009-02-11 20:38:56 +03:00
}
2009-06-04 03:44:04 +04:00
free ( buf ) ;
2009-02-11 23:56:35 +03:00
return 0 ;
2009-02-11 20:38:56 +03:00
}
2009-06-08 19:16:48 +04:00
static void handle_signal ( struct udev * udev , int signo )
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
{
2009-06-04 03:44:04 +04:00
switch ( signo ) {
case SIGINT :
case SIGTERM :
2009-07-13 05:33:15 +04:00
udev_exit = true ;
2009-06-04 03:44:04 +04:00
break ;
case SIGCHLD :
2010-05-27 17:11:00 +04:00
for ( ; ; ) {
2009-06-04 03:44:04 +04:00
pid_t pid ;
2009-06-08 19:16:48 +04:00
int status ;
2009-06-04 03:44:04 +04:00
struct udev_list_node * loop , * tmp ;
2004-11-05 15:16:32 +03:00
2009-06-08 19:16:48 +04:00
pid = waitpid ( - 1 , & status , WNOHANG ) ;
2009-06-04 03:44:04 +04:00
if ( pid < = 0 )
break ;
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
2009-06-04 03:44:04 +04:00
udev_list_node_foreach_safe ( loop , tmp , & worker_list ) {
struct worker * worker = node_to_worker ( loop ) ;
2008-10-17 20:59:27 +04:00
2009-06-04 03:44:04 +04:00
if ( worker - > pid ! = pid )
continue ;
[PATCH] convert udevsend/udevd to DGRAM and single-threaded
On Fri, Feb 06, 2004 at 01:08:24AM -0500, Chris Friesen wrote:
>
> Kay, you said "unless we can get rid of _all_ the threads or at least
> getting faster, I don't want to change it."
>
> Well how about we get rid of all the threads, *and* we get faster?
Yes, we are twice as fast now on my box :)
> This patch applies to current bk trees, and does the following:
>
> 1) Switch to DGRAM sockets rather than STREAM. This simplifies things
> as mentioned in the previous message.
>
> 2) Invalid sequence numbers are mapped to -1 rather than zero, since
> zero is a valid sequence number (I think). Also, this allows for real
> speed tests using scripts starting at a zero sequence number, since that
> is what the initial expected sequence number is.
>
> 3) Get rid of all threading. This is the biggie. Some highlights:
> a) timeout using setitimer() and SIGALRM
> b) async child death notification via SIGCHLD
> c) these two signal handlers do nothing but raise volatile flags,
> all the
> work is done in the main loop
> d) locking no longer required
I cleaned up the rest of the comments, the whitespace and a few names to match
the whole thing. Please recheck it. Test script is switched to work on subsystem
'test' to let udev ignore it.
2004-02-07 09:21:15 +03:00
2009-07-13 05:09:05 +04:00
info ( udev , " worker [%u] exit \n " , pid ) ;
if ( ! WIFEXITED ( status ) | | WEXITSTATUS ( status ) ! = 0 ) {
2009-07-11 20:21:26 +04:00
err ( udev , " worker [%u] unexpectedly returned with status 0x%04x \n " , pid , status ) ;
2009-07-13 05:09:05 +04:00
if ( worker - > event ! = NULL ) {
err ( udev , " worker [%u] failed while handling '%s' \n " , pid , worker - > event - > devpath ) ;
worker - > event - > exitcode = - 32 ;
event_queue_delete ( worker - > event ) ;
/* drop reference from running event */
worker_unref ( worker ) ;
}
2009-06-04 03:44:04 +04:00
}
worker_unref ( worker ) ;
break ;
}
}
break ;
case SIGHUP :
2009-07-13 05:33:15 +04:00
reload_config = true ;
2009-06-04 03:44:04 +04:00
break ;
2004-04-01 11:03:07 +04:00
}
}
2010-05-20 19:09:04 +04:00
static void static_dev_create_from_modules ( struct udev * udev )
{
struct utsname kernel ;
char modules [ UTIL_PATH_SIZE ] ;
char buf [ 4096 ] ;
FILE * f ;
uname ( & kernel ) ;
util_strscpyl ( modules , sizeof ( modules ) , " /lib/modules/ " , kernel . release , " /modules.devname " , NULL ) ;
f = fopen ( modules , " r " ) ;
if ( f = = NULL )
return ;
while ( fgets ( buf , sizeof ( buf ) , f ) ! = NULL ) {
char * s ;
const char * modname ;
const char * devname ;
const char * devno ;
int maj , min ;
char type ;
mode_t mode ;
char filename [ UTIL_PATH_SIZE ] ;
if ( buf [ 0 ] = = ' # ' )
continue ;
modname = buf ;
s = strchr ( modname , ' ' ) ;
if ( s = = NULL )
continue ;
s [ 0 ] = ' \0 ' ;
devname = & s [ 1 ] ;
s = strchr ( devname , ' ' ) ;
if ( s = = NULL )
continue ;
s [ 0 ] = ' \0 ' ;
devno = & s [ 1 ] ;
s = strchr ( devno , ' ' ) ;
if ( s = = NULL )
s = strchr ( devno , ' \n ' ) ;
if ( s ! = NULL )
s [ 0 ] = ' \0 ' ;
if ( sscanf ( devno , " %c%u:%u " , & type , & maj , & min ) ! = 3 )
continue ;
if ( type = = ' c ' )
mode = 0600 | S_IFCHR ;
else if ( type = = ' b ' )
mode = 0600 | S_IFBLK ;
else
continue ;
util_strscpyl ( filename , sizeof ( filename ) , udev_get_dev_path ( udev ) , " / " , devname , NULL ) ;
util_create_path ( udev , filename ) ;
udev_selinux_setfscreatecon ( udev , filename , mode ) ;
info ( udev , " mknod '%s' %c%u:%u \n " , filename , type , maj , min ) ;
if ( mknod ( filename , mode , makedev ( maj , min ) ) < 0 & & errno = = EEXIST )
utimensat ( AT_FDCWD , filename , NULL , 0 ) ;
udev_selinux_resetfscreatecon ( udev ) ;
}
fclose ( f ) ;
}
2010-05-20 11:04:26 +04:00
static int copy_dir ( struct udev * udev , DIR * dir_from , DIR * dir_to , int maxdepth )
{
struct dirent * dent ;
for ( dent = readdir ( dir_from ) ; dent ! = NULL ; dent = readdir ( dir_from ) ) {
struct stat stats ;
if ( dent - > d_name [ 0 ] = = ' . ' )
continue ;
if ( fstatat ( dirfd ( dir_from ) , dent - > d_name , & stats , AT_SYMLINK_NOFOLLOW ) ! = 0 )
continue ;
if ( S_ISBLK ( stats . st_mode ) | | S_ISCHR ( stats . st_mode ) ) {
udev_selinux_setfscreateconat ( udev , dirfd ( dir_to ) , dent - > d_name , stats . st_mode & 0777 ) ;
if ( mknodat ( dirfd ( dir_to ) , dent - > d_name , stats . st_mode , stats . st_rdev ) = = 0 ) {
fchmodat ( dirfd ( dir_to ) , dent - > d_name , stats . st_mode & 0777 , 0 ) ;
fchownat ( dirfd ( dir_to ) , dent - > d_name , stats . st_uid , stats . st_gid , 0 ) ;
} else {
utimensat ( dirfd ( dir_to ) , dent - > d_name , NULL , 0 ) ;
}
udev_selinux_resetfscreatecon ( udev ) ;
} else if ( S_ISLNK ( stats . st_mode ) ) {
char target [ UTIL_PATH_SIZE ] ;
ssize_t len ;
len = readlinkat ( dirfd ( dir_from ) , dent - > d_name , target , sizeof ( target ) ) ;
if ( len < = 0 | | len = = ( ssize_t ) sizeof ( target ) )
continue ;
target [ len ] = ' \0 ' ;
udev_selinux_setfscreateconat ( udev , dirfd ( dir_to ) , dent - > d_name , S_IFLNK ) ;
if ( symlinkat ( target , dirfd ( dir_to ) , dent - > d_name ) < 0 & & errno = = EEXIST )
utimensat ( dirfd ( dir_to ) , dent - > d_name , NULL , AT_SYMLINK_NOFOLLOW ) ;
udev_selinux_resetfscreatecon ( udev ) ;
} else if ( S_ISDIR ( stats . st_mode ) ) {
DIR * dir2_from , * dir2_to ;
if ( maxdepth = = 0 )
continue ;
udev_selinux_setfscreateconat ( udev , dirfd ( dir_to ) , dent - > d_name , S_IFDIR | 0755 ) ;
mkdirat ( dirfd ( dir_to ) , dent - > d_name , 0755 ) ;
udev_selinux_resetfscreatecon ( udev ) ;
dir2_to = fdopendir ( openat ( dirfd ( dir_to ) , dent - > d_name , O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC ) ) ;
if ( dir2_to = = NULL )
continue ;
dir2_from = fdopendir ( openat ( dirfd ( dir_from ) , dent - > d_name , O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC ) ) ;
if ( dir2_from = = NULL ) {
closedir ( dir2_to ) ;
continue ;
}
copy_dir ( udev , dir2_from , dir2_to , maxdepth - 1 ) ;
closedir ( dir2_to ) ;
closedir ( dir2_from ) ;
}
}
return 0 ;
}
2010-05-20 19:09:04 +04:00
static void static_dev_create_links ( struct udev * udev , DIR * dir )
2010-05-20 11:04:26 +04:00
{
struct stdlinks {
const char * link ;
const char * target ;
} ;
static const struct stdlinks stdlinks [ ] = {
{ " core " , " /proc/kcore " } ,
2010-05-25 08:56:37 +04:00
{ " fd " , " /proc/self/fd " } ,
2010-05-20 11:04:26 +04:00
{ " stdin " , " /proc/self/fd/0 " } ,
{ " stdout " , " /proc/self/fd/1 " } ,
{ " stderr " , " /proc/self/fd/2 " } ,
} ;
unsigned int i ;
for ( i = 0 ; i < ARRAY_SIZE ( stdlinks ) ; i + + ) {
2010-05-20 19:09:04 +04:00
udev_selinux_setfscreateconat ( udev , dirfd ( dir ) , stdlinks [ i ] . link , S_IFLNK ) ;
if ( symlinkat ( stdlinks [ i ] . target , dirfd ( dir ) , stdlinks [ i ] . link ) < 0 & & errno = = EEXIST )
utimensat ( dirfd ( dir ) , stdlinks [ i ] . link , NULL , AT_SYMLINK_NOFOLLOW ) ;
2010-05-20 11:04:26 +04:00
udev_selinux_resetfscreatecon ( udev ) ;
}
2010-05-20 19:09:04 +04:00
}
static void static_dev_create_from_devices ( struct udev * udev , DIR * dir )
{
DIR * dir_from ;
2010-05-20 11:04:26 +04:00
dir_from = opendir ( LIBEXECDIR " /devices " ) ;
2010-05-20 19:09:04 +04:00
if ( dir_from = = NULL )
return ;
copy_dir ( udev , dir_from , dir , 8 ) ;
closedir ( dir_from ) ;
}
static void static_dev_create ( struct udev * udev )
{
DIR * dir ;
2010-05-20 11:04:26 +04:00
2010-05-20 19:09:04 +04:00
dir = opendir ( udev_get_dev_path ( udev ) ) ;
if ( dir = = NULL )
return ;
static_dev_create_links ( udev , dir ) ;
static_dev_create_from_devices ( udev , dir ) ;
closedir ( dir ) ;
2010-05-20 11:04:26 +04:00
}
static int mem_size_mb ( void )
{
FILE * f ;
char buf [ 4096 ] ;
long int memsize = - 1 ;
f = fopen ( " /proc/meminfo " , " r " ) ;
if ( f = = NULL )
return - 1 ;
while ( fgets ( buf , sizeof ( buf ) , f ) ! = NULL ) {
long int value ;
if ( sscanf ( buf , " MemTotal: %ld kB " , & value ) = = 1 ) {
memsize = value / 1024 ;
break ;
}
}
fclose ( f ) ;
return memsize ;
}
2008-09-03 01:19:36 +04:00
int main ( int argc , char * argv [ ] )
2005-01-16 06:08:54 +03:00
{
2008-09-06 17:45:31 +04:00
struct udev * udev ;
2005-11-05 21:41:00 +03:00
int fd ;
2009-12-15 18:14:14 +03:00
FILE * f ;
2009-06-04 03:44:04 +04:00
sigset_t mask ;
2009-07-13 05:33:15 +04:00
int daemonize = false ;
2009-01-21 00:33:02 +03:00
int resolve_names = 1 ;
2006-09-08 13:27:03 +04:00
static const struct option options [ ] = {
2008-10-02 18:49:05 +04:00
{ " daemon " , no_argument , NULL , ' d ' } ,
{ " debug " , no_argument , NULL , ' D ' } ,
2010-05-27 19:41:51 +04:00
{ " children-max " , required_argument , NULL , ' c ' } ,
2010-05-28 14:07:27 +04:00
{ " exec-delay " , required_argument , NULL , ' e ' } ,
2010-05-27 19:41:51 +04:00
{ " resolve-names " , required_argument , NULL , ' N ' } ,
2008-10-02 18:49:05 +04:00
{ " help " , no_argument , NULL , ' h ' } ,
{ " version " , no_argument , NULL , ' V ' } ,
2006-09-08 13:27:03 +04:00
{ }
} ;
2006-08-21 04:38:20 +04:00
int rc = 1 ;
[PATCH] udevd - cleanup and better timeout handling
On Thu, Jan 29, 2004 at 04:55:11PM +0100, Kay Sievers wrote:
> On Thu, Jan 29, 2004 at 02:56:25AM +0100, Kay Sievers wrote:
> > On Wed, Jan 28, 2004 at 10:47:36PM +0100, Kay Sievers wrote:
> > > Oh, couldn't resist to try threads.
> > > It's a multithreaded udevd that communicates through a localhost socket.
> > > The message includes a magic with the udev version, so we don't accept
> > > older udevsend's.
> > >
> > > No need for locking, cause we can't bind two sockets on the same address.
> > > The daemon tries to connect and if it fails it starts the daemon.
> > >
> > > We create a thread for every incoming connection, handle over the socket,
> > > sort the messages in the global message queue and exit the thread.
> > > Huh, that was easy with threads :)
> > >
> > > With the addition of a message we wakeup the queue manager thread and
> > > handle timeouts or move the message to the global exec list. This wakes
> > > up the exec list manager who looks if a process is already running for this
> > > device path.
> > > If yes, the exec is delayed otherwise we create a thread that execs udev.
> > > n the background. With the return of udev we free the message and wakeup
> > > the exec list manager to look if something is pending.
> > >
> > > It is just a quick shot, cause I couldn't solve the problems with fork an
> > > scheduling and I wanted to see if I'm to stupid :)
> > > But if anybody with a better idea or more experience with I/O scheduling
> > > we may go another way. The remaining problem is that klibc doesn't support
> > > threads.
> > >
> > > By now, we don't exec anything, it's just a sleep 3 for every exec,
> > > but you can see the queue management by watching syslog and do:
> > >
> > > DEVPATH=/abc ACTION=add SEQNUM=0 ./udevsend /abc
>
> Next version, switched to unix domain sockets.
Next cleaned up version. Hey, nobody wants to try it :)
Works for me, It's funny if I connect/disconnect my 4in1-usb-flash-reader
every two seconds. The 2.6 usb rocks! I can connect/diconnect a hub with 3
devices plugged in every second and don't run into any problem but a _very_
big udevd queue.
2004-02-01 20:12:36 +03:00
2008-09-06 17:45:31 +04:00
udev = udev_new ( ) ;
if ( udev = = NULL )
goto exit ;
2009-06-10 00:47:48 +04:00
udev_log_init ( " udevd " ) ;
2008-09-06 17:45:31 +04:00
udev_set_log_fn ( udev , log_fn ) ;
2008-10-16 19:16:58 +04:00
info ( udev , " version %s \n " , VERSION ) ;
2008-10-18 21:30:42 +04:00
udev_selinux_init ( udev ) ;
2004-02-02 19:19:41 +03:00
2010-05-27 17:11:00 +04:00
for ( ; ; ) {
2008-09-06 17:45:31 +04:00
int option ;
2010-05-28 14:07:27 +04:00
option = getopt_long ( argc , argv , " cdeDthV " , options , NULL ) ;
2006-09-08 13:27:03 +04:00
if ( option = = - 1 )
break ;
switch ( option ) {
case ' d ' :
2009-07-13 05:33:15 +04:00
daemonize = true ;
2006-09-08 13:27:03 +04:00
break ;
2010-05-27 19:41:51 +04:00
case ' c ' :
2010-05-28 14:07:27 +04:00
children_max = strtoul ( optarg , NULL , 0 ) ;
break ;
case ' e ' :
exec_delay = strtoul ( optarg , NULL , 0 ) ;
2006-09-08 13:30:00 +04:00
break ;
2008-04-20 23:07:06 +04:00
case ' D ' :
2009-07-13 05:33:15 +04:00
debug = true ;
2008-09-06 17:45:31 +04:00
if ( udev_get_log_priority ( udev ) < LOG_INFO )
udev_set_log_priority ( udev , LOG_INFO ) ;
2006-09-08 13:28:38 +04:00
break ;
2009-01-21 00:33:02 +03:00
case ' N ' :
if ( strcmp ( optarg , " early " ) = = 0 ) {
resolve_names = 1 ;
2009-01-21 00:36:09 +03:00
} else if ( strcmp ( optarg , " late " ) = = 0 ) {
resolve_names = 0 ;
2009-01-21 00:33:02 +03:00
} else if ( strcmp ( optarg , " never " ) = = 0 ) {
resolve_names = - 1 ;
} else {
2009-01-21 00:36:09 +03:00
fprintf ( stderr , " resolve-names must be early, late or never \n " ) ;
err ( udev , " resolve-names must be early, late or never \n " ) ;
2009-01-21 00:33:02 +03:00
goto exit ;
}
break ;
2006-09-08 13:27:03 +04:00
case ' h ' :
2010-05-28 14:07:27 +04:00
printf ( " Usage: udevd OPTIONS \n "
" --daemon \n "
" --debug \n "
" --children-max=<maximum number of workers> \n "
" --exec-delay=<seconds to wait before executing RUN=> \n "
" --resolve-names=early|late|never \n "
" --version \n "
" --help \n "
" \n " ) ;
2007-02-25 01:43:36 +03:00
goto exit ;
case ' V ' :
2008-07-30 03:45:23 +04:00
printf ( " %s \n " , VERSION ) ;
2006-08-21 04:38:20 +04:00
goto exit ;
2006-09-08 13:27:03 +04:00
default :
goto exit ;
2005-06-08 13:57:53 +04:00
}
}
2005-08-15 13:57:04 +04:00
2006-09-03 05:04:20 +04:00
if ( getuid ( ) ! = 0 ) {
fprintf ( stderr , " root privileges required \n " ) ;
2008-09-06 17:45:31 +04:00
err ( udev , " root privileges required \n " ) ;
2006-09-03 05:04:20 +04:00
goto exit ;
}
2010-05-28 14:07:27 +04:00
/*
* read the kernel commandline , in case we need to get into debug mode
* udev . log - priority = < level > syslog priority
* udev . children - max = < number of workers > events are fully serialized if set to 1
*
*/
f = fopen ( " /proc/cmdline " , " r " ) ;
if ( f ! = NULL ) {
char cmdline [ 4096 ] ;
if ( fgets ( cmdline , sizeof ( cmdline ) , f ) ! = NULL ) {
char * pos ;
pos = strstr ( cmdline , " udev.log-priority= " ) ;
if ( pos ! = NULL ) {
pos + = strlen ( " udev.log-priority= " ) ;
udev_set_log_priority ( udev , util_log_priority ( pos ) ) ;
}
pos = strstr ( cmdline , " udev.children-max= " ) ;
if ( pos ! = NULL ) {
pos + = strlen ( " udev.children-max= " ) ;
children_max = strtoul ( pos , NULL , 0 ) ;
}
pos = strstr ( cmdline , " udev.exec-delay= " ) ;
if ( pos ! = NULL ) {
pos + = strlen ( " udev.exec-delay= " ) ;
exec_delay = strtoul ( pos , NULL , 0 ) ;
}
}
fclose ( f ) ;
}
2010-05-27 19:45:58 +04:00
/* make sure std{in,out,err} fds are in a sane state */
2007-03-14 00:27:21 +03:00
fd = open ( " /dev/null " , O_RDWR ) ;
if ( fd < 0 ) {
fprintf ( stderr , " cannot open /dev/null \n " ) ;
2008-09-06 17:45:31 +04:00
err ( udev , " cannot open /dev/null \n " ) ;
2007-03-14 00:27:21 +03:00
}
if ( write ( STDOUT_FILENO , 0 , 0 ) < 0 )
dup2 ( fd , STDOUT_FILENO ) ;
if ( write ( STDERR_FILENO , 0 , 0 ) < 0 )
dup2 ( fd , STDERR_FILENO ) ;
2008-09-08 19:59:00 +04:00
udev_ctrl = udev_ctrl_new_from_socket ( udev , UDEV_CTRL_SOCK_PATH ) ;
if ( udev_ctrl = = NULL ) {
fprintf ( stderr , " error initializing control socket " ) ;
err ( udev , " error initializing udevd socket " ) ;
rc = 1 ;
goto exit ;
}
if ( udev_ctrl_enable_receiving ( udev_ctrl ) < 0 ) {
fprintf ( stderr , " error binding control socket, seems udevd is already running \n " ) ;
err ( udev , " error binding control socket, seems udevd is already running \n " ) ;
rc = 1 ;
2005-11-04 07:25:15 +03:00
goto exit ;
}
2009-06-04 03:44:04 +04:00
pfd [ FD_CONTROL ] . fd = udev_ctrl_get_fd ( udev_ctrl ) ;
2005-11-04 07:25:15 +03:00
2009-06-04 03:44:04 +04:00
monitor = udev_monitor_new_from_netlink ( udev , " kernel " ) ;
if ( monitor = = NULL | | udev_monitor_enable_receiving ( monitor ) < 0 ) {
2006-08-21 04:38:20 +04:00
fprintf ( stderr , " error initializing netlink socket \n " ) ;
2008-09-06 17:45:31 +04:00
err ( udev , " error initializing netlink socket \n " ) ;
2005-11-04 07:25:15 +03:00
rc = 3 ;
goto exit ;
}
2009-06-04 03:44:04 +04:00
udev_monitor_set_receive_buffer_size ( monitor , 128 * 1024 * 1024 ) ;
pfd [ FD_NETLINK ] . fd = udev_monitor_get_fd ( monitor ) ;
pfd [ FD_INOTIFY ] . fd = udev_watch_init ( udev ) ;
if ( pfd [ FD_INOTIFY ] . fd < 0 ) {
fprintf ( stderr , " error initializing inotify \n " ) ;
err ( udev , " error initializing inotify \n " ) ;
rc = 4 ;
goto exit ;
}
if ( udev_get_rules_path ( udev ) ! = NULL ) {
inotify_add_watch ( pfd [ FD_INOTIFY ] . fd , udev_get_rules_path ( udev ) ,
2010-01-13 15:09:02 +03:00
IN_DELETE | IN_MOVE | IN_CLOSE_WRITE ) ;
2009-06-04 03:44:04 +04:00
} else {
char filename [ UTIL_PATH_SIZE ] ;
2009-11-04 19:06:52 +03:00
struct stat statbuf ;
2009-06-04 03:44:04 +04:00
2009-06-17 04:25:07 +04:00
inotify_add_watch ( pfd [ FD_INOTIFY ] . fd , LIBEXECDIR " /rules.d " ,
2010-01-13 15:09:02 +03:00
IN_DELETE | IN_MOVE | IN_CLOSE_WRITE ) ;
2009-06-04 03:44:04 +04:00
inotify_add_watch ( pfd [ FD_INOTIFY ] . fd , SYSCONFDIR " /udev/rules.d " ,
2010-01-13 15:09:02 +03:00
IN_DELETE | IN_MOVE | IN_CLOSE_WRITE ) ;
2009-06-04 03:44:04 +04:00
/* watch dynamic rules directory */
util_strscpyl ( filename , sizeof ( filename ) , udev_get_dev_path ( udev ) , " /.udev/rules.d " , NULL ) ;
2009-11-04 19:06:52 +03:00
if ( stat ( filename , & statbuf ) ! = 0 ) {
util_create_path ( udev , filename ) ;
udev_selinux_setfscreatecon ( udev , filename , S_IFDIR | 0755 ) ;
mkdir ( filename , 0755 ) ;
udev_selinux_resetfscreatecon ( udev ) ;
}
2009-06-04 03:44:04 +04:00
inotify_add_watch ( pfd [ FD_INOTIFY ] . fd , filename ,
2010-01-13 15:09:02 +03:00
IN_DELETE | IN_MOVE | IN_CLOSE_WRITE ) ;
2009-06-04 03:44:04 +04:00
}
udev_watch_restore ( udev ) ;
/* block and listen to all signals on signalfd */
sigfillset ( & mask ) ;
2009-09-05 11:48:23 +04:00
sigprocmask ( SIG_SETMASK , & mask , & orig_sigmask ) ;
2009-06-04 03:44:04 +04:00
pfd [ FD_SIGNAL ] . fd = signalfd ( - 1 , & mask , 0 ) ;
if ( pfd [ FD_SIGNAL ] . fd < 0 ) {
fprintf ( stderr , " error getting signalfd \n " ) ;
err ( udev , " error getting signalfd \n " ) ;
rc = 5 ;
goto exit ;
}
/* unnamed socket from workers to the main daemon */
2009-10-30 14:31:59 +03:00
if ( socketpair ( AF_LOCAL , SOCK_DGRAM | SOCK_CLOEXEC , 0 , worker_watch ) < 0 ) {
2009-06-04 03:44:04 +04:00
fprintf ( stderr , " error getting socketpair \n " ) ;
err ( udev , " error getting socketpair \n " ) ;
rc = 6 ;
goto exit ;
}
pfd [ FD_WORKER ] . fd = worker_watch [ READ_END ] ;
2005-11-04 07:25:15 +03:00
2009-01-21 00:33:02 +03:00
rules = udev_rules_new ( udev , resolve_names ) ;
2008-10-18 17:02:01 +04:00
if ( rules = = NULL ) {
err ( udev , " error reading rules \n " ) ;
goto exit ;
}
2009-06-04 03:44:04 +04:00
2009-05-22 00:22:37 +04:00
udev_queue_export = udev_queue_export_new ( udev ) ;
if ( udev_queue_export = = NULL ) {
err ( udev , " error creating queue file \n " ) ;
goto exit ;
}
2006-04-25 20:50:56 +04:00
2005-06-08 13:57:53 +04:00
if ( daemonize ) {
2005-01-16 06:06:22 +03:00
pid_t pid ;
pid = fork ( ) ;
switch ( pid ) {
case 0 :
break ;
case - 1 :
2008-09-29 19:01:32 +04:00
err ( udev , " fork of daemon failed: %m \n " ) ;
2005-11-04 07:25:15 +03:00
rc = 4 ;
2005-01-16 06:06:22 +03:00
goto exit ;
default :
2006-08-23 01:20:15 +04:00
rc = 0 ;
2005-11-04 07:25:15 +03:00
goto exit ;
2005-01-16 06:06:22 +03:00
}
}
2009-12-15 18:14:14 +03:00
f = fopen ( " /dev/kmsg " , " w " ) ;
if ( f ! = NULL ) {
fprintf ( f , " <6>udev: starting version " VERSION " \n " ) ;
fclose ( f ) ;
}
2009-06-04 03:44:04 +04:00
2010-05-27 19:41:51 +04:00
if ( ! debug ) {
2008-10-29 19:32:13 +03:00
dup2 ( fd , STDIN_FILENO ) ;
2007-03-14 00:27:21 +03:00
dup2 ( fd , STDOUT_FILENO ) ;
2008-09-08 19:59:00 +04:00
dup2 ( fd , STDERR_FILENO ) ;
}
2007-03-14 00:27:21 +03:00
if ( fd > STDERR_FILENO )
close ( fd ) ;
2006-08-21 04:38:20 +04:00
2010-05-27 19:45:58 +04:00
/* set scheduling priority for the main daemon process */
2005-01-17 02:53:08 +03:00
setpriority ( PRIO_PROCESS , 0 , UDEVD_PRIORITY ) ;
2005-11-05 21:41:00 +03:00
chdir ( " / " ) ;
2005-11-06 00:02:21 +03:00
umask ( 022 ) ;
2008-09-09 17:14:38 +04:00
setsid ( ) ;
2005-11-05 21:41:00 +03:00
/* OOM_DISABLE == -17 */
fd = open ( " /proc/self/oom_adj " , O_RDWR ) ;
2009-06-08 19:16:48 +04:00
if ( fd < 0 ) {
2008-09-29 19:01:32 +04:00
err ( udev , " error disabling OOM: %m \n " ) ;
2009-06-08 19:16:48 +04:00
} else {
2005-11-05 21:41:00 +03:00
write ( fd , " -17 " , 3 ) ;
close ( fd ) ;
}
2010-05-27 19:41:51 +04:00
if ( children_max < = 0 ) {
2010-05-28 14:07:27 +04:00
int memsize = mem_size_mb ( ) ;
/* set value depending on the amount of RAM */
if ( memsize > 0 )
children_max = 128 + ( memsize / 8 ) ;
else
children_max = 128 ;
2010-05-27 19:41:51 +04:00
}
info ( udev , " set children_max to %u \n " , children_max ) ;
2005-06-05 06:53:17 +04:00
2010-05-20 19:09:04 +04:00
static_dev_create ( udev ) ;
static_dev_create_from_modules ( udev ) ;
udev_rules_apply_static_dev_perms ( rules ) ;
2009-06-04 03:44:04 +04:00
udev_list_init ( & event_list ) ;
udev_list_init ( & worker_list ) ;
2005-08-08 07:07:36 +04:00
while ( ! udev_exit ) {
2009-01-21 13:09:27 +03:00
int fdcount ;
2009-06-04 03:44:04 +04:00
int timeout ;
2009-01-20 14:49:20 +03:00
2009-06-04 03:44:04 +04:00
/* set timeout to kill idle workers */
2010-05-27 19:27:56 +04:00
if ( udev_list_is_empty ( & event_list ) & & children > 2 )
2009-06-04 03:44:04 +04:00
timeout = 3 * 1000 ;
else
timeout = - 1 ;
/* wait for events */
fdcount = poll ( pfd , ARRAY_SIZE ( pfd ) , timeout ) ;
if ( fdcount < 0 )
continue ;
2005-01-05 07:37:50 +03:00
2009-06-04 03:44:04 +04:00
/* timeout - kill idle workers */
if ( fdcount = = 0 )
2009-07-11 20:21:26 +04:00
worker_kill ( udev , 2 ) ;
2009-01-21 13:09:27 +03:00
2009-06-04 03:44:04 +04:00
/* event has finished */
if ( pfd [ FD_WORKER ] . revents & POLLIN )
worker_returned ( ) ;
2009-01-21 13:09:27 +03:00
2009-06-04 03:44:04 +04:00
/* get kernel uevent */
if ( pfd [ FD_NETLINK ] . revents & POLLIN ) {
struct udev_device * dev ;
2009-01-20 14:49:20 +03:00
2009-06-04 03:44:04 +04:00
dev = udev_monitor_receive_device ( monitor ) ;
if ( dev ! = NULL )
event_queue_insert ( dev ) ;
else
udev_device_unref ( dev ) ;
[PATCH] convert udevsend/udevd to DGRAM and single-threaded
On Fri, Feb 06, 2004 at 01:08:24AM -0500, Chris Friesen wrote:
>
> Kay, you said "unless we can get rid of _all_ the threads or at least
> getting faster, I don't want to change it."
>
> Well how about we get rid of all the threads, *and* we get faster?
Yes, we are twice as fast now on my box :)
> This patch applies to current bk trees, and does the following:
>
> 1) Switch to DGRAM sockets rather than STREAM. This simplifies things
> as mentioned in the previous message.
>
> 2) Invalid sequence numbers are mapped to -1 rather than zero, since
> zero is a valid sequence number (I think). Also, this allows for real
> speed tests using scripts starting at a zero sequence number, since that
> is what the initial expected sequence number is.
>
> 3) Get rid of all threading. This is the biggie. Some highlights:
> a) timeout using setitimer() and SIGALRM
> b) async child death notification via SIGCHLD
> c) these two signal handlers do nothing but raise volatile flags,
> all the
> work is done in the main loop
> d) locking no longer required
I cleaned up the rest of the comments, the whitespace and a few names to match
the whole thing. Please recheck it. Test script is switched to work on subsystem
'test' to let udev ignore it.
2004-02-07 09:21:15 +03:00
}
2004-04-01 11:03:46 +04:00
2009-06-04 03:44:04 +04:00
/* start new events */
if ( ! udev_list_is_empty ( & event_list ) & & ! stop_exec_queue )
events_start ( udev ) ;
2008-10-16 19:16:58 +04:00
2009-06-04 03:44:04 +04:00
/* get signal */
if ( pfd [ FD_SIGNAL ] . revents & POLLIN ) {
struct signalfd_siginfo fdsi ;
ssize_t size ;
2008-10-16 19:16:58 +04:00
2009-06-04 03:44:04 +04:00
size = read ( pfd [ FD_SIGNAL ] . fd , & fdsi , sizeof ( struct signalfd_siginfo ) ) ;
if ( size = = sizeof ( struct signalfd_siginfo ) )
2009-06-08 19:16:48 +04:00
handle_signal ( udev , fdsi . ssi_signo ) ;
2005-01-05 07:37:50 +03:00
}
2004-04-01 11:03:46 +04:00
2009-06-04 03:44:04 +04:00
/* device node and rules directory inotify watch */
if ( pfd [ FD_INOTIFY ] . revents & POLLIN )
2009-02-11 23:56:35 +03:00
handle_inotify ( udev ) ;
2005-10-27 23:04:38 +04:00
2009-06-04 03:44:04 +04:00
/*
* get control message
*
* This needs to be after the inotify handling , to make sure ,
* that the settle signal is send back after the possibly generated
* " change " events by the inotify device node watch .
*/
if ( pfd [ FD_CONTROL ] . revents & POLLIN )
handle_ctrl_msg ( udev_ctrl ) ;
2009-01-20 14:49:20 +03:00
2006-08-21 04:38:20 +04:00
/* rules changed, set by inotify or a HUP signal */
2005-10-27 23:04:38 +04:00
if ( reload_config ) {
2008-10-18 17:02:01 +04:00
struct udev_rules * rules_new ;
2009-07-11 20:21:26 +04:00
worker_kill ( udev , 0 ) ;
2009-01-21 00:33:02 +03:00
rules_new = udev_rules_new ( udev , resolve_names ) ;
2008-10-18 17:02:01 +04:00
if ( rules_new ! = NULL ) {
udev_rules_unref ( rules ) ;
rules = rules_new ;
}
2009-06-04 03:44:04 +04:00
reload_config = 0 ;
2009-03-10 16:00:16 +03:00
}
[PATCH] udevd - cleanup and better timeout handling
On Thu, Jan 29, 2004 at 04:55:11PM +0100, Kay Sievers wrote:
> On Thu, Jan 29, 2004 at 02:56:25AM +0100, Kay Sievers wrote:
> > On Wed, Jan 28, 2004 at 10:47:36PM +0100, Kay Sievers wrote:
> > > Oh, couldn't resist to try threads.
> > > It's a multithreaded udevd that communicates through a localhost socket.
> > > The message includes a magic with the udev version, so we don't accept
> > > older udevsend's.
> > >
> > > No need for locking, cause we can't bind two sockets on the same address.
> > > The daemon tries to connect and if it fails it starts the daemon.
> > >
> > > We create a thread for every incoming connection, handle over the socket,
> > > sort the messages in the global message queue and exit the thread.
> > > Huh, that was easy with threads :)
> > >
> > > With the addition of a message we wakeup the queue manager thread and
> > > handle timeouts or move the message to the global exec list. This wakes
> > > up the exec list manager who looks if a process is already running for this
> > > device path.
> > > If yes, the exec is delayed otherwise we create a thread that execs udev.
> > > n the background. With the return of udev we free the message and wakeup
> > > the exec list manager to look if something is pending.
> > >
> > > It is just a quick shot, cause I couldn't solve the problems with fork an
> > > scheduling and I wanted to see if I'm to stupid :)
> > > But if anybody with a better idea or more experience with I/O scheduling
> > > we may go another way. The remaining problem is that klibc doesn't support
> > > threads.
> > >
> > > By now, we don't exec anything, it's just a sleep 3 for every exec,
> > > but you can see the queue management by watching syslog and do:
> > >
> > > DEVPATH=/abc ACTION=add SEQNUM=0 ./udevsend /abc
>
> Next version, switched to unix domain sockets.
Next cleaned up version. Hey, nobody wants to try it :)
Works for me, It's funny if I connect/disconnect my 4in1-usb-flash-reader
every two seconds. The 2.6 usb rocks! I can connect/diconnect a hub with 3
devices plugged in every second and don't run into any problem but a _very_
big udevd queue.
2004-02-01 20:12:36 +03:00
}
2009-06-04 03:44:04 +04:00
2009-05-22 00:22:37 +04:00
udev_queue_export_cleanup ( udev_queue_export ) ;
2006-08-21 04:38:20 +04:00
rc = 0 ;
[PATCH] udevd - cleanup and better timeout handling
On Thu, Jan 29, 2004 at 04:55:11PM +0100, Kay Sievers wrote:
> On Thu, Jan 29, 2004 at 02:56:25AM +0100, Kay Sievers wrote:
> > On Wed, Jan 28, 2004 at 10:47:36PM +0100, Kay Sievers wrote:
> > > Oh, couldn't resist to try threads.
> > > It's a multithreaded udevd that communicates through a localhost socket.
> > > The message includes a magic with the udev version, so we don't accept
> > > older udevsend's.
> > >
> > > No need for locking, cause we can't bind two sockets on the same address.
> > > The daemon tries to connect and if it fails it starts the daemon.
> > >
> > > We create a thread for every incoming connection, handle over the socket,
> > > sort the messages in the global message queue and exit the thread.
> > > Huh, that was easy with threads :)
> > >
> > > With the addition of a message we wakeup the queue manager thread and
> > > handle timeouts or move the message to the global exec list. This wakes
> > > up the exec list manager who looks if a process is already running for this
> > > device path.
> > > If yes, the exec is delayed otherwise we create a thread that execs udev.
> > > n the background. With the return of udev we free the message and wakeup
> > > the exec list manager to look if something is pending.
> > >
> > > It is just a quick shot, cause I couldn't solve the problems with fork an
> > > scheduling and I wanted to see if I'm to stupid :)
> > > But if anybody with a better idea or more experience with I/O scheduling
> > > we may go another way. The remaining problem is that klibc doesn't support
> > > threads.
> > >
> > > By now, we don't exec anything, it's just a sleep 3 for every exec,
> > > but you can see the queue management by watching syslog and do:
> > >
> > > DEVPATH=/abc ACTION=add SEQNUM=0 ./udevsend /abc
>
> Next version, switched to unix domain sockets.
Next cleaned up version. Hey, nobody wants to try it :)
Works for me, It's funny if I connect/disconnect my 4in1-usb-flash-reader
every two seconds. The 2.6 usb rocks! I can connect/diconnect a hub with 3
devices plugged in every second and don't run into any problem but a _very_
big udevd queue.
2004-02-01 20:12:36 +03:00
exit :
2009-05-22 00:22:37 +04:00
udev_queue_export_unref ( udev_queue_export ) ;
2008-10-18 17:02:01 +04:00
udev_rules_unref ( rules ) ;
2008-09-08 19:59:00 +04:00
udev_ctrl_unref ( udev_ctrl ) ;
2009-06-04 03:44:04 +04:00
if ( pfd [ FD_SIGNAL ] . fd > = 0 )
close ( pfd [ FD_SIGNAL ] . fd ) ;
if ( worker_watch [ READ_END ] > = 0 )
close ( worker_watch [ READ_END ] ) ;
if ( worker_watch [ WRITE_END ] > = 0 )
close ( worker_watch [ WRITE_END ] ) ;
udev_monitor_unref ( monitor ) ;
2008-10-18 21:30:42 +04:00
udev_selinux_exit ( udev ) ;
2008-10-02 20:48:40 +04:00
udev_unref ( udev ) ;
2009-06-10 00:47:48 +04:00
udev_log_close ( ) ;
2005-11-04 07:25:15 +03:00
return rc ;
[PATCH] spilt udev into pieces
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here is the next updated updated version to apply to the lastet udev.
I've added infrastructure for getting the state of the IPC queue in the
sender and set the program to exec by the daemon. Also the magic key id
is replaced by the usual key generation by path/nr.
It looks promising, I use it on my machine and my 4in1 USB-flash-reader
connect/disconnect emits the events "randomly" but udevd is able to
reorder it and calls our normal udev in the right order.
2004-01-23 11:28:57 +03:00
}