also accept real socket files for RUN+="socket:<path>"

This commit is contained in:
Kay Sievers 2008-04-02 04:43:25 +02:00
parent c3b145a381
commit c7969cdbcb
11 changed files with 71 additions and 24 deletions

View 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"

9
udev.7
View File

@ -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),

View File

@ -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>

View 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;

View File

@ -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\.

View File

@ -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>

View 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) {

View File

@ -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

View File

@ -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) {

View 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) {

View 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) {