chiark / gitweb /
remove all PHYSDEVPATH handling and warning about
[elogind.git] / udev / udev-rules.c
index 52638aeb1db2f40af60bc11ff3bd95bc9c9d7c7c..fac418e526a625099d8b96adec4711b50fd2b3fb 100644 (file)
@@ -140,6 +140,7 @@ enum token_type {
        TK_A_IGNORE_DEVICE,
        TK_A_STRING_ESCAPE_NONE,
        TK_A_STRING_ESCAPE_REPLACE,
+       TK_A_INOTIFY_WATCH,             /* int */
        TK_A_NUM_FAKE_PART,             /* int */
        TK_A_DEVLINK_PRIO,              /* int */
        TK_A_OWNER,                     /* val */
@@ -182,7 +183,6 @@ struct token {
                        union {
                                unsigned int attr_off;
                                int ignore_error;
-                               int i;
                                unsigned int rule_goto;
                                mode_t  mode;
                                uid_t uid;
@@ -190,6 +190,7 @@ struct token {
                                int num_fake_part;
                                int devlink_prio;
                                int event_timeout;
+                               int watch;
                        };
                } key;
        };
@@ -270,6 +271,7 @@ static const char *token_str(enum token_type type)
                [TK_A_IGNORE_DEVICE] =          "A IGNORE_DEVICE",
                [TK_A_STRING_ESCAPE_NONE] =     "A STRING_ESCAPE_NONE",
                [TK_A_STRING_ESCAPE_REPLACE] =  "A STRING_ESCAPE_REPLACE",
+               [TK_A_INOTIFY_WATCH] =          "A INOTIFY_WATCH",
                [TK_A_NUM_FAKE_PART] =          "A NUM_FAKE_PART",
                [TK_A_DEVLINK_PRIO] =           "A DEVLINK_PRIO",
                [TK_A_OWNER] =                  "A OWNER",
@@ -360,6 +362,9 @@ static void dump_token(struct udev_rules *rules, struct token *token)
                dbg(rules->udev, "%s %s '%s'(%s) %#o\n",
                    token_str(type), operation_str(op), value, string_glob_str(glob), token->key.mode);
                break;
+       case TK_A_INOTIFY_WATCH:
+               dbg(rules->udev, "%s %u\n", token_str(type), token->key.watch);
+               break;
        case TK_A_NUM_FAKE_PART:
                dbg(rules->udev, "%s %u\n", token_str(type), token->key.num_fake_part);
                break;
@@ -732,7 +737,7 @@ static int import_program_into_properties(struct udev_device *dev, const char *p
 {
        struct udev *udev = udev_device_get_udev(dev);
        char **envp;
-       char result[2048];
+       char result[4096];
        size_t reslen;
        char *line;
 
@@ -1027,9 +1032,8 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
                token->key.value_off = add_string(rule_tmp->rules, value);
                token->key.ignore_error = *(int *)data;
                break;
+       case TK_A_INOTIFY_WATCH:
        case TK_A_NUM_FAKE_PART:
-               token->key.num_fake_part = *(int *)data;
-               break;
        case TK_A_DEVLINK_PRIO:
                token->key.devlink_prio = *(int *)data;
                break;
@@ -1133,8 +1137,6 @@ static int add_rule(struct udev_rules *rules, char *line,
 {
        char *linepos;
        char *attr;
-       int physdev = 0;
-       int waitfor = 0;
        struct rule_tmp rule_tmp;
 
        memset(&rule_tmp, 0x00, sizeof(struct rule_tmp));
@@ -1276,8 +1278,6 @@ static int add_rule(struct udev_rules *rules, char *line,
                                err(rules->udev, "error parsing ENV attribute\n");
                                goto invalid;
                        }
-                       if (strncmp(attr, "PHYSDEV", 7) == 0)
-                               physdev = 1;
                        if (op < OP_MATCH_MAX) {
                                if (rule_add_key(&rule_tmp, TK_M_ENV, op, value, attr) != 0)
                                        goto invalid;
@@ -1374,7 +1374,6 @@ static int add_rule(struct udev_rules *rules, char *line,
 
                if (strcasecmp(key, "WAIT_FOR") == 0 || strcasecmp(key, "WAIT_FOR_SYSFS") == 0) {
                        rule_add_key(&rule_tmp, TK_M_WAITFOR, 0, value, NULL);
-                       waitfor = 1;
                        continue;
                }
 
@@ -1512,15 +1511,26 @@ static int add_rule(struct udev_rules *rules, char *line,
                                rule_add_key(&rule_tmp, TK_A_NUM_FAKE_PART, 0, NULL, &num);
                                dbg(rules->udev, "creation of partition nodes requested\n");
                        }
+                       pos = strstr(value, "nowatch");
+                       if (pos != NULL) {
+                               const int off = 0;
+
+                               rule_add_key(&rule_tmp, TK_A_INOTIFY_WATCH, 0, NULL, &off);
+                               dbg(rules->udev, "inotify watch of device disabled\n");
+                       } else {
+                               pos = strstr(value, "watch");
+                               if (pos != NULL) {
+                                       const int on = 1;
+
+                                       rule_add_key(&rule_tmp, TK_A_INOTIFY_WATCH, 0, NULL, &on);
+                                       dbg(rules->udev, "inotify watch of device requested\n");
+                               }
+                       }
                        continue;
                }
                err(rules->udev, "unknown key '%s' in %s:%u\n", key, filename, lineno);
        }
 
-       if (physdev && !waitfor)
-               err(rules->udev, "PHYSDEV* values are deprecated and not available on recent kernels, "
-                   "please fix it in %s:%u\n", filename, lineno);
-
        /* add rule token */
        rule_tmp.rule.rule.token_count = 1 + rule_tmp.token_cur;
        if (add_token(rules, &rule_tmp.rule) != 0)
@@ -2244,6 +2254,9 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
                                break;
                        udev_device_set_num_fake_partitions(event->dev, cur->key.num_fake_part);
                        break;
+               case TK_A_INOTIFY_WATCH:
+                       event->inotify_watch = cur->key.watch;
+                       break;
                case TK_A_DEVLINK_PRIO:
                        udev_device_set_devlink_priority(event->dev, cur->key.devlink_prio);
                        break;
@@ -2371,13 +2384,13 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
                                        count = udev_util_replace_chars(name_str, "/");
                                        if (count > 0)
                                                info(event->udev, "%i character(s) replaced\n", count);
-                                       free(event->name);
-                                       event->name = strdup(name_str);
-                                       info(event->udev, "NAME '%s' %s:%u\n",
-                                            event->name,
-                                            &rules->buf[rule->rule.filename_off],
-                                            rule->rule.filename_line);
                                }
+                               free(event->name);
+                               event->name = strdup(name_str);
+                               info(event->udev, "NAME '%s' %s:%u\n",
+                                    event->name,
+                                    &rules->buf[rule->rule.filename_off],
+                                    rule->rule.filename_line);
                                break;
                        }
                case TK_A_DEVLINK: