diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-23 02:34:22 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-23 02:34:22 +0200 |
commit | 40fd3bc837e04538df305b512157e55a2a5e0789 (patch) | |
tree | 3f8625c9ce4ce2412e5fcaea64a5b837d93c7430 | |
parent | 5a05e120af1fa09d08f564e847ef48d50efa1156 (diff) |
shrink struct udev_event
-rw-r--r-- | udev/udev-event.c | 22 | ||||
-rw-r--r-- | udev/udev-rules.c | 10 | ||||
-rw-r--r-- | udev/udev.h | 4 |
3 files changed, 24 insertions, 12 deletions
diff --git a/udev/udev-event.c b/udev/udev-event.c index a41d4edb41..36d36ac643 100644 --- a/udev/udev-event.c +++ b/udev/udev-event.c @@ -47,7 +47,11 @@ struct udev_event *udev_event_new(struct udev_device *dev) void udev_event_unref(struct udev_event *event) { + if (event == NULL) + return; udev_list_cleanup_entries(event->udev, &event->run_list); + free(event->tmp_node); + free(event->program_result); dbg(event->udev, "free event %p\n", event); free(event); } @@ -245,15 +249,18 @@ found: dbg(event->udev, "substitute minor number '%s'\n", temp2); break; case SUBST_RESULT: - if (event->program_result[0] == '\0') + if (event->program_result == NULL) break; /* get part part of the result string */ i = 0; if (attr != NULL) i = strtoul(attr, &rest, 10); if (i > 0) { + char result[UTIL_PATH_SIZE]; + dbg(event->udev, "request part #%d of result string\n", i); - cpos = event->program_result; + util_strlcpy(result, event->program_result, sizeof(result)); + cpos = result; while (--i) { while (cpos[0] != '\0' && !isspace(cpos[0])) cpos++; @@ -338,7 +345,7 @@ found: char filename[UTIL_PATH_SIZE]; const char *devtype; - if (event->tmp_node[0] != '\0') { + if (event->tmp_node != NULL) { util_strlcat(string, event->tmp_node, maxsize); dbg(event->udev, "return existing temporary node\n"); break; @@ -360,10 +367,12 @@ found: break; } dbg(event->udev, "create temporary node\n"); - snprintf(event->tmp_node, sizeof(event->tmp_node), "%s/.tmp-%s-%u:%u", + asprintf(&event->tmp_node, "%s/.tmp-%s-%u:%u", udev_get_dev_path(event->udev), devtype, major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); + if (event->tmp_node == NULL) + break; udev_node_mknod(dev, event->tmp_node, makedev(0, 0), 0600, 0, 0); util_strlcat(string, event->tmp_node, maxsize); } @@ -537,10 +546,11 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules) dbg(event->udev, "device node add '%s'\n", udev_device_get_devpath(dev)); udev_rules_apply_to_event(rules, event); - if (event->tmp_node[0] != '\0') { + if (event->tmp_node != NULL) { dbg(event->udev, "removing temporary device node\n"); util_unlink_secure(event->udev, event->tmp_node); - event->tmp_node[0] = '\0'; + free(event->tmp_node); + event->tmp_node = NULL; } if (event->ignore_device) { diff --git a/udev/udev-rules.c b/udev/udev-rules.c index b456c3da33..675a7f0625 100644 --- a/udev/udev-rules.c +++ b/udev/udev-rules.c @@ -1783,11 +1783,12 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event char **envp; char result[UTIL_PATH_SIZE]; + free(event->program_result); + event->program_result = NULL; util_strlcpy(program, &rules->buf[cur->key.value_off], sizeof(program)); udev_event_apply_format(event, program, sizeof(program)); envp = udev_device_get_properties_envp(event->dev); if (util_run_program(event->udev, program, envp, result, sizeof(result), NULL) != 0) { - event->program_result[0] = '\0'; if (cur->key.op != KEY_OP_NOMATCH) goto nomatch; } else { @@ -1799,7 +1800,8 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (count > 0) info(event->udev, "%i character(s) replaced\n" , count); } - util_strlcpy(event->program_result, result, sizeof(event->program_result)); + event->program_result = strdup(result); + dbg(event->udev, "storing result '%s'\n", event->program_result); if (cur->key.op == KEY_OP_NOMATCH) goto nomatch; } @@ -1884,7 +1886,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event break; if (cur->key.op == KEY_OP_ASSIGN_FINAL) event->group_final = 1; - util_strlcpy(group, &rules->buf[cur->key.value_off], sizeof(group)); + util_strlcpy(group, &rules->buf[cur->key.value_off], sizeof(group)); udev_event_apply_format(event, group, sizeof(group)); event->gid = util_lookup_group(event->udev, group); break; @@ -1898,7 +1900,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event break; if (cur->key.op == KEY_OP_ASSIGN_FINAL) event->mode_final = 1; - util_strlcpy(mode, &rules->buf[cur->key.value_off], sizeof(mode)); + util_strlcpy(mode, &rules->buf[cur->key.value_off], sizeof(mode)); udev_event_apply_format(event, mode, sizeof(mode)); event->mode = strtol(mode, &endptr, 8); if (endptr[0] != '\0') { diff --git a/udev/udev.h b/udev/udev.h index a00be37334..927ff36e01 100644 --- a/udev/udev.h +++ b/udev/udev.h @@ -61,11 +61,11 @@ struct udev_event { struct udev_device *dev; struct udev_device *dev_parent; int devlink_final; - char program_result[UTIL_PATH_SIZE]; char name[UTIL_PATH_SIZE]; int name_final; int name_ignore; - char tmp_node[UTIL_PATH_SIZE]; + char *tmp_node; + char *program_result; mode_t mode; int mode_final; uid_t uid; |