+ /* rule matches, if we have ENV assignments export it */
+ for (i = 0; i < rule->env.count; i++) {
+ struct key_pair *pair = &rule->env.keys[i];
+
+ if (pair->key.operation == KEY_OP_ASSIGN) {
+ char temp_value[NAME_SIZE];
+ const char *key_name = key_pair_name(rule, pair);
+ const char *value = key_val(rule, &pair->key);
+
+ /* make sure we don't write to the same string we possibly read from */
+ strlcpy(temp_value, value, sizeof(temp_value));
+ udev_rules_apply_format(udev, temp_value, NAME_SIZE);
+
+ if (temp_value[0] == '\0') {
+ name_list_key_remove(&udev->env_list, key_name);
+ unsetenv(key_name);
+ info("unset ENV '%s'", key_name);
+ } else {
+ char *key_value = name_list_key_add(&udev->env_list, key_name, temp_value);
+
+ if (key_value == NULL)
+ break;
+ putenv(key_value);
+ info("set ENV '%s'", key_value);
+ }
+ }
+ }
+
+ /* if we have ATTR assignements write value to sysfs file */
+ for (i = 0; i < rule->attr.count; i++) {
+ struct key_pair *pair = &rule->attr.keys[i];
+
+ if (pair->key.operation == KEY_OP_ASSIGN) {
+ const char *key_name = key_pair_name(rule, pair);
+ char attr[PATH_SIZE];
+ char value[NAME_SIZE];
+ FILE *f;
+
+ strlcpy(attr, sysfs_path, sizeof(attr));
+ strlcat(attr, udev->dev->devpath, sizeof(attr));
+ strlcat(attr, "/", sizeof(attr));
+ strlcat(attr, key_name, sizeof(attr));
+ strlcpy(value, key_val(rule, &pair->key), sizeof(value));
+ udev_rules_apply_format(udev, value, sizeof(value));
+ info("writing '%s' to sysfs file '%s'", value, attr);
+ f = fopen(attr, "w");
+ if (f != NULL) {
+ if (!udev->test_run)
+ if (fprintf(f, "%s", value) <= 0)
+ err("error writing ATTR{%s}: %s", attr, strerror(errno));
+ fclose(f);
+ } else
+ err("error opening ATTR{%s} for writing: %s", attr, strerror(errno));
+ }
+ }