chiark / gitweb /
also accept real socket files for RUN+="socket:<path>"
authorKay Sievers <kay.sievers@vrfy.org>
Wed, 2 Apr 2008 02:43:25 +0000 (04:43 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Wed, 2 Apr 2008 02:43:25 +0000 (04:43 +0200)
etc/udev/rules.d/95-udev-late.rules
udev.7
udev.xml
udev_rules.c
udevadm.8
udevadm.xml
udevcontrol.c
udevd.8
udevd.c
udevmonitor.c
udevtrigger.c

index 4a015b9eed252fcb317010bbd27644e47e62d3b4..7207081d46dcafc3f3593e711548bb4212568a82 100644 (file)
@@ -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"
 
diff --git a/udev.7 b/udev.7
index e237ba7d46a38b46cfc1444af2f8a1bf80ff6189..3bc04b7c634860cf26b0539dfb030f6fd81ae8ec 100644 (file)
--- a/udev.7
+++ b/udev.7
@@ -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),
index 71832a2fe5977115e60497874c1a502bea12aca1..e4329653170e1921482e9510cb684f9cd7755dd5 100644 (file)
--- a/udev.xml
+++ b/udev.xml
                 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>
 
       <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>
index 1521db08def5ac5c92a66b2fce51744dedb50492..eccea3b57c75c1a4aae4db773c2bdd1e4ff78e4f 100644 (file)
@@ -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;
index acad283bc329c86ac6054a6f174321a009620ef3..0db30126bd00de711652549fe2a746405e22f8ed 100644 (file)
--- a/udevadm.8
+++ b/udevadm.8
@@ -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\.
index ccbeeca404cdb2b083745780fc2d0044463c818f..121c1401d6850a1ff0bdb6f5c15ea598e78add12 100644 (file)
         </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>
                 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>
 
index 2442a3e0a95f87f24269a5e82ca8962d640d71d7..f6b5dd905339bd64703e180945849051586dccfb 100644 (file)
@@ -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) {
diff --git a/udevd.8 b/udevd.8
index 0f0dd1ac2dccf249c1c8e7a032072baf1c6ccbc1..1323313a0dd19cb5768f6d97deb918adbbda0457 100644 (file)
--- a/udevd.8
+++ b/udevd.8
@@ -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
diff --git a/udevd.c b/udevd.c
index 82ebd22dbad1dc1891fcdc34bcbee2a5df8182d8..493bb54514ce4fa6ea16bf7b119354c409b6a788 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -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) {
index 75e39481a02a3ff3773b215a6741766745acd0e0..2430dd39a557fe1411d9b21380e501126b32ce36 100644 (file)
@@ -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) {
index 4e3a8fab2d633f84f79a36f2e4c8740b5a61cac6..e50fd4ee04e9ea4915ed9d9b0d31d605fa3941cd 100644 (file)
@@ -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) {