]> err.no Git - systemd/commitdiff
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 f56db7ff155bbe70fa36fd2b83217cd9f148d42c..8812f1fc8432a451125f1b93e8ef250c09b040f2 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 36d36ac643f1bb7d7b35db79391f8fa5d24d3537..fcb999370974db5624dcc510c8833b83e46adb47 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 675a7f06255719bd921ea4db5e082c00e896800b..19ee06d3798c996a50ce2ae6b3ce6b0e9ff329c0 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 927ff36e0116bdcdd45338d091085a51fe7f1b61..faa1bf68516cb6737c4f8069bcd8008101aba58c 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 */