chiark / gitweb /
shrink struct udev_event
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 23 Oct 2008 00:57:08 +0000 (02:57 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Thu, 23 Oct 2008 00:57:08 +0000 (02:57 +0200)
udev/lib/libudev-device.c
udev/udev-event.c
udev/udev-rules.c
udev/udev.h

index f56db7f..8812f1f 100644 (file)
 #define ENVP_SIZE 128
 
 struct udev_device {
-       int refcount;
        struct udev *udev;
        struct udev_device *parent_device;
-       int parent_set;
        char *syspath;
        const char *devpath;
        char *sysname;
        const char *sysnum;
        char *devnode;
        char *subsystem;
-       int subsystem_set;
-       struct udev_list_node devlinks_list;
-       int devlinks_uptodate;
-       struct udev_list_node properties_list;
        char **envp;
-       int envp_uptodate;
        char *driver;
-       int driver_set;
-       dev_t devnum;
        char *action;
-       int event_timeout;
        char *devpath_old;
        char *physdevpath;
-       int timeout;
+       struct udev_list_node devlinks_list;
+       struct udev_list_node properties_list;
+       struct udev_list_node sysattr_list;
        unsigned long long int seqnum;
+       int event_timeout;
+       int timeout;
        int num_fake_partitions;
        int devlink_priority;
-       int ignore_remove;
-       struct udev_list_node sysattr_list;
-       int info_loaded;
+       int refcount;
+       dev_t devnum;
+       unsigned int parent_set:1;
+       unsigned int subsystem_set:1;
+       unsigned int devlinks_uptodate:1;
+       unsigned int envp_uptodate:1;
+       unsigned int driver_set:1;
+       unsigned int info_loaded:1;
+       unsigned int ignore_remove:1;
 };
 
 static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len)
index 36d36ac..fcb9993 100644 (file)
@@ -52,6 +52,7 @@ void udev_event_unref(struct udev_event *event)
        udev_list_cleanup_entries(event->udev, &event->run_list);
        free(event->tmp_node);
        free(event->program_result);
+       free(event->name);
        dbg(event->udev, "free event %p\n", event);
        free(event);
 }
@@ -558,15 +559,17 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
                        goto exit;
                }
 
-               if (event->name_ignore) {
+               if (event->name != NULL && event->name[0] == '\0') {
                        info(event->udev, "device node creation supressed\n");
                        goto exit;
                }
 
-               if (event->name[0] == '\0') {
+               if (event->name == NULL) {
                        info(event->udev, "no node name set, will use kernel name '%s'\n",
                             udev_device_get_sysname(event->dev));
-                       util_strlcpy(event->name, udev_device_get_sysname(event->dev), sizeof(event->name));
+                       event->name = strdup(udev_device_get_sysname(event->dev));
+                       if (event->name == NULL)
+                               goto exit;
                }
 
                /* set device node name */
@@ -604,10 +607,8 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
                        info(event->udev, "device event will be ignored\n");
                        goto exit;
                }
-               if (event->name[0] == '\0') {
-                       info(event->udev, "device renaming supressed\n");
+               if (event->name == NULL)
                        goto exit;
-               }
 
                /* look if we want to change the name of the netif */
                if (strcmp(event->name, udev_device_get_sysname(dev)) != 0) {
index 675a7f0..19ee06d 100644 (file)
@@ -1952,6 +1952,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
                case TK_A_NAME:
                        {
                                const char *name  = &rules->buf[cur->key.value_off];
+                               char name_str[UTIL_PATH_SIZE];
                                int count;
 
                                if (event->name_final)
@@ -1959,17 +1960,17 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
                                if (cur->key.op == KEY_OP_ASSIGN_FINAL)
                                        event->name_final = 1;
                                if (name[0] == '\0') {
-                                       event->name[0] = '\0';
-                                       event->name_ignore = 1;
+                                       free(event->name);
+                                       event->name = NULL;
                                        break;
                                }
-                               event->name_ignore = 0;
-                               util_strlcpy(event->name, name, sizeof(event->name));
-                               udev_event_apply_format(event, event->name, sizeof(event->name));
+                               util_strlcpy(name_str, name, sizeof(name_str));
+                               udev_event_apply_format(event, name_str, sizeof(name_str));
                                if (esc == ESCAPE_UNSET || esc == ESCAPE_REPLACE) {
-                                       count = util_replace_chars(event->name, ALLOWED_CHARS_FILE);
+                                       count = util_replace_chars(name_str, ALLOWED_CHARS_FILE);
                                        if (count > 0)
                                                info(event->udev, "%i character(s) replaced\n", count);
+                                       event->name = strdup(name_str);
                                }
                                break;
                        }
index 927ff36..faa1bf6 100644 (file)
@@ -57,30 +57,28 @@ static inline void logging_close(void)
 }
 
 struct udev_event {
+       struct udev_list_node node;
        struct udev *udev;
        struct udev_device *dev;
        struct udev_device *dev_parent;
-       int devlink_final;
-       char name[UTIL_PATH_SIZE];
-       int name_final;
-       int name_ignore;
+       char *name;
        char *tmp_node;
        char *program_result;
        mode_t mode;
-       int mode_final;
        uid_t uid;
-       int owner_final;
        gid_t gid;
-       int group_final;
        struct udev_list_node run_list;
-       int run_final;
-       int ignore_device;
-       int test;
-
-       struct udev_list_node node;
        pid_t pid;
        int exitstatus;
        time_t queue_time;
+       unsigned int group_final:1;
+       unsigned int owner_final:1;
+       unsigned int mode_final:1;
+       unsigned int name_final:1;
+       unsigned int devlink_final:1;
+       unsigned int run_final:1;
+       unsigned int ignore_device:1;
+       unsigned int test:1;
 };
 
 /* udev-rules.c */