Bug 589 - feature req: Linux uevent processing support
Summary: feature req: Linux uevent processing support
Status: RESOLVED WONTFIX
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: PC Linux
: P5 enhancement
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-02 13:59 UTC by Arkadiusz Miskiewicz
Modified: 2009-11-29 03:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arkadiusz Miskiewicz 2009-09-02 13:59:32 UTC
Please consider adding builtin commands for processing uevent support.

uevent is Linux kernel mechanism for sending notifications to userspace. It's done via netlink. This means that shell itself needs to support uevent to gather netlink notifications.

uevent start [X] - start gathering uevent messages where X is optional max number of stored events (oldest entries are dropped)

uevent get - get one gathered uevent message from shell memory [1, see below]

uevent stop - stop gathering uevent messages

uevent flush - drop all gathered messages

Example code on how to gather uevent messages:
http://lwn.net/Articles/242046/ (as you see it's done via netlink socket and you need to poll, so it has to be shell feature)

http://git.fedorahosted.org/git/?p=mkinitrd;a=blob;f=nash/uevent.c;h=a05bd9896e37d22153d32f4074b635c973b367aa;hb=HEAD
(nash is fedora shell used for initrd)

Example usage in shell script:

uevent start 1000
while [ 1 ]; do
  uevent get
  if [ -n "$UEVENTDATE" ]; then
     echo "New event gathered at $UEVENTDATE"
     echo "ACTION: $UDEVNET_ACTION"
     echo "SUBSYSTEM: $UEVENT_SUBSYSTEM"
  fi
done


1.

uevent message can look like this:

UDEV_LOG=3
ACTION=remove   
DEVPATH=/block/sdb
SUBSYSTEM=block   
DEVNAME=/dev/sdb  
DEVTYPE=disk      
PHYSDEVPATH=/devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host11/target11:0:0/11:0:0:0
PHYSDEVBUS=scsi                                                                           
PHYSDEVDRIVER=sd                                                                          
SEQNUM=3068                                                                               
MAJOR=8                                                                                   
MINOR=16                                                                                  
ID_VENDOR=Kingston                                                                        
ID_VENDOR_ENC=Kingston                                                                    
ID_VENDOR_ID=13fe                                                                         
ID_MODEL=DataTraveler_2.0                                                                 
ID_MODEL_ENC=DataTraveler\x202.0                                                          
ID_MODEL_ID=1d00                                                                          
ID_REVISION=PMAP                                                                          
ID_SERIAL=Kingston_DataTraveler_2.0_5B7A1093032E-0:0                                      
ID_SERIAL_SHORT=5B7A1093032E

so I guess "uevent get" should
- remove all UEVENT_* variables
- set all variables delivered via netlink as shell env variables but with UEVENT_ prefix (so for example we would get env vars UEVENT_BUS=scsi or UEVENT_DEVPATH=/block/sdb). Set additional UEVENTDATE=date of gathering of the event.
Comment 1 Arkadiusz Miskiewicz 2009-09-02 14:46:27 UTC
Uhm, actually that's overcomplicated.

New proposition:

ueventd [-a] /some/shell/script.sh

processes uevents and runs shell script for each event synchronously (unless -a is added - then fork script.sh and don't wait for it return)

Example usage:
ueventd /blah.sh &

uevent variables would be of course exported as shell env for blah.sh.
Comment 2 Denys Vlasenko 2009-11-29 03:35:23 UTC
Please reopen if you have a patch, or post the patch to the mailing list.