diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2008-04-02 04:43:25 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-04-02 04:43:25 +0200 |
commit | c7969cdbcb1f6d39177f6cc2e28597fabe186594 (patch) | |
tree | 911ae0237a456f87829aeb689f7e0be8a7b57fb4 | |
parent | c3b145a381090f18c4c5f4149e19183343880ec2 (diff) |
also accept real socket files for RUN+="socket:<path>"
-rw-r--r-- | etc/udev/rules.d/95-udev-late.rules | 2 | ||||
-rw-r--r-- | udev.7 | 9 | ||||
-rw-r--r-- | udev.xml | 8 | ||||
-rw-r--r-- | udev_rules.c | 27 | ||||
-rw-r--r-- | udevadm.8 | 11 | ||||
-rw-r--r-- | udevadm.xml | 12 | ||||
-rw-r--r-- | udevcontrol.c | 2 | ||||
-rw-r--r-- | udevd.8 | 2 | ||||
-rw-r--r-- | udevd.c | 2 | ||||
-rw-r--r-- | udevmonitor.c | 2 | ||||
-rw-r--r-- | udevtrigger.c | 18 |
11 files changed, 71 insertions, 24 deletions
diff --git a/etc/udev/rules.d/95-udev-late.rules b/etc/udev/rules.d/95-udev-late.rules index 4a015b9eed..7207081d46 100644 --- a/etc/udev/rules.d/95-udev-late.rules +++ b/etc/udev/rules.d/95-udev-late.rules @@ -4,5 +4,5 @@ ACTION=="remove", ENV{REMOVE_CMD}!="", RUN+="$env{REMOVE_CMD}" # event to be catched by udevmonitor -RUN+="socket:/org/kernel/udev/monitor" +RUN+="socket:@/org/kernel/udev/monitor" @@ -1,6 +1,6 @@ .\" Title: udev .\" Author: -.\" Generator: DocBook XSL Stylesheets v1.73.1 <http://docbook.sf.net/> +.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/> .\" Date: August 2005 .\" Manual: udev .\" Source: udev @@ -213,6 +213,9 @@ Export a variable to the environment\. Depending on the type of operator, this k \fBRUN\fR .RS 4 Add a program to the list of programs to be executed for a specific device\. This can only be used for very short running tasks\. Running an event process for a long period of time may block all further events for this or a dependent device\. Long running tasks need to be immediately detached from the event process itself\. +.sp +If the specifiefd string starts with +\fBsocket:\fR\fB\fIpath\fR\fR, all current event values will be passed to the specified socket, as a message in the same format the kernel sends an uevent\. If the first character of the specified path is an @ character, an abstract namespace socket is used, instead of an existing socket file\. .RE .PP \fBLABEL\fR @@ -409,9 +412,7 @@ The count of characters to be substituted may be limited by specifying the forma Written by Greg Kroah\-Hartman <greg@kroah\.com> and Kay Sievers -<kay\.sievers@vrfy\.org>\. With much help from Dan Stekloff -<dsteklof@us\.ibm\.com> -and many others\. +<kay\.sievers@vrfy\.org>\. With much help from Dan Stekloff and many others\. .SH "SEE ALSO" .PP \fBudevd\fR(8), @@ -333,6 +333,12 @@ event process for a long period of time may block all further events for this or a dependent device. Long running tasks need to be immediately detached from the event process itself.</para> + <para>If the specifiefd string starts with + <option>socket:<replaceable>path</replaceable></option>, all current event + values will be passed to the specified socket, as a message in the same + format the kernel sends an uevent. If the first character of the specified path + is an @ character, an abstract namespace socket is used, instead of an existing + socket file.</para> </listitem> </varlistentry> @@ -600,7 +606,7 @@ <refsect1><title>AUTHOR</title> <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from - Dan Stekloff <email>dsteklof@us.ibm.com</email> and many others.</para> + Dan Stekloff and many others.</para> </refsect1> <refsect1> diff --git a/udev_rules.c b/udev_rules.c index 1521db08de..eccea3b57c 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -455,24 +455,35 @@ static int import_parent_into_env(struct udevice *udev, const char *filter) return rc; } -static int pass_env_to_socket(const char *sockname, const char *devpath, const char *action) +static int pass_env_to_socket(const char *sockpath, const char *devpath, const char *action) { int sock; struct sockaddr_un saddr; - socklen_t addrlen; + socklen_t saddrlen; + struct stat stats; char buf[2048]; size_t bufpos = 0; int i; ssize_t count; int retval = 0; - dbg("pass environment to socket '%s'", sockname); + dbg("pass environment to socket '%s'", sockpath); sock = socket(AF_LOCAL, SOCK_DGRAM, 0); memset(&saddr, 0x00, sizeof(struct sockaddr_un)); saddr.sun_family = AF_LOCAL; - /* abstract namespace only */ - strcpy(&saddr.sun_path[1], sockname); - addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1; + if (sockpath[0] == '@') { + /* abstract namespace socket requested */ + strlcpy(&saddr.sun_path[1], &sockpath[1], sizeof(saddr.sun_path)-1); + saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]); + } else if (stat(sockpath, &stats) == 0 && S_ISSOCK(stats.st_mode)) { + /* existing socket file */ + strlcpy(saddr.sun_path, sockpath, sizeof(saddr.sun_path)); + saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path); + } else { + /* no socket file, assume abstract namespace socket */ + strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1); + saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]); + } bufpos = snprintf(buf, sizeof(buf)-1, "%s@%s", action, devpath); bufpos++; @@ -483,10 +494,10 @@ static int pass_env_to_socket(const char *sockname, const char *devpath, const c if (bufpos > sizeof(buf)) bufpos = sizeof(buf); - count = sendto(sock, &buf, bufpos, 0, (struct sockaddr *)&saddr, addrlen); + count = sendto(sock, &buf, bufpos, 0, (struct sockaddr *)&saddr, saddrlen); if (count < 0) retval = -1; - info("passed %zi bytes to socket '%s', ", count, sockname); + info("passed %zi bytes to socket '%s', ", count, sockpath); close(sock); return retval; @@ -1,6 +1,6 @@ .\" Title: udevadm .\" Author: -.\" Generator: DocBook XSL Stylesheets v1.73.1 <http://docbook.sf.net/> +.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/> .\" Date: November 2007 .\" Manual: udevadm .\" Source: udev @@ -97,7 +97,7 @@ Print help text\. .RE .SS "udevadm trigger [options]" .PP -Request kernel device uevents, usually used to replay events at system coldplug\. +Request device uevents, usually used to replay events at system coldplug\. .PP \fB\-\-verbose\fR .RS 4 @@ -138,6 +138,13 @@ Trigger events for devices with a matching sysfs attribute\. If a value is speci .RS 4 Do not trigger events for devices with a matching sysfs attribute\. If a value is specified along with the attribute name, the content of the attribute is matched against the given value using shell style pattern matching\. If no value is specified, the existence of the sysfs attribute is checked\. This option can be specified multiple times\. .RE +.PP +\fB\-\-socket\fR\fB\fIpath\fR\fR +.RS 4 +Pass the synthesized events to the specified socket, instead of triggering a global kernel event\. All available event values will be send in the same format the kernel sends an uevent, or +\fBRUN+="socket:\fR\fB\fIpath\fR\fR\fB"\fR +sends a message\. If the first character of the specified path is an @ character, an abstract namespace socket is used, instead of an existing socket file\. +.RE .SS "udevadm settle [options]" .PP Watches the udev event queue, and exits if all current events are handled\. diff --git a/udevadm.xml b/udevadm.xml index ccbeeca404..121c1401d6 100644 --- a/udevadm.xml +++ b/udevadm.xml @@ -130,7 +130,7 @@ </refsect2> <refsect2><title>udevadm trigger <optional>options</optional></title> - <para>Request kernel device uevents, usually used to replay events at system coldplug.</para> + <para>Request device uevents, usually used to replay events at system coldplug.</para> <variablelist> <varlistentry> <term><option>--verbose</option></term> @@ -188,6 +188,16 @@ of the sysfs attribute is checked. This option can be specified multiple times.</para> </listitem> </varlistentry> + <varlistentry> + <term><option>--socket<replaceable>path</replaceable></option></term> + <listitem> + <para>Pass the synthesized events to the specified socket, instead of triggering + a global kernel event. All available event values will be send in the same format + the kernel sends an uevent, or <option>RUN+="socket:<replaceable>path</replaceable>"</option> + sends a message. If the first character of the specified path is an @ character, + an abstract namespace socket is used, instead of an existing socket file.</para> + </listitem> + </varlistentry> </variablelist> </refsect2> diff --git a/udevcontrol.c b/udevcontrol.c index 2442a3e0a9..f6b5dd9053 100644 --- a/udevcontrol.c +++ b/udevcontrol.c @@ -144,7 +144,7 @@ int udevcontrol(int argc, char *argv[], char *envp[]) saddr.sun_family = AF_LOCAL; /* use abstract namespace for socket path */ strcpy(&saddr.sun_path[1], UDEVD_CTRL_SOCK_PATH); - addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1; + addrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]); retval = sendto(sock, &ctrl_msg, sizeof(ctrl_msg), 0, (struct sockaddr *)&saddr, addrlen); if (retval == -1) { @@ -1,6 +1,6 @@ .\" Title: udevd .\" Author: -.\" Generator: DocBook XSL Stylesheets v1.73.1 <http://docbook.sf.net/> +.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/> .\" Date: August 2005 .\" Manual: udevd .\" Source: udev @@ -862,7 +862,7 @@ static int init_udevd_socket(void) saddr.sun_family = AF_LOCAL; /* use abstract namespace for socket path */ strcpy(&saddr.sun_path[1], UDEVD_CTRL_SOCK_PATH); - addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1; + addrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]); udevd_sock = socket(AF_LOCAL, SOCK_DGRAM, 0); if (udevd_sock == -1) { diff --git a/udevmonitor.c b/udevmonitor.c index 75e39481a0..2430dd39a5 100644 --- a/udevmonitor.c +++ b/udevmonitor.c @@ -49,7 +49,7 @@ static int init_udev_monitor_socket(void) saddr.sun_family = AF_LOCAL; /* use abstract namespace for socket path */ strcpy(&saddr.sun_path[1], "/org/kernel/udev/monitor"); - addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1; + addrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]); udev_monitor_sock = socket(AF_LOCAL, SOCK_DGRAM, 0); if (udev_monitor_sock == -1) { diff --git a/udevtrigger.c b/udevtrigger.c index 4e3a8fab2d..e50fd4ee04 100644 --- a/udevtrigger.c +++ b/udevtrigger.c @@ -631,12 +631,24 @@ int udevtrigger(int argc, char *argv[], char *envp[]) } if (sockpath != NULL) { + struct stat stats; + sock = socket(AF_LOCAL, SOCK_DGRAM, 0); memset(&saddr, 0x00, sizeof(struct sockaddr_un)); saddr.sun_family = AF_LOCAL; - /* abstract namespace only */ - strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1); - saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1; + if (sockpath[0] == '@') { + /* abstract namespace socket requested */ + strlcpy(&saddr.sun_path[1], &sockpath[1], sizeof(saddr.sun_path)-1); + saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]); + } else if (stat(sockpath, &stats) == 0 && S_ISSOCK(stats.st_mode)) { + /* existing socket file */ + strlcpy(saddr.sun_path, sockpath, sizeof(saddr.sun_path)); + saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path); + } else { + /* no socket file, assume abstract namespace socket */ + strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1); + saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]); + } } if (failed) { |