6 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
7 * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation version 2 of the License.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
35 #include "libsysfs/sysfs/libsysfs.h"
37 #include "udev_libc_wrapper.h"
39 #include "udev_utils.h"
40 #include "udev_version.h"
42 #include "udev_rules.h"
46 /* compare string with pattern (supports * ? [0-9] [!A-Z]) */
47 static int strcmp_pattern(const char *p, const char *s)
52 return (p[0] != '\0');
63 while ((p[0] != '\0') && (p[0] != ']')) {
66 if ((s[0] >= p[0]) && (s[0] <= p[2]))
70 match = (p[0] == s[0]);
74 while ((p[0] != '\0') && (p[0] != ']'))
77 return strcmp_pattern(p+1, s+1);
83 if (strcmp_pattern(p, s+1))
84 return strcmp_pattern(p+1, s);
92 if ((p[0] == s[0]) || (p[0] == '?'))
93 return strcmp_pattern(p+1, s+1);
99 /* extract possible {attr} and move str behind it */
100 static char *get_format_attribute(char **str)
105 if (*str[0] == '{') {
106 pos = strchr(*str, '}');
108 err("missing closing brace for format");
114 dbg("attribute='%s', str='%s'", attr, *str);
119 /* extract possible format length and move str behind it*/
120 static int get_format_len(char **str)
125 if (isdigit(*str[0])) {
126 num = (int) strtoul(*str, &tail, 10);
129 dbg("format length=%i", num);
132 err("format parsing error '%s'", *str);
138 /** Finds the lowest positive N such that <name>N isn't present in
139 * $(udevroot) either as a file or a symlink.
141 * @param name Name to check for
142 * @return 0 if <name> didn't exist and N otherwise.
144 static int find_free_number(struct udevice *udev, const char *name)
146 char devpath[PATH_SIZE];
147 char filename[PATH_SIZE];
150 strlcpy(filename, name, sizeof(filename));
152 dbg("look for existing node '%s'", filename);
153 if (udev_db_search_name(devpath, sizeof(devpath), filename) != 0) {
154 dbg("free num=%d", num);
160 info("find_free_number gone crazy (num=%d), aborted", num);
163 snprintf(filename, sizeof(filename), "%s%d", name, num);
164 filename[sizeof(filename)-1] = '\0';
168 static int find_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device,
169 const char *name, char *value, size_t len)
171 struct sysfs_attribute *tmpattr;
173 dbg("look for device attribute '%s'", name);
175 tmpattr = sysfs_get_classdev_attr(class_dev, name);
180 tmpattr = sysfs_get_device_attr(sysfs_device, name);
188 strlcpy(value, tmpattr->value, len);
189 remove_trailing_char(value, '\n');
191 dbg("found attribute '%s'", tmpattr->path);
195 static void apply_format(struct udevice *udev, char *string, size_t maxsize,
196 struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
198 char temp[PATH_SIZE];
199 char temp2[PATH_SIZE];
200 char *tail, *pos, *cpos, *attr, *rest;
204 unsigned int next_free_number;
205 struct sysfs_class_device *class_dev_parent;
209 pos = strchr(pos, '%');
215 len = get_format_len(&tail);
217 strlcpy(temp, tail+1, sizeof(temp));
219 dbg("format=%c, string='%s', tail='%s'",c , string, tail);
220 attr = get_format_attribute(&tail);
224 strlcat(string, udev->devpath, maxsize);
225 dbg("substitute kernel name '%s'", udev->kernel_name);
228 strlcat(string, udev->bus_id, maxsize);
229 dbg("substitute bus_id '%s'", udev->bus_id);
232 strlcat(string, udev->kernel_name, maxsize);
233 dbg("substitute kernel name '%s'", udev->kernel_name);
236 strlcat(string, udev->kernel_number, maxsize);
237 dbg("substitute kernel number '%s'", udev->kernel_number);
240 sprintf(temp2, "%d", minor(udev->devt));
241 strlcat(string, temp2, maxsize);
242 dbg("substitute minor number '%s'", temp2);
245 sprintf(temp2, "%d", major(udev->devt));
246 strlcat(string, temp2, maxsize);
247 dbg("substitute major number '%s'", temp2);
250 if (udev->program_result[0] == '\0')
252 /* get part part of the result string */
255 i = strtoul(attr, &rest, 10);
257 dbg("request part #%d of result string", i);
258 cpos = udev->program_result;
260 while (cpos[0] != '\0' && !isspace(cpos[0]))
262 while (isspace(cpos[0]))
266 err("requested part of result string not found");
269 strlcpy(temp2, cpos, sizeof(temp2));
270 /* %{2+}c copies the whole string from the second part on */
271 if (rest[0] != '+') {
272 cpos = strchr(temp2, ' ');
276 strlcat(string, temp2, maxsize);
277 dbg("substitute part of result string '%s'", temp2);
279 strlcat(string, udev->program_result, maxsize);
280 dbg("substitute result string '%s'", udev->program_result);
285 dbg("missing attribute");
288 if (find_sysfs_attribute(class_dev, sysfs_device, attr, temp2, sizeof(temp2)) != 0) {
289 struct sysfs_device *parent_device;
291 dbg("sysfs attribute '%s' not found, walk up the physical devices", attr);
292 parent_device = sysfs_get_device_parent(sysfs_device);
293 while (parent_device) {
294 dbg("looking at '%s'", parent_device->path);
295 if (find_sysfs_attribute(NULL, parent_device, attr, temp2, sizeof(temp2)) == 0)
297 parent_device = sysfs_get_device_parent(parent_device);
302 /* strip trailing whitespace of sysfs value */
304 while (i > 0 && isspace(temp2[i-1]))
306 replace_untrusted_chars(temp2);
307 strlcat(string, temp2, maxsize);
308 dbg("substitute sysfs value '%s'", temp2);
311 strlcat(string, "%", maxsize);
315 next_free_number = find_free_number(udev, string);
316 if (next_free_number > 0) {
317 sprintf(temp2, "%d", next_free_number);
318 strlcat(string, temp2, maxsize);
324 class_dev_parent = sysfs_get_classdev_parent(class_dev);
325 if (class_dev_parent != NULL) {
326 struct udevice udev_parent;
328 dbg("found parent '%s', get the node name", class_dev_parent->path);
329 udev_init_device(&udev_parent, NULL, NULL, NULL);
330 /* lookup the name in the udev_db with the DEVPATH of the parent */
331 if (udev_db_get_device(&udev_parent, &class_dev_parent->path[strlen(sysfs_path)]) == 0) {
332 strlcat(string, udev_parent.name, maxsize);
333 dbg("substitute parent node name'%s'", udev_parent.name);
335 dbg("parent not found in database");
336 udev_cleanup_device(&udev_parent);
340 if (udev->tmp_node[0] == '\0') {
341 dbg("create temporary device node for callout");
342 snprintf(udev->tmp_node, sizeof(udev->tmp_node), "%s/.tmp-%u-%u",
343 udev_root, major(udev->devt), minor(udev->devt));
344 udev->tmp_node[sizeof(udev->tmp_node)-1] = '\0';
345 udev_make_node(udev, udev->tmp_node, udev->devt, 0600, 0, 0);
347 strlcat(string, udev->tmp_node, maxsize);
348 dbg("substitute temporary device node name '%s'", udev->tmp_node);
351 strlcat(string, udev_root, maxsize);
352 dbg("substitute udev_root '%s'", udev_root);
355 err("unknown substitution type '%%%c'", c);
358 /* truncate to specified length */
362 strlcat(string, tail, maxsize);
366 static int execute_program_pipe(const char *command, const char *subsystem, char *value, int len)
375 char *argv[(sizeof(arg) / 2) + 1];
379 strlcpy(arg, command, sizeof(arg));
381 if (strchr(arg, ' ')) {
383 while (pos != NULL) {
384 if (pos[0] == '\'') {
385 /* don't separate if in apostrophes */
387 argv[i] = strsep(&pos, "\'");
388 while (pos && pos[0] == ' ')
391 argv[i] = strsep(&pos, " ");
393 dbg("arg[%i] '%s'", i, argv[i]);
397 dbg("execute '%s' with parsed arguments", arg);
400 argv[1] = (char *) subsystem;
402 dbg("execute '%s' with subsystem '%s' argument", arg, argv[1]);
405 retval = pipe(pipefds);
414 /* child dup2 write side of pipe to STDOUT */
415 devnull = open("/dev/null", O_RDWR);
417 dup2(devnull, STDIN_FILENO);
418 dup2(devnull, STDERR_FILENO);
421 dup2(pipefds[1], STDOUT_FILENO);
422 retval = execv(arg, argv);
423 err("exec of program failed");
426 err("fork of '%s' failed", arg);
430 /* parent reads from pipefds[0] */
435 count = read(pipefds[0], value + i, len - i-1);
437 err("read failed with '%s'", strerror(errno));
446 err("result len %d too short", len);
454 waitpid(pid, &status, 0);
456 if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
457 dbg("exec program status 0x%x", status);
463 remove_trailing_char(value, '\n');
464 dbg("result is '%s'", value);
465 replace_untrusted_chars(value);
472 static int match_rule(struct udevice *udev, struct udev_rule *rule,
473 struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
475 struct sysfs_device *parent_device = sysfs_device;
477 if (rule->action_operation != KEY_OP_UNSET) {
478 dbg("check for " KEY_ACTION " rule->action='%s' udev->action='%s'",
479 rule->action, udev->action);
480 if (strcmp_pattern(rule->action, udev->action) != 0) {
481 dbg(KEY_ACTION " is not matching");
482 if (rule->action_operation != KEY_OP_NOMATCH)
485 dbg(KEY_ACTION " matches");
486 if (rule->action_operation == KEY_OP_NOMATCH)
489 dbg(KEY_ACTION " key is true");
492 if (rule->kernel_operation != KEY_OP_UNSET) {
493 dbg("check for " KEY_KERNEL " rule->kernel='%s' udev_kernel_name='%s'",
494 rule->kernel, udev->kernel_name);
495 if (strcmp_pattern(rule->kernel, udev->kernel_name) != 0) {
496 dbg(KEY_KERNEL " is not matching");
497 if (rule->kernel_operation != KEY_OP_NOMATCH)
500 dbg(KEY_KERNEL " matches");
501 if (rule->kernel_operation == KEY_OP_NOMATCH)
504 dbg(KEY_KERNEL " key is true");
507 if (rule->subsystem_operation != KEY_OP_UNSET) {
508 dbg("check for " KEY_SUBSYSTEM " rule->subsystem='%s' udev->subsystem='%s'",
509 rule->subsystem, udev->subsystem);
510 if (strcmp_pattern(rule->subsystem, udev->subsystem) != 0) {
511 dbg(KEY_SUBSYSTEM " is not matching");
512 if (rule->subsystem_operation != KEY_OP_NOMATCH)
515 dbg(KEY_SUBSYSTEM " matches");
516 if (rule->subsystem_operation == KEY_OP_NOMATCH)
519 dbg(KEY_SUBSYSTEM " key is true");
522 if (rule->env_pair_count) {
525 dbg("check for " KEY_ENV " pairs");
526 for (i = 0; i < rule->env_pair_count; i++) {
527 struct key_pair *pair;
530 pair = &rule->env_pair[i];
531 value = getenv(pair->name);
533 dbg(KEY_ENV "{'%s'} is not found", pair->name);
536 if (strcmp_pattern(pair->value, value) != 0) {
537 dbg(KEY_ENV "{'%s'} is not matching", pair->name);
538 if (pair->operation != KEY_OP_NOMATCH)
541 dbg(KEY_ENV "{'%s'} matches", pair->name);
542 if (pair->operation == KEY_OP_NOMATCH)
546 dbg(KEY_ENV " key is true");
549 /* walk up the chain of physical devices and find a match */
551 /* check for matching driver */
552 if (rule->driver_operation != KEY_OP_UNSET) {
553 if (parent_device == NULL) {
554 dbg("device has no sysfs_device");
557 dbg("check for " KEY_DRIVER " rule->driver='%s' sysfs_device->driver_name='%s'",
558 rule->driver, parent_device->driver_name);
559 if (strcmp_pattern(rule->driver, parent_device->driver_name) != 0) {
560 dbg(KEY_DRIVER " is not matching");
561 if (rule->driver_operation != KEY_OP_NOMATCH)
564 dbg(KEY_DRIVER " matches");
565 if (rule->driver_operation == KEY_OP_NOMATCH)
568 dbg(KEY_DRIVER " key is true");
571 /* check for matching bus value */
572 if (rule->bus_operation != KEY_OP_UNSET) {
573 if (parent_device == NULL) {
574 dbg("device has no sysfs_device");
577 dbg("check for " KEY_BUS " rule->bus='%s' sysfs_device->bus='%s'",
578 rule->bus, parent_device->bus);
579 if (strcmp_pattern(rule->bus, parent_device->bus) != 0) {
580 dbg(KEY_BUS " is not matching");
581 if (rule->bus_operation != KEY_OP_NOMATCH)
584 dbg(KEY_BUS " matches");
585 if (rule->bus_operation == KEY_OP_NOMATCH)
588 dbg(KEY_BUS " key is true");
591 /* check for matching bus id */
592 if (rule->id_operation != KEY_OP_UNSET) {
593 if (parent_device == NULL) {
594 dbg("device has no sysfs_device");
597 dbg("check " KEY_ID);
598 if (strcmp_pattern(rule->id, parent_device->bus_id) != 0) {
599 dbg(KEY_ID " is not matching");
600 if (rule->id_operation != KEY_OP_NOMATCH)
603 dbg(KEY_ID " matches");
604 if (rule->id_operation == KEY_OP_NOMATCH)
607 dbg(KEY_ID " key is true");
610 /* check for matching sysfs pairs */
611 if (rule->sysfs_pair_count) {
614 dbg("check " KEY_SYSFS " pairs");
615 for (i = 0; i < rule->sysfs_pair_count; i++) {
616 struct key_pair *pair;
617 char value[VALUE_SIZE];
620 pair = &rule->sysfs_pair[i];
621 if (find_sysfs_attribute(class_dev, parent_device, pair->name, value, sizeof(value)) != 0)
624 /* strip trailing whitespace of value, if not asked to match for it */
625 len = strlen(pair->value);
626 if (len && !isspace(pair->value[len-1])) {
628 while (len > 0 && isspace(value[len-1]))
630 dbg("removed %i trailing whitespace chars from '%s'", strlen(value)-len, value);
633 dbg("compare attribute '%s' value '%s' with '%s'", pair->name, value, pair->value);
634 if (strcmp_pattern(pair->value, value) != 0) {
635 dbg(KEY_SYSFS "{'%s'} is not matching", pair->name);
636 if (pair->operation != KEY_OP_NOMATCH)
639 dbg(KEY_SYSFS "{'%s'} matches", pair->name);
640 if (pair->operation == KEY_OP_NOMATCH)
644 dbg(KEY_SYSFS " keys are true");
647 /* found matching physical device */
650 dbg("try parent sysfs device");
651 parent_device = sysfs_get_device_parent(parent_device);
652 if (parent_device == NULL)
654 dbg("look at sysfs_device->path='%s'", parent_device->path);
655 dbg("look at sysfs_device->bus_id='%s'", parent_device->bus_id);
658 /* execute external program */
659 if (rule->program_operation != KEY_OP_UNSET) {
660 char program[PATH_SIZE];
662 dbg("check " KEY_PROGRAM);
663 strlcpy(program, rule->program, sizeof(program));
664 apply_format(udev, program, sizeof(program), class_dev, sysfs_device);
665 if (execute_program_pipe(program, udev->subsystem,
666 udev->program_result, sizeof(udev->program_result)) != 0) {
667 dbg(KEY_PROGRAM " returned nonzero");
668 if (rule->program_operation != KEY_OP_NOMATCH)
671 dbg(KEY_PROGRAM " returned successful");
672 if (rule->program_operation == KEY_OP_NOMATCH)
675 dbg(KEY_PROGRAM " key is true");
678 /* check for matching result of external program */
679 if (rule->result_operation != KEY_OP_UNSET) {
680 dbg("check for " KEY_RESULT " rule->result='%s', udev->program_result='%s'",
681 rule->result, udev->program_result);
682 if (strcmp_pattern(rule->result, udev->program_result) != 0) {
683 dbg(KEY_RESULT " is not matching");
684 if (rule->result_operation != KEY_OP_NOMATCH)
687 dbg(KEY_RESULT " matches");
688 if (rule->result_operation == KEY_OP_NOMATCH)
691 dbg(KEY_RESULT " key is true");
701 int udev_rules_get_name(struct udevice *udev, struct sysfs_class_device *class_dev)
703 struct sysfs_class_device *class_dev_parent;
704 struct sysfs_device *sysfs_device = NULL;
705 struct udev_rule *rule;
707 dbg("class_dev->name='%s'", class_dev->name);
709 /* Figure out where the "device"-symlink is at. For char devices this will
710 * always be in the class_dev->path. On block devices, only the main block
711 * device will have the device symlink in it's path. All partition devices
712 * need to look at the symlink in its parent directory.
714 class_dev_parent = sysfs_get_classdev_parent(class_dev);
715 if (class_dev_parent != NULL) {
716 dbg("given class device has a parent, use this instead");
717 sysfs_device = sysfs_get_classdev_device(class_dev_parent);
719 sysfs_device = sysfs_get_classdev_device(class_dev);
723 dbg("found devices device: path='%s', bus_id='%s', bus='%s'",
724 sysfs_device->path, sysfs_device->bus_id, sysfs_device->bus);
725 strlcpy(udev->bus_id, sysfs_device->bus_id, sizeof(udev->bus_id));
728 dbg("udev->kernel_name='%s'", udev->kernel_name);
730 /* look for a matching rule to apply */
731 list_for_each_entry(rule, &udev_rule_list, node) {
733 if (match_rule(udev, rule, class_dev, sysfs_device) == 0) {
734 if (udev->name[0] != '\0' && rule->name[0] != '\0') {
735 dbg("node name already set, rule ignored");
740 if (rule->ignore_device) {
741 info("configured rule in '%s[%i]' applied, '%s' is ignored",
742 rule->config_file, rule->config_line, udev->kernel_name);
743 udev->ignore_device = 1;
746 if (rule->ignore_remove) {
747 udev->ignore_remove = 1;
748 dbg("remove event should be ignored");
750 /* apply all_partitions option only at a main block device */
751 if (rule->partitions && udev->type == DEV_BLOCK && udev->kernel_number[0] == '\0') {
752 udev->partitions = rule->partitions;
753 dbg("creation of partition nodes requested");
756 /* apply permissions */
757 if (rule->mode != 0000) {
758 udev->mode = rule->mode;
759 dbg("applied mode=%#o to '%s'", udev->mode, udev->kernel_name);
761 if (rule->owner[0] != '\0') {
762 strlcpy(udev->owner, rule->owner, sizeof(udev->owner));
763 apply_format(udev, udev->owner, sizeof(udev->owner), class_dev, sysfs_device);
764 dbg("applied owner='%s' to '%s'", udev->owner, udev->kernel_name);
766 if (rule->group[0] != '\0') {
767 strlcpy(udev->group, rule->group, sizeof(udev->group));
768 apply_format(udev, udev->group, sizeof(udev->group), class_dev, sysfs_device);
769 dbg("applied group='%s' to '%s'", udev->group, udev->kernel_name);
772 /* collect symlinks */
773 if (rule->symlink[0] != '\0') {
774 char temp[PATH_SIZE];
777 info("configured rule in '%s[%i]' applied, added symlink '%s'",
778 rule->config_file, rule->config_line, rule->symlink);
779 strlcpy(temp, rule->symlink, sizeof(temp));
780 apply_format(udev, temp, sizeof(temp), class_dev, sysfs_device);
782 /* add multiple symlinks separated by spaces */
784 next = strchr(temp, ' ');
787 info("add symlink '%s'", pos);
788 name_list_add(&udev->symlink_list, pos, 0);
790 next = strchr(pos, ' ');
792 info("add symlink '%s'", pos);
793 name_list_add(&udev->symlink_list, pos, 0);
796 /* set name, later rules with name set will be ignored */
797 if (rule->name[0] != '\0') {
798 info("configured rule in '%s[%i]' applied, '%s' becomes '%s'",
799 rule->config_file, rule->config_line, udev->kernel_name, rule->name);
801 strlcpy(udev->name, rule->name, sizeof(udev->name));
802 apply_format(udev, udev->name, sizeof(udev->name), class_dev, sysfs_device);
803 strlcpy(udev->config_file, rule->config_file, sizeof(udev->config_file));
804 udev->config_line = rule->config_line;
806 if (udev->type != DEV_NET)
807 dbg("name, '%s' is going to have owner='%s', group='%s', mode=%#o partitions=%i",
808 udev->name, udev->owner, udev->group, udev->mode, udev->partitions);
811 if (rule->run[0] != '\0') {
812 char program[PATH_SIZE];
814 strlcpy(program, rule->run, sizeof(program));
815 apply_format(udev, program, sizeof(program), class_dev, sysfs_device);
816 dbg("add run '%s'", program);
817 name_list_add(&udev->run_list, program, 0);
820 if (rule->last_rule) {
821 dbg("last rule to be applied");
827 if (udev->name[0] == '\0') {
828 strlcpy(udev->name, udev->kernel_name, sizeof(udev->name));
829 info("no rule found, use kernel name '%s'", udev->name);
832 if (udev->tmp_node[0] != '\0') {
833 dbg("removing temporary device node");
834 unlink_secure(udev->tmp_node);
835 udev->tmp_node[0] = '\0';
841 int udev_rules_get_run(struct udevice *udev)
843 struct udev_rule *rule;
844 char program[PATH_SIZE];
846 /* look for a matching rule to apply */
847 list_for_each_entry(rule, &udev_rule_list, node) {
850 if (rule->run[0] == '\0')
853 if (rule->name[0] != '\0' || rule->symlink[0] != '\0' ||
854 rule->mode != 0000 || rule->owner[0] != '\0' || rule->group[0] != '\0') {
855 dbg("skip rule that names a device");
859 if (rule->action_operation != KEY_OP_UNSET) {
860 dbg("check for " KEY_ACTION " rule->action='%s' udev->action='%s'",
861 rule->action, udev->action);
862 if (strcmp_pattern(rule->action, udev->action) != 0) {
863 dbg(KEY_ACTION " is not matching");
864 if (rule->action_operation != KEY_OP_NOMATCH)
867 dbg(KEY_ACTION " matches");
868 if (rule->action_operation == KEY_OP_NOMATCH)
871 dbg(KEY_ACTION " key is true");
874 if (rule->kernel_operation != KEY_OP_UNSET) {
875 dbg("check for " KEY_KERNEL " rule->kernel='%s' udev->kernel_name='%s'",
876 rule->kernel, udev->kernel_name);
877 if (strcmp_pattern(rule->kernel, udev->kernel_name) != 0) {
878 dbg(KEY_KERNEL " is not matching");
879 if (rule->kernel_operation != KEY_OP_NOMATCH)
882 dbg(KEY_KERNEL " matches");
883 if (rule->kernel_operation == KEY_OP_NOMATCH)
886 dbg(KEY_KERNEL " key is true");
889 if (rule->subsystem_operation != KEY_OP_UNSET) {
890 dbg("check for " KEY_SUBSYSTEM " rule->subsystem='%s' udev->subsystem='%s'",
891 rule->subsystem, udev->subsystem);
892 if (strcmp_pattern(rule->subsystem, udev->subsystem) != 0) {
893 dbg(KEY_SUBSYSTEM " is not matching");
894 if (rule->subsystem_operation != KEY_OP_NOMATCH)
897 dbg(KEY_SUBSYSTEM " matches");
898 if (rule->subsystem_operation == KEY_OP_NOMATCH)
901 dbg(KEY_SUBSYSTEM " key is true");
904 if (rule->env_pair_count) {
907 dbg("check for " KEY_ENV " pairs");
908 for (i = 0; i < rule->env_pair_count; i++) {
909 struct key_pair *pair;
912 pair = &rule->env_pair[i];
913 value = getenv(pair->name);
915 dbg(KEY_ENV "{'%s'} is not found", pair->name);
918 if (strcmp_pattern(pair->value, value) != 0) {
919 dbg(KEY_ENV "{'%s'} is not matching", pair->name);
920 if (pair->operation != KEY_OP_NOMATCH)
923 dbg(KEY_ENV "{'%s'} matches", pair->name);
924 if (pair->operation == KEY_OP_NOMATCH)
928 dbg(KEY_ENV " key is true");
933 if (rule->ignore_device) {
934 info("configured rule in '%s[%i]' applied, '%s' is ignored",
935 rule->config_file, rule->config_line, udev->kernel_name);
936 udev->ignore_device = 1;
940 strlcpy(program, rule->run, sizeof(program));
941 apply_format(udev, program, sizeof(program), NULL, NULL);
942 dbg("add run '%s'", program);
943 name_list_add(&udev->run_list, program, 0);
945 if (rule->last_rule) {
946 dbg("last rule to be applied");