2 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
3 * Copyright (C) 2003-2006 Kay Sievers <kay.sievers@vrfy.org>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include <sys/socket.h>
37 #include "udev_rules.h"
38 #include "udev_selinux.h"
40 extern char **environ;
42 /* extract possible {attr} and move str behind it */
43 static char *get_format_attribute(struct udev *udev, char **str)
49 pos = strchr(*str, '}');
51 err(udev, "missing closing brace for format\n");
57 dbg(udev, "attribute='%s', str='%s'\n", attr, *str);
62 /* extract possible format length and move str behind it*/
63 static int get_format_len(struct udev *udev, char **str)
68 if (isdigit(*str[0])) {
69 num = (int) strtoul(*str, &tail, 10);
72 dbg(udev, "format length=%i\n", num);
75 err(udev, "format parsing error '%s'\n", *str);
81 static int get_key(char **line, char **key, char **value)
91 while (isspace(linepos[0]))
95 temp = strchr(linepos, '=');
96 if (temp == NULL || temp == linepos)
102 /* get a quoted value */
103 if (linepos[0] == '"' || linepos[0] == '\'') {
104 temp = strchr(&linepos[1], linepos[0]);
107 *value = &linepos[1];
113 temp = strchr(linepos, '\n');
121 static int run_program(struct udev *udev, const char *command, const char *subsystem,
122 char *result, size_t ressize, size_t *reslen)
125 int outpipe[2] = {-1, -1};
126 int errpipe[2] = {-1, -1};
129 char program[PATH_SIZE];
130 char *argv[(sizeof(arg) / 2) + 1];
135 /* build argv from comand */
136 strlcpy(arg, command, sizeof(arg));
138 if (strchr(arg, ' ') != NULL) {
141 while (pos != NULL) {
142 if (pos[0] == '\'') {
143 /* don't separate if in apostrophes */
145 argv[i] = strsep(&pos, "\'");
146 while (pos != NULL && pos[0] == ' ')
149 argv[i] = strsep(&pos, " ");
151 dbg(udev, "arg[%i] '%s'\n", i, argv[i]);
159 info(udev, "'%s'\n", command);
161 /* prepare pipes from child to parent */
162 if (result != NULL || udev_get_log_priority(udev) >= LOG_INFO) {
163 if (pipe(outpipe) != 0) {
164 err(udev, "pipe failed: %s\n", strerror(errno));
168 if (udev_get_log_priority(udev) >= LOG_INFO) {
169 if (pipe(errpipe) != 0) {
170 err(udev, "pipe failed: %s\n", strerror(errno));
175 /* allow programs in /lib/udev called without the path */
176 if (strchr(argv[0], '/') == NULL) {
177 strlcpy(program, UDEV_PREFIX "/lib/udev/", sizeof(program));
178 strlcat(program, argv[0], sizeof(program));
185 /* child closes parent ends of pipes */
186 if (outpipe[READ_END] > 0)
187 close(outpipe[READ_END]);
188 if (errpipe[READ_END] > 0)
189 close(errpipe[READ_END]);
191 /* discard child output or connect to pipe */
192 devnull = open("/dev/null", O_RDWR);
194 dup2(devnull, STDIN_FILENO);
195 if (outpipe[WRITE_END] < 0)
196 dup2(devnull, STDOUT_FILENO);
197 if (errpipe[WRITE_END] < 0)
198 dup2(devnull, STDERR_FILENO);
201 err(udev, "open /dev/null failed: %s\n", strerror(errno));
202 if (outpipe[WRITE_END] > 0) {
203 dup2(outpipe[WRITE_END], STDOUT_FILENO);
204 close(outpipe[WRITE_END]);
206 if (errpipe[WRITE_END] > 0) {
207 dup2(errpipe[WRITE_END], STDERR_FILENO);
208 close(errpipe[WRITE_END]);
210 execv(argv[0], argv);
211 if (errno == ENOENT || errno == ENOTDIR) {
212 /* may be on a filesytem which is not mounted right now */
213 info(udev, "program '%s' not found\n", argv[0]);
216 err(udev, "exec of program '%s' failed\n", argv[0]);
220 err(udev, "fork of '%s' failed: %s\n", argv[0], strerror(errno));
223 /* read from child if requested */
224 if (outpipe[READ_END] > 0 || errpipe[READ_END] > 0) {
228 /* parent closes child ends of pipes */
229 if (outpipe[WRITE_END] > 0)
230 close(outpipe[WRITE_END]);
231 if (errpipe[WRITE_END] > 0)
232 close(errpipe[WRITE_END]);
234 /* read child output */
235 while (outpipe[READ_END] > 0 || errpipe[READ_END] > 0) {
240 if (outpipe[READ_END] > 0)
241 FD_SET(outpipe[READ_END], &readfds);
242 if (errpipe[READ_END] > 0)
243 FD_SET(errpipe[READ_END], &readfds);
244 fdcount = select(UDEV_MAX(outpipe[READ_END], errpipe[READ_END])+1, &readfds, NULL, NULL, NULL);
253 if (outpipe[READ_END] > 0 && FD_ISSET(outpipe[READ_END], &readfds)) {
258 count = read(outpipe[READ_END], inbuf, sizeof(inbuf)-1);
260 close(outpipe[READ_END]);
261 outpipe[READ_END] = -1;
263 err(udev, "stdin read failed: %s\n", strerror(errno));
270 /* store result for rule processing */
272 if (respos + count < ressize) {
273 memcpy(&result[respos], inbuf, count);
276 err(udev, "ressize %ld too short\n", (long)ressize);
281 while ((line = strsep(&pos, "\n")))
282 if (pos || line[0] != '\0')
283 info(udev, "'%s' (stdout) '%s'\n", argv[0], line);
287 if (errpipe[READ_END] > 0 && FD_ISSET(errpipe[READ_END], &readfds)) {
292 count = read(errpipe[READ_END], errbuf, sizeof(errbuf)-1);
294 close(errpipe[READ_END]);
295 errpipe[READ_END] = -1;
297 err(udev, "stderr read failed: %s\n", strerror(errno));
300 errbuf[count] = '\0';
302 while ((line = strsep(&pos, "\n")))
303 if (pos || line[0] != '\0')
304 info(udev, "'%s' (stderr) '%s'\n", argv[0], line);
307 if (outpipe[READ_END] > 0)
308 close(outpipe[READ_END]);
309 if (errpipe[READ_END] > 0)
310 close(errpipe[READ_END]);
312 /* return the childs stdout string */
314 result[respos] = '\0';
315 dbg(udev, "result='%s'\n", result);
320 waitpid(pid, &status, 0);
321 if (WIFEXITED(status)) {
322 info(udev, "'%s' returned with status %i\n", argv[0], WEXITSTATUS(status));
323 if (WEXITSTATUS(status) != 0)
326 err(udev, "'%s' abnormal exit\n", argv[0]);
334 static int import_keys_into_env(struct udevice *udevice, const char *buf, size_t bufsize)
336 char line[LINE_SIZE];
345 /* loop through the whole buffer */
348 while (cur < bufsize) {
349 count = buf_get_line(buf, bufsize, cur);
354 /* eat the whitespace */
355 while ((count > 0) && isspace(bufline[0])) {
362 /* see if this is a comment */
363 if (bufline[0] == COMMENT_CHARACTER)
366 if (count >= sizeof(line)) {
367 err(udevice->udev, "line too long, skipped\n");
371 memcpy(line, bufline, count);
375 if (get_key(&linepos, &variable, &value) == 0) {
376 dbg(udevice->udev, "import '%s=%s'\n", variable, value);
378 /* handle device, renamed by external tool, returning new path */
379 if (strcmp(variable, "DEVPATH") == 0) {
380 info(udevice->udev, "updating devpath from '%s' to '%s'\n", udevice->dev->devpath, value);
381 sysfs_device_set_values(udevice->udev, udevice->dev, value, NULL, NULL);
383 name_list_key_add(udevice->udev, &udevice->env_list, variable, value);
384 setenv(variable, value, 1);
391 static int import_file_into_env(struct udevice *udevice, const char *filename)
396 if (file_map(filename, &buf, &bufsize) != 0) {
397 err(udevice->udev, "can't open '%s': %s\n", filename, strerror(errno));
400 import_keys_into_env(udevice, buf, bufsize);
401 file_unmap(buf, bufsize);
406 static int import_program_into_env(struct udevice *udevice, const char *program)
411 if (run_program(udevice->udev, program, udevice->dev->subsystem, result, sizeof(result), &reslen) != 0)
413 return import_keys_into_env(udevice, result, reslen);
416 static int import_parent_into_env(struct udevice *udevice, const char *filter)
418 struct sysfs_device *dev_parent;
421 dev_parent = sysfs_device_get_parent(udevice->udev, udevice->dev);
422 if (dev_parent != NULL) {
423 struct udevice *udev_parent;
424 struct name_entry *name_loop;
426 dbg(udevice->udev, "found parent '%s', get the node name\n", dev_parent->devpath);
427 udev_parent = udev_device_init(udevice->udev);
428 if (udev_parent == NULL)
430 /* import the udev_db of the parent */
431 if (udev_db_get_device(udev_parent, dev_parent->devpath) == 0) {
432 dbg(udevice->udev, "import stored parent env '%s'\n", udev_parent->name);
433 list_for_each_entry(name_loop, &udev_parent->env_list, node) {
434 char name[NAME_SIZE];
437 strlcpy(name, name_loop->name, sizeof(name));
438 pos = strchr(name, '=');
442 if (fnmatch(filter, name, 0) == 0) {
443 dbg(udevice->udev, "import key '%s'\n", name_loop->name);
444 name_list_add(udevice->udev, &udevice->env_list, name_loop->name, 0);
445 setenv(name, pos, 1);
447 dbg(udevice->udev, "skip key '%s'\n", name_loop->name);
452 dbg(udevice->udev, "parent not found in database\n");
453 udev_device_cleanup(udev_parent);
459 static int pass_env_to_socket(struct udev *udev, const char *sockpath, const char *devpath, const char *action)
462 struct sockaddr_un saddr;
471 dbg(udev, "pass environment to socket '%s'\n", sockpath);
472 sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
473 memset(&saddr, 0x00, sizeof(struct sockaddr_un));
474 saddr.sun_family = AF_LOCAL;
475 if (sockpath[0] == '@') {
476 /* abstract namespace socket requested */
477 strlcpy(&saddr.sun_path[1], &sockpath[1], sizeof(saddr.sun_path)-1);
478 saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
479 } else if (stat(sockpath, &stats) == 0 && S_ISSOCK(stats.st_mode)) {
480 /* existing socket file */
481 strlcpy(saddr.sun_path, sockpath, sizeof(saddr.sun_path));
482 saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path);
484 /* no socket file, assume abstract namespace socket */
485 strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1);
486 saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
489 bufpos = snprintf(buf, sizeof(buf)-1, "%s@%s", action, devpath);
491 for (i = 0; environ[i] != NULL && bufpos < (sizeof(buf)-1); i++) {
492 bufpos += strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos-1);
495 if (bufpos > sizeof(buf))
496 bufpos = sizeof(buf);
498 count = sendto(sock, &buf, bufpos, 0, (struct sockaddr *)&saddr, saddrlen);
501 info(udev, "passed %zi bytes to socket '%s', \n", count, sockpath);
507 int udev_rules_run(struct udevice *udevice)
509 struct name_entry *name_loop;
512 dbg(udevice->udev, "executing run list\n");
513 list_for_each_entry(name_loop, &udevice->run_list, node) {
514 if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0) {
515 pass_env_to_socket(udevice->udev, &name_loop->name[strlen("socket:")], udevice->dev->devpath, udevice->action);
517 char program[PATH_SIZE];
519 strlcpy(program, name_loop->name, sizeof(program));
520 udev_rules_apply_format(udevice, program, sizeof(program));
521 if (run_program(udevice->udev, program, udevice->dev->subsystem, NULL, 0, NULL) != 0)
522 if (!name_loop->ignore_error)
530 #define WAIT_LOOP_PER_SECOND 50
531 static int wait_for_file(struct udevice *udevice, const char *file, int timeout)
533 char filepath[PATH_SIZE];
534 char devicepath[PATH_SIZE] = "";
536 int loop = timeout * WAIT_LOOP_PER_SECOND;
538 /* a relative path is a device attribute */
539 if (file[0] != '/') {
540 strlcpy(devicepath, udev_get_sys_path(udevice->udev), sizeof(devicepath));
541 strlcat(devicepath, udevice->dev->devpath, sizeof(devicepath));
543 strlcpy(filepath, devicepath, sizeof(filepath));
544 strlcat(filepath, "/", sizeof(filepath));
545 strlcat(filepath, file, sizeof(filepath));
549 dbg(udevice->udev, "will wait %i sec for '%s'\n", timeout, file);
552 if (stat(file, &stats) == 0) {
553 info(udevice->udev, "file '%s' appeared after %i loops\n", file, (timeout * WAIT_LOOP_PER_SECOND) - loop-1);
556 /* make sure, the device did not disappear in the meantime */
557 if (devicepath[0] != '\0' && stat(devicepath, &stats) != 0) {
558 info(udevice->udev, "device disappeared while waiting for '%s'\n", file);
561 info(udevice->udev, "wait for '%s' for %i mseconds\n", file, 1000 / WAIT_LOOP_PER_SECOND);
562 usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND);
564 info(udevice->udev, "waiting for '%s' failed\n", file);
568 /* handle "[$SUBSYSTEM/$KERNEL]<attribute>" lookup */
569 static int attr_get_by_subsys_id(struct udev *udev, const char *attrstr, char *devpath, size_t len, char **attr)
571 char subsys[NAME_SIZE];
577 if (attrstr[0] != '[')
580 attrib = strchr(&attrstr[1], ']');
585 strlcpy(subsys, &attrstr[1], sizeof(subsys));
586 pos = strchr(subsys, ']');
590 id = strchr(subsys, '/');
595 if (sysfs_lookup_devpath_by_subsys_id(udev, devpath, len, subsys, id)) {
597 if (attrib[0] != '\0')
608 static int attr_subst_subdir(char *attr, size_t len)
613 pos = strstr(attr, "/*/");
619 strlcpy(str, &pos[2], sizeof(str));
624 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
627 if (dent->d_name[0] == '.')
629 strlcat(attr, dent->d_name, len);
630 strlcat(attr, str, len);
631 if (stat(attr, &stats) == 0) {
640 strlcat(attr, str, len);
646 void udev_rules_apply_format(struct udevice *udevice, char *string, size_t maxsize)
648 char temp[PATH_SIZE];
649 char temp2[PATH_SIZE];
650 char *head, *tail, *pos, *cpos, *attr, *rest;
673 static const struct subst_map {
676 enum subst_type type;
678 { .name = "devpath", .fmt = 'p', .type = SUBST_DEVPATH },
679 { .name = "number", .fmt = 'n', .type = SUBST_KERNEL_NUMBER },
680 { .name = "kernel", .fmt = 'k', .type = SUBST_KERNEL },
681 { .name = "id", .fmt = 'b', .type = SUBST_ID },
682 { .name = "driver", .fmt = 'd', .type = SUBST_DRIVER },
683 { .name = "major", .fmt = 'M', .type = SUBST_MAJOR },
684 { .name = "minor", .fmt = 'm', .type = SUBST_MINOR },
685 { .name = "result", .fmt = 'c', .type = SUBST_RESULT },
686 { .name = "attr", .fmt = 's', .type = SUBST_ATTR },
687 { .name = "sysfs", .fmt = 's', .type = SUBST_ATTR },
688 { .name = "parent", .fmt = 'P', .type = SUBST_PARENT },
689 { .name = "tempnode", .fmt = 'N', .type = SUBST_TEMP_NODE },
690 { .name = "name", .fmt = 'D', .type = SUBST_NAME },
691 { .name = "links", .fmt = 'L', .type = SUBST_LINKS },
692 { .name = "root", .fmt = 'r', .type = SUBST_ROOT },
693 { .name = "sys", .fmt = 'S', .type = SUBST_SYS },
694 { .name = "env", .fmt = 'E', .type = SUBST_ENV },
697 enum subst_type type;
698 const struct subst_map *subst;
703 while (head[0] != '\0') {
704 if (head[0] == '$') {
705 /* substitute named variable */
708 if (head[1] == '$') {
709 strlcpy(temp, head+2, sizeof(temp));
710 strlcpy(head+1, temp, maxsize);
715 for (subst = map; subst->name; subst++) {
716 if (strncasecmp(&head[1], subst->name, strlen(subst->name)) == 0) {
718 tail = head + strlen(subst->name)+1;
719 dbg(udevice->udev, "will substitute format name '%s'\n", subst->name);
724 err(udevice->udev, "unknown format variable '%s'\n", head);
725 } else if (head[0] == '%') {
726 /* substitute format char */
729 if (head[1] == '%') {
730 strlcpy(temp, head+2, sizeof(temp));
731 strlcpy(head+1, temp, maxsize);
737 len = get_format_len(udevice->udev, &tail);
738 for (subst = map; subst->name; subst++) {
739 if (tail[0] == subst->fmt) {
742 dbg(udevice->udev, "will substitute format char '%c'\n", subst->fmt);
747 err(udevice->udev, "unknown format char '%c'\n", tail[0]);
753 attr = get_format_attribute(udevice->udev, &tail);
754 strlcpy(temp, tail, sizeof(temp));
755 dbg(udevice->udev, "format=%i, string='%s', tail='%s'\n", type ,string, tail);
759 strlcat(string, udevice->dev->devpath, maxsize);
760 dbg(udevice->udev, "substitute devpath '%s'\n", udevice->dev->devpath);
763 strlcat(string, udevice->dev->kernel, maxsize);
764 dbg(udevice->udev, "substitute kernel name '%s'\n", udevice->dev->kernel);
766 case SUBST_KERNEL_NUMBER:
767 strlcat(string, udevice->dev->kernel_number, maxsize);
768 dbg(udevice->udev, "substitute kernel number '%s'\n", udevice->dev->kernel_number);
771 if (udevice->dev_parent != NULL) {
772 strlcat(string, udevice->dev_parent->kernel, maxsize);
773 dbg(udevice->udev, "substitute id '%s'\n", udevice->dev_parent->kernel);
777 if (udevice->dev_parent != NULL) {
778 strlcat(string, udevice->dev_parent->driver, maxsize);
779 dbg(udevice->udev, "substitute driver '%s'\n", udevice->dev_parent->driver);
783 sprintf(temp2, "%d", major(udevice->devt));
784 strlcat(string, temp2, maxsize);
785 dbg(udevice->udev, "substitute major number '%s'\n", temp2);
788 sprintf(temp2, "%d", minor(udevice->devt));
789 strlcat(string, temp2, maxsize);
790 dbg(udevice->udev, "substitute minor number '%s'\n", temp2);
793 if (udevice->program_result[0] == '\0')
795 /* get part part of the result string */
798 i = strtoul(attr, &rest, 10);
800 dbg(udevice->udev, "request part #%d of result string\n", i);
801 cpos = udevice->program_result;
803 while (cpos[0] != '\0' && !isspace(cpos[0]))
805 while (isspace(cpos[0]))
809 err(udevice->udev, "requested part of result string not found\n");
812 strlcpy(temp2, cpos, sizeof(temp2));
813 /* %{2+}c copies the whole string from the second part on */
814 if (rest[0] != '+') {
815 cpos = strchr(temp2, ' ');
819 strlcat(string, temp2, maxsize);
820 dbg(udevice->udev, "substitute part of result string '%s'\n", temp2);
822 strlcat(string, udevice->program_result, maxsize);
823 dbg(udevice->udev, "substitute result string '%s'\n", udevice->program_result);
828 err(udevice->udev, "missing file parameter for attr\n");
830 char devpath[PATH_SIZE];
832 const char *value = NULL;
835 if (attr_get_by_subsys_id(udevice->udev, attr, devpath, sizeof(devpath), &attrib)) {
837 value = sysfs_attr_get_value(udevice->udev, devpath, attrib);
842 /* try the current device, other matches may have selected */
843 if (value == NULL && udevice->dev_parent != NULL && udevice->dev_parent != udevice->dev)
844 value = sysfs_attr_get_value(udevice->udev, udevice->dev_parent->devpath, attr);
846 /* look at all devices along the chain of parents */
848 struct sysfs_device *dev_parent = udevice->dev;
851 dbg(udevice->udev, "looking at '%s'\n", dev_parent->devpath);
852 value = sysfs_attr_get_value(udevice->udev, dev_parent->devpath, attr);
855 dev_parent = sysfs_device_get_parent(udevice->udev, dev_parent);
856 } while (dev_parent != NULL);
862 /* strip trailing whitespace, and replace unwanted characters */
863 size = strlcpy(temp2, value, sizeof(temp2));
864 if (size >= sizeof(temp2))
865 size = sizeof(temp2)-1;
866 while (size > 0 && isspace(temp2[size-1]))
867 temp2[--size] = '\0';
868 count = replace_chars(temp2, ALLOWED_CHARS_INPUT);
870 info(udevice->udev, "%i character(s) replaced\n" , count);
871 strlcat(string, temp2, maxsize);
872 dbg(udevice->udev, "substitute sysfs value '%s'\n", temp2);
877 struct sysfs_device *dev_parent;
879 dev_parent = sysfs_device_get_parent(udevice->udev, udevice->dev);
880 if (dev_parent != NULL) {
881 struct udevice *udev_parent;
883 dbg(udevice->udev, "found parent '%s', get the node name\n", dev_parent->devpath);
884 udev_parent = udev_device_init(udevice->udev);
885 if (udev_parent != NULL) {
886 /* lookup the name in the udev_db with the DEVPATH of the parent */
887 if (udev_db_get_device(udev_parent, dev_parent->devpath) == 0) {
888 strlcat(string, udev_parent->name, maxsize);
889 dbg(udevice->udev, "substitute parent node name'%s'\n", udev_parent->name);
891 dbg(udevice->udev, "parent not found in database\n");
892 udev_device_cleanup(udev_parent);
897 case SUBST_TEMP_NODE:
898 if (udevice->tmp_node[0] == '\0' && major(udevice->devt) > 0) {
899 dbg(udevice->udev, "create temporary device node for callout\n");
900 snprintf(udevice->tmp_node, sizeof(udevice->tmp_node), "%s/.tmp-%u-%u",
901 udev_get_dev_path(udevice->udev), major(udevice->devt), minor(udevice->devt));
902 udevice->tmp_node[sizeof(udevice->tmp_node)-1] = '\0';
903 udev_node_mknod(udevice, udevice->tmp_node, udevice->devt, 0600, 0, 0);
905 strlcat(string, udevice->tmp_node, maxsize);
906 dbg(udevice->udev, "substitute temporary device node name '%s'\n", udevice->tmp_node);
909 if (udevice->name[0] == '\0') {
910 strlcat(string, udevice->dev->kernel, maxsize);
911 dbg(udevice->udev, "substitute udevice->kernel '%s'\n", udevice->name);
913 strlcat(string, udevice->name, maxsize);
914 dbg(udevice->udev, "substitute udevice->name '%s'\n", udevice->name);
918 if (!list_empty(&udevice->symlink_list)) {
919 struct name_entry *name_loop;
920 char symlinks[PATH_SIZE] = "";
922 list_for_each_entry(name_loop, &udevice->symlink_list, node) {
923 strlcat(symlinks, name_loop->name, sizeof(symlinks));
924 strlcat(symlinks, " ", sizeof(symlinks));
926 remove_trailing_chars(symlinks, ' ');
927 strlcat(string, symlinks, maxsize);
931 strlcat(string, udev_get_dev_path(udevice->udev), maxsize);
932 dbg(udevice->udev, "substitute udev_root '%s'\n", udev_get_dev_path(udevice->udev));
935 strlcat(string, udev_get_sys_path(udevice->udev), maxsize);
936 dbg(udevice->udev, "substitute sys_path '%s'\n", udev_get_sys_path(udevice->udev));
940 dbg(udevice->udev, "missing attribute\n");
945 dbg(udevice->udev, "env '%s' not available\n", attr);
948 dbg(udevice->udev, "substitute env '%s=%s'\n", attr, pos);
949 strlcat(string, pos, maxsize);
952 err(udevice->udev, "unknown substitution type=%i\n", type);
955 /* possibly truncate to format-char specified length */
956 if (len >= 0 && len < (int)strlen(head)) {
958 dbg(udevice->udev, "truncate to %i chars, subtitution string becomes '%s'\n", len, head);
960 strlcat(string, temp, maxsize);
964 static char *key_val(struct udev_rule *rule, struct key *key)
966 return rule->buf + key->val_off;
969 static char *key_pair_name(struct udev_rule *rule, struct key_pair *pair)
971 return rule->buf + pair->key_name_off;
974 static int match_key(struct udev *udev, const char *key_name, struct udev_rule *rule, struct key *key, const char *val)
976 char value[PATH_SIZE];
981 if (key->operation != KEY_OP_MATCH &&
982 key->operation != KEY_OP_NOMATCH)
985 /* look for a matching string, parts are separated by '|' */
986 strlcpy(value, rule->buf + key->val_off, sizeof(value));
988 dbg(udev, "key %s value='%s'\n", key_name, key_value);
990 pos = strchr(key_value, '|');
996 dbg(udev, "match %s '%s' <-> '%s'\n", key_name, key_value, val);
997 match = (fnmatch(key_value, val, 0) == 0);
1004 if (match && (key->operation == KEY_OP_MATCH)) {
1005 dbg(udev, "%s is true (matching value)\n", key_name);
1008 if (!match && (key->operation == KEY_OP_NOMATCH)) {
1009 dbg(udev, "%s is true (non-matching value)\n", key_name);
1015 /* match a single rule against a given device and possibly its parent devices */
1016 static int match_rule(struct udevice *udevice, struct udev_rule *rule)
1020 if (match_key(udevice->udev, "ACTION", rule, &rule->action, udevice->action))
1023 if (match_key(udevice->udev, "KERNEL", rule, &rule->kernel, udevice->dev->kernel))
1026 if (match_key(udevice->udev, "SUBSYSTEM", rule, &rule->subsystem, udevice->dev->subsystem))
1029 if (match_key(udevice->udev, "DEVPATH", rule, &rule->devpath, udevice->dev->devpath))
1032 if (match_key(udevice->udev, "DRIVER", rule, &rule->driver, udevice->dev->driver))
1035 /* match NAME against a value assigned by an earlier rule */
1036 if (match_key(udevice->udev, "NAME", rule, &rule->name, udevice->name))
1039 /* match against current list of symlinks */
1040 if (rule->symlink_match.operation == KEY_OP_MATCH ||
1041 rule->symlink_match.operation == KEY_OP_NOMATCH) {
1042 struct name_entry *name_loop;
1045 list_for_each_entry(name_loop, &udevice->symlink_list, node) {
1046 if (match_key(udevice->udev, "SYMLINK", rule, &rule->symlink_match, name_loop->name) == 0) {
1055 for (i = 0; i < rule->env.count; i++) {
1056 struct key_pair *pair = &rule->env.keys[i];
1058 /* we only check for matches, assignments will be handled later */
1059 if (pair->key.operation == KEY_OP_MATCH ||
1060 pair->key.operation == KEY_OP_NOMATCH) {
1061 const char *key_name = key_pair_name(rule, pair);
1062 const char *value = getenv(key_name);
1065 dbg(udevice->udev, "ENV{'%s'} is not set, treat as empty\n", key_name);
1068 if (match_key(udevice->udev, "ENV", rule, &pair->key, value))
1073 if (rule->test.operation == KEY_OP_MATCH ||
1074 rule->test.operation == KEY_OP_NOMATCH) {
1075 char filename[PATH_SIZE];
1076 char devpath[PATH_SIZE];
1078 struct stat statbuf;
1081 strlcpy(filename, key_val(rule, &rule->test), sizeof(filename));
1082 udev_rules_apply_format(udevice, filename, sizeof(filename));
1084 if (attr_get_by_subsys_id(udevice->udev, filename, devpath, sizeof(devpath), &attr)) {
1085 strlcpy(filename, udev_get_sys_path(udevice->udev), sizeof(filename));
1086 strlcat(filename, devpath, sizeof(filename));
1088 strlcat(filename, "/", sizeof(filename));
1089 strlcat(filename, attr, sizeof(filename));
1091 } else if (filename[0] != '/') {
1092 char tmp[PATH_SIZE];
1094 strlcpy(tmp, udev_get_sys_path(udevice->udev), sizeof(tmp));
1095 strlcat(tmp, udevice->dev->devpath, sizeof(tmp));
1096 strlcat(tmp, "/", sizeof(tmp));
1097 strlcat(tmp, filename, sizeof(tmp));
1098 strlcpy(filename, tmp, sizeof(filename));
1101 attr_subst_subdir(filename, sizeof(filename));
1103 match = (stat(filename, &statbuf) == 0);
1104 info(udevice->udev, "'%s' %s", filename, match ? "exists\n" : "does not exist\n");
1105 if (match && rule->test_mode_mask > 0) {
1106 match = ((statbuf.st_mode & rule->test_mode_mask) > 0);
1107 info(udevice->udev, "'%s' has mode=%#o and %s %#o\n", filename, statbuf.st_mode,
1108 match ? "matches" : "does not match",
1109 rule->test_mode_mask);
1111 if (match && rule->test.operation == KEY_OP_NOMATCH)
1113 if (!match && rule->test.operation == KEY_OP_MATCH)
1115 dbg(udevice->udev, "TEST key is true\n");
1118 if (rule->wait_for.operation != KEY_OP_UNSET) {
1119 char filename[PATH_SIZE];
1122 strlcpy(filename, key_val(rule, &rule->wait_for), sizeof(filename));
1123 udev_rules_apply_format(udevice, filename, sizeof(filename));
1124 found = (wait_for_file(udevice, filename, 10) == 0);
1125 if (!found && (rule->wait_for.operation != KEY_OP_NOMATCH))
1129 /* check for matching sysfs attribute pairs */
1130 for (i = 0; i < rule->attr.count; i++) {
1131 struct key_pair *pair = &rule->attr.keys[i];
1133 if (pair->key.operation == KEY_OP_MATCH ||
1134 pair->key.operation == KEY_OP_NOMATCH) {
1135 const char *key_name = key_pair_name(rule, pair);
1136 const char *key_value = key_val(rule, &pair->key);
1137 char devpath[PATH_SIZE];
1139 const char *value = NULL;
1140 char val[VALUE_SIZE];
1143 if (attr_get_by_subsys_id(udevice->udev, key_name, devpath, sizeof(devpath), &attrib)) {
1145 value = sysfs_attr_get_value(udevice->udev, devpath, attrib);
1150 value = sysfs_attr_get_value(udevice->udev, udevice->dev->devpath, key_name);
1153 strlcpy(val, value, sizeof(val));
1155 /* strip trailing whitespace of value, if not asked to match for it */
1156 len = strlen(key_value);
1157 if (len > 0 && !isspace(key_value[len-1])) {
1159 while (len > 0 && isspace(val[len-1]))
1161 dbg(udevice->udev, "removed %zi trailing whitespace chars from '%s'\n", strlen(val)-len, val);
1164 if (match_key(udevice->udev, "ATTR", rule, &pair->key, val))
1169 /* walk up the chain of parent devices and find a match */
1170 udevice->dev_parent = udevice->dev;
1172 /* check for matching kernel device name */
1173 if (match_key(udevice->udev, "KERNELS", rule, &rule->kernels, udevice->dev_parent->kernel))
1176 /* check for matching subsystem value */
1177 if (match_key(udevice->udev, "SUBSYSTEMS", rule, &rule->subsystems, udevice->dev_parent->subsystem))
1180 /* check for matching driver */
1181 if (match_key(udevice->udev, "DRIVERS", rule, &rule->drivers, udevice->dev_parent->driver))
1184 /* check for matching sysfs attribute pairs */
1185 for (i = 0; i < rule->attrs.count; i++) {
1186 struct key_pair *pair = &rule->attrs.keys[i];
1188 if (pair->key.operation == KEY_OP_MATCH ||
1189 pair->key.operation == KEY_OP_NOMATCH) {
1190 const char *key_name = key_pair_name(rule, pair);
1191 const char *key_value = key_val(rule, &pair->key);
1193 char val[VALUE_SIZE];
1196 value = sysfs_attr_get_value(udevice->udev, udevice->dev_parent->devpath, key_name);
1198 value = sysfs_attr_get_value(udevice->udev, udevice->dev->devpath, key_name);
1201 strlcpy(val, value, sizeof(val));
1203 /* strip trailing whitespace of value, if not asked to match for it */
1204 len = strlen(key_value);
1205 if (len > 0 && !isspace(key_value[len-1])) {
1207 while (len > 0 && isspace(val[len-1]))
1209 dbg(udevice->udev, "removed %zi trailing whitespace chars from '%s'\n", strlen(val)-len, val);
1212 if (match_key(udevice->udev, "ATTRS", rule, &pair->key, val))
1217 /* found matching device */
1220 /* move to parent device */
1221 dbg(udevice->udev, "try parent sysfs device\n");
1222 udevice->dev_parent = sysfs_device_get_parent(udevice->udev, udevice->dev_parent);
1223 if (udevice->dev_parent == NULL)
1225 dbg(udevice->udev, "looking at dev_parent->devpath='%s'\n", udevice->dev_parent->devpath);
1226 dbg(udevice->udev, "looking at dev_parent->kernel='%s'\n", udevice->dev_parent->kernel);
1229 /* execute external program */
1230 if (rule->program.operation != KEY_OP_UNSET) {
1231 char program[PATH_SIZE];
1232 char result[PATH_SIZE];
1234 strlcpy(program, key_val(rule, &rule->program), sizeof(program));
1235 udev_rules_apply_format(udevice, program, sizeof(program));
1236 if (run_program(udevice->udev, program, udevice->dev->subsystem, result, sizeof(result), NULL) != 0) {
1237 dbg(udevice->udev, "PROGRAM is false\n");
1238 udevice->program_result[0] = '\0';
1239 if (rule->program.operation != KEY_OP_NOMATCH)
1244 dbg(udevice->udev, "PROGRAM matches\n");
1245 remove_trailing_chars(result, '\n');
1246 if (rule->string_escape == ESCAPE_UNSET ||
1247 rule->string_escape == ESCAPE_REPLACE) {
1248 count = replace_chars(result, ALLOWED_CHARS_INPUT);
1250 info(udevice->udev, "%i character(s) replaced\n" , count);
1252 dbg(udevice->udev, "result is '%s'\n", result);
1253 strlcpy(udevice->program_result, result, sizeof(udevice->program_result));
1254 dbg(udevice->udev, "PROGRAM returned successful\n");
1255 if (rule->program.operation == KEY_OP_NOMATCH)
1258 dbg(udevice->udev, "PROGRAM key is true\n");
1261 /* check for matching result of external program */
1262 if (match_key(udevice->udev, "RESULT", rule, &rule->result, udevice->program_result))
1265 /* import variables returned from program or or file into environment */
1266 if (rule->import.operation != KEY_OP_UNSET) {
1267 char import[PATH_SIZE];
1270 strlcpy(import, key_val(rule, &rule->import), sizeof(import));
1271 udev_rules_apply_format(udevice, import, sizeof(import));
1272 dbg(udevice->udev, "check for IMPORT import='%s'\n", import);
1273 if (rule->import_type == IMPORT_PROGRAM) {
1274 rc = import_program_into_env(udevice, import);
1275 } else if (rule->import_type == IMPORT_FILE) {
1276 dbg(udevice->udev, "import file import='%s'\n", import);
1277 rc = import_file_into_env(udevice, import);
1278 } else if (rule->import_type == IMPORT_PARENT) {
1279 dbg(udevice->udev, "import parent import='%s'\n", import);
1280 rc = import_parent_into_env(udevice, import);
1283 dbg(udevice->udev, "IMPORT failed\n");
1284 if (rule->import.operation != KEY_OP_NOMATCH)
1287 dbg(udevice->udev, "IMPORT '%s' imported\n", key_val(rule, &rule->import));
1288 dbg(udevice->udev, "IMPORT key is true\n");
1291 /* rule matches, if we have ENV assignments export it */
1292 for (i = 0; i < rule->env.count; i++) {
1293 struct key_pair *pair = &rule->env.keys[i];
1295 if (pair->key.operation == KEY_OP_ASSIGN) {
1296 char temp_value[NAME_SIZE];
1297 const char *key_name = key_pair_name(rule, pair);
1298 const char *value = key_val(rule, &pair->key);
1300 /* make sure we don't write to the same string we possibly read from */
1301 strlcpy(temp_value, value, sizeof(temp_value));
1302 udev_rules_apply_format(udevice, temp_value, NAME_SIZE);
1304 if (temp_value[0] == '\0') {
1305 name_list_key_remove(udevice->udev, &udevice->env_list, key_name);
1307 info(udevice->udev, "unset ENV '%s'\n", key_name);
1309 struct name_entry *entry;
1311 entry = name_list_key_add(udevice->udev, &udevice->env_list, key_name, temp_value);
1314 putenv(entry->name);
1315 info(udevice->udev, "set ENV '%s'\n", entry->name);
1320 /* if we have ATTR assignments, write value to sysfs file */
1321 for (i = 0; i < rule->attr.count; i++) {
1322 struct key_pair *pair = &rule->attr.keys[i];
1324 if (pair->key.operation == KEY_OP_ASSIGN) {
1325 const char *key_name = key_pair_name(rule, pair);
1326 char devpath[PATH_SIZE];
1328 char attr[PATH_SIZE] = "";
1329 char value[NAME_SIZE];
1332 if (attr_get_by_subsys_id(udevice->udev, key_name, devpath, sizeof(devpath), &attrib)) {
1333 if (attrib != NULL) {
1334 strlcpy(attr, udev_get_sys_path(udevice->udev), sizeof(attr));
1335 strlcat(attr, devpath, sizeof(attr));
1336 strlcat(attr, "/", sizeof(attr));
1337 strlcat(attr, attrib, sizeof(attr));
1341 if (attr[0] == '\0') {
1342 strlcpy(attr, udev_get_sys_path(udevice->udev), sizeof(attr));
1343 strlcat(attr, udevice->dev->devpath, sizeof(attr));
1344 strlcat(attr, "/", sizeof(attr));
1345 strlcat(attr, key_name, sizeof(attr));
1348 attr_subst_subdir(attr, sizeof(attr));
1350 strlcpy(value, key_val(rule, &pair->key), sizeof(value));
1351 udev_rules_apply_format(udevice, value, sizeof(value));
1352 info(udevice->udev, "writing '%s' to sysfs file '%s'\n", value, attr);
1353 f = fopen(attr, "w");
1355 if (!udevice->test_run)
1356 if (fprintf(f, "%s", value) <= 0)
1357 err(udevice->udev, "error writing ATTR{%s}: %s\n", attr, strerror(errno));
1360 err(udevice->udev, "error opening ATTR{%s} for writing: %s\n", attr, strerror(errno));
1369 int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice)
1371 struct udev_rules_iter iter;
1372 struct udev_rule *rule;
1375 dbg(udevice->udev, "udevice->dev->devpath='%s'\n", udevice->dev->devpath);
1376 dbg(udevice->udev, "udevice->dev->kernel='%s'\n", udevice->dev->kernel);
1378 /* look for a matching rule to apply */
1379 udev_rules_iter_init(&iter, rules);
1381 rule = udev_rules_iter_next(&iter);
1386 (rule->name.operation == KEY_OP_ASSIGN ||
1387 rule->name.operation == KEY_OP_ASSIGN_FINAL ||
1388 rule->name.operation == KEY_OP_ADD)) {
1389 dbg(udevice->udev, "node name already set, rule ignored\n");
1393 dbg(udevice->udev, "process rule\n");
1394 if (match_rule(udevice, rule) == 0) {
1396 if (rule->ignore_device) {
1397 info(udevice->udev, "rule applied, '%s' is ignored\n", udevice->dev->kernel);
1398 udevice->ignore_device = 1;
1401 if (rule->ignore_remove) {
1402 udevice->ignore_remove = 1;
1403 dbg(udevice->udev, "remove event should be ignored\n");
1405 if (rule->link_priority != 0) {
1406 udevice->link_priority = rule->link_priority;
1407 info(udevice->udev, "link_priority=%i\n", udevice->link_priority);
1409 if (rule->event_timeout >= 0) {
1410 udevice->event_timeout = rule->event_timeout;
1411 info(udevice->udev, "event_timeout=%i\n", udevice->event_timeout);
1413 /* apply all_partitions option only at a main block device */
1414 if (rule->partitions &&
1415 strcmp(udevice->dev->subsystem, "block") == 0 && udevice->dev->kernel_number[0] == '\0') {
1416 udevice->partitions = rule->partitions;
1417 dbg(udevice->udev, "creation of partition nodes requested\n");
1420 /* apply permissions */
1421 if (!udevice->mode_final && rule->mode.operation != KEY_OP_UNSET) {
1422 if (rule->mode.operation == KEY_OP_ASSIGN_FINAL)
1423 udevice->mode_final = 1;
1425 strlcpy(buf, key_val(rule, &rule->mode), sizeof(buf));
1426 udev_rules_apply_format(udevice, buf, sizeof(buf));
1427 udevice->mode = strtol(buf, NULL, 8);
1428 dbg(udevice->udev, "applied mode=%#o to '%s'\n", udevice->mode, udevice->dev->kernel);
1430 if (!udevice->owner_final && rule->owner.operation != KEY_OP_UNSET) {
1431 if (rule->owner.operation == KEY_OP_ASSIGN_FINAL)
1432 udevice->owner_final = 1;
1433 strlcpy(udevice->owner, key_val(rule, &rule->owner), sizeof(udevice->owner));
1434 udev_rules_apply_format(udevice, udevice->owner, sizeof(udevice->owner));
1435 dbg(udevice->udev, "applied owner='%s' to '%s'\n", udevice->owner, udevice->dev->kernel);
1437 if (!udevice->group_final && rule->group.operation != KEY_OP_UNSET) {
1438 if (rule->group.operation == KEY_OP_ASSIGN_FINAL)
1439 udevice->group_final = 1;
1440 strlcpy(udevice->group, key_val(rule, &rule->group), sizeof(udevice->group));
1441 udev_rules_apply_format(udevice, udevice->group, sizeof(udevice->group));
1442 dbg(udevice->udev, "applied group='%s' to '%s'\n", udevice->group, udevice->dev->kernel);
1445 /* collect symlinks */
1446 if (!udevice->symlink_final &&
1447 (rule->symlink.operation == KEY_OP_ASSIGN ||
1448 rule->symlink.operation == KEY_OP_ASSIGN_FINAL ||
1449 rule->symlink.operation == KEY_OP_ADD)) {
1450 char temp[PATH_SIZE];
1454 if (rule->symlink.operation == KEY_OP_ASSIGN_FINAL)
1455 udevice->symlink_final = 1;
1456 if (rule->symlink.operation == KEY_OP_ASSIGN ||
1457 rule->symlink.operation == KEY_OP_ASSIGN_FINAL) {
1458 info(udevice->udev, "reset symlink list\n");
1459 name_list_cleanup(udevice->udev, &udevice->symlink_list);
1461 /* allow multiple symlinks separated by spaces */
1462 strlcpy(temp, key_val(rule, &rule->symlink), sizeof(temp));
1463 udev_rules_apply_format(udevice, temp, sizeof(temp));
1464 if (rule->string_escape == ESCAPE_UNSET ||
1465 rule->string_escape == ESCAPE_REPLACE) {
1466 count = replace_chars(temp, ALLOWED_CHARS_FILE " ");
1468 info(udevice->udev, "%i character(s) replaced\n" , count);
1470 dbg(udevice->udev, "rule applied, added symlink(s) '%s'\n", temp);
1472 while (isspace(pos[0]))
1474 next = strchr(pos, ' ');
1477 info(udevice->udev, "add symlink '%s'\n", pos);
1478 name_list_add(udevice->udev, &udevice->symlink_list, pos, 0);
1479 while (isspace(next[1]))
1482 next = strchr(pos, ' ');
1484 if (pos[0] != '\0') {
1485 info(udevice->udev, "add symlink '%s'\n", pos);
1486 name_list_add(udevice->udev, &udevice->symlink_list, pos, 0);
1490 /* set name, later rules with name set will be ignored */
1491 if (rule->name.operation == KEY_OP_ASSIGN ||
1492 rule->name.operation == KEY_OP_ASSIGN_FINAL ||
1493 rule->name.operation == KEY_OP_ADD) {
1497 strlcpy(udevice->name, key_val(rule, &rule->name), sizeof(udevice->name));
1498 udev_rules_apply_format(udevice, udevice->name, sizeof(udevice->name));
1499 if (rule->string_escape == ESCAPE_UNSET ||
1500 rule->string_escape == ESCAPE_REPLACE) {
1501 count = replace_chars(udevice->name, ALLOWED_CHARS_FILE);
1503 info(udevice->udev, "%i character(s) replaced\n", count);
1506 info(udevice->udev, "rule applied, '%s' becomes '%s'\n", udevice->dev->kernel, udevice->name);
1507 if (strcmp(udevice->dev->subsystem, "net") != 0)
1508 dbg(udevice->udev, "name, '%s' is going to have owner='%s', group='%s', mode=%#o partitions=%i\n",
1509 udevice->name, udevice->owner, udevice->group, udevice->mode, udevice->partitions);
1512 if (!udevice->run_final && rule->run.operation != KEY_OP_UNSET) {
1513 struct name_entry *entry;
1515 if (rule->run.operation == KEY_OP_ASSIGN_FINAL)
1516 udevice->run_final = 1;
1517 if (rule->run.operation == KEY_OP_ASSIGN || rule->run.operation == KEY_OP_ASSIGN_FINAL) {
1518 info(udevice->udev, "reset run list\n");
1519 name_list_cleanup(udevice->udev, &udevice->run_list);
1521 dbg(udevice->udev, "add run '%s'\n", key_val(rule, &rule->run));
1522 entry = name_list_add(udevice->udev, &udevice->run_list, key_val(rule, &rule->run), 0);
1523 if (rule->run_ignore_error)
1524 entry->ignore_error = 1;
1527 if (rule->last_rule) {
1528 dbg(udevice->udev, "last rule to be applied\n");
1532 if (rule->goto_label.operation != KEY_OP_UNSET) {
1533 dbg(udevice->udev, "moving forward to label '%s'\n", key_val(rule, &rule->goto_label));
1534 udev_rules_iter_label(&iter, key_val(rule, &rule->goto_label));
1540 info(udevice->udev, "no node name set, will use kernel name '%s'\n", udevice->dev->kernel);
1541 strlcpy(udevice->name, udevice->dev->kernel, sizeof(udevice->name));
1544 if (udevice->tmp_node[0] != '\0') {
1545 dbg(udevice->udev, "removing temporary device node\n");
1546 unlink_secure(udevice->udev, udevice->tmp_node);
1547 udevice->tmp_node[0] = '\0';
1553 int udev_rules_get_run(struct udev_rules *rules, struct udevice *udevice)
1555 struct udev_rules_iter iter;
1556 struct udev_rule *rule;
1558 dbg(udevice->udev, "udevice->kernel='%s'\n", udevice->dev->kernel);
1560 /* look for a matching rule to apply */
1561 udev_rules_iter_init(&iter, rules);
1563 rule = udev_rules_iter_next(&iter);
1567 dbg(udevice->udev, "process rule\n");
1568 if (rule->name.operation == KEY_OP_ASSIGN ||
1569 rule->name.operation == KEY_OP_ASSIGN_FINAL ||
1570 rule->name.operation == KEY_OP_ADD ||
1571 rule->symlink.operation == KEY_OP_ASSIGN ||
1572 rule->symlink.operation == KEY_OP_ASSIGN_FINAL ||
1573 rule->symlink.operation == KEY_OP_ADD ||
1574 rule->mode.operation != KEY_OP_UNSET ||
1575 rule->owner.operation != KEY_OP_UNSET || rule->group.operation != KEY_OP_UNSET) {
1576 dbg(udevice->udev, "skip rule that names a device\n");
1580 if (match_rule(udevice, rule) == 0) {
1581 if (rule->ignore_device) {
1582 info(udevice->udev, "rule applied, '%s' is ignored\n", udevice->dev->kernel);
1583 udevice->ignore_device = 1;
1586 if (rule->ignore_remove) {
1587 udevice->ignore_remove = 1;
1588 dbg(udevice->udev, "remove event should be ignored\n");
1591 if (!udevice->run_final && rule->run.operation != KEY_OP_UNSET) {
1592 struct name_entry *entry;
1594 if (rule->run.operation == KEY_OP_ASSIGN ||
1595 rule->run.operation == KEY_OP_ASSIGN_FINAL) {
1596 info(udevice->udev, "reset run list\n");
1597 name_list_cleanup(udevice->udev, &udevice->run_list);
1599 dbg(udevice->udev, "add run '%s'\n", key_val(rule, &rule->run));
1600 entry = name_list_add(udevice->udev, &udevice->run_list, key_val(rule, &rule->run), 0);
1601 if (rule->run_ignore_error)
1602 entry->ignore_error = 1;
1603 if (rule->run.operation == KEY_OP_ASSIGN_FINAL)
1607 if (rule->last_rule) {
1608 dbg(udevice->udev, "last rule to be applied\n");
1612 if (rule->goto_label.operation != KEY_OP_UNSET) {
1613 dbg(udevice->udev, "moving forward to label '%s'\n", key_val(rule, &rule->goto_label));
1614 udev_rules_iter_label(&iter, key_val(rule, &rule->goto_label));