1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

shrink struct udev_event

This commit is contained in:
Kay Sievers 2008-10-23 02:57:08 +02:00
parent 40fd3bc837
commit b99028c963
4 changed files with 38 additions and 38 deletions

View File

@ -34,36 +34,36 @@
#define ENVP_SIZE 128 #define ENVP_SIZE 128
struct udev_device { struct udev_device {
int refcount;
struct udev *udev; struct udev *udev;
struct udev_device *parent_device; struct udev_device *parent_device;
int parent_set;
char *syspath; char *syspath;
const char *devpath; const char *devpath;
char *sysname; char *sysname;
const char *sysnum; const char *sysnum;
char *devnode; char *devnode;
char *subsystem; char *subsystem;
int subsystem_set;
struct udev_list_node devlinks_list;
int devlinks_uptodate;
struct udev_list_node properties_list;
char **envp; char **envp;
int envp_uptodate;
char *driver; char *driver;
int driver_set;
dev_t devnum;
char *action; char *action;
int event_timeout;
char *devpath_old; char *devpath_old;
char *physdevpath; 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; unsigned long long int seqnum;
int event_timeout;
int timeout;
int num_fake_partitions; int num_fake_partitions;
int devlink_priority; int devlink_priority;
int ignore_remove; int refcount;
struct udev_list_node sysattr_list; dev_t devnum;
int info_loaded; 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) static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len)

View File

@ -52,6 +52,7 @@ void udev_event_unref(struct udev_event *event)
udev_list_cleanup_entries(event->udev, &event->run_list); udev_list_cleanup_entries(event->udev, &event->run_list);
free(event->tmp_node); free(event->tmp_node);
free(event->program_result); free(event->program_result);
free(event->name);
dbg(event->udev, "free event %p\n", event); dbg(event->udev, "free event %p\n", event);
free(event); free(event);
} }
@ -558,15 +559,17 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
goto exit; goto exit;
} }
if (event->name_ignore) { if (event->name != NULL && event->name[0] == '\0') {
info(event->udev, "device node creation supressed\n"); info(event->udev, "device node creation supressed\n");
goto exit; goto exit;
} }
if (event->name[0] == '\0') { if (event->name == NULL) {
info(event->udev, "no node name set, will use kernel name '%s'\n", info(event->udev, "no node name set, will use kernel name '%s'\n",
udev_device_get_sysname(event->dev)); 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 */ /* 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"); info(event->udev, "device event will be ignored\n");
goto exit; goto exit;
} }
if (event->name[0] == '\0') { if (event->name == NULL)
info(event->udev, "device renaming supressed\n");
goto exit; goto exit;
}
/* look if we want to change the name of the netif */ /* look if we want to change the name of the netif */
if (strcmp(event->name, udev_device_get_sysname(dev)) != 0) { if (strcmp(event->name, udev_device_get_sysname(dev)) != 0) {

View File

@ -1952,6 +1952,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
case TK_A_NAME: case TK_A_NAME:
{ {
const char *name = &rules->buf[cur->key.value_off]; const char *name = &rules->buf[cur->key.value_off];
char name_str[UTIL_PATH_SIZE];
int count; int count;
if (event->name_final) 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) if (cur->key.op == KEY_OP_ASSIGN_FINAL)
event->name_final = 1; event->name_final = 1;
if (name[0] == '\0') { if (name[0] == '\0') {
event->name[0] = '\0'; free(event->name);
event->name_ignore = 1; event->name = NULL;
break; break;
} }
event->name_ignore = 0; util_strlcpy(name_str, name, sizeof(name_str));
util_strlcpy(event->name, name, sizeof(event->name)); udev_event_apply_format(event, name_str, sizeof(name_str));
udev_event_apply_format(event, event->name, sizeof(event->name));
if (esc == ESCAPE_UNSET || esc == ESCAPE_REPLACE) { 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) if (count > 0)
info(event->udev, "%i character(s) replaced\n", count); info(event->udev, "%i character(s) replaced\n", count);
event->name = strdup(name_str);
} }
break; break;
} }

View File

@ -57,30 +57,28 @@ static inline void logging_close(void)
} }
struct udev_event { struct udev_event {
struct udev_list_node node;
struct udev *udev; struct udev *udev;
struct udev_device *dev; struct udev_device *dev;
struct udev_device *dev_parent; struct udev_device *dev_parent;
int devlink_final; char *name;
char name[UTIL_PATH_SIZE];
int name_final;
int name_ignore;
char *tmp_node; char *tmp_node;
char *program_result; char *program_result;
mode_t mode; mode_t mode;
int mode_final;
uid_t uid; uid_t uid;
int owner_final;
gid_t gid; gid_t gid;
int group_final;
struct udev_list_node run_list; struct udev_list_node run_list;
int run_final;
int ignore_device;
int test;
struct udev_list_node node;
pid_t pid; pid_t pid;
int exitstatus; int exitstatus;
time_t queue_time; 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 */ /* udev-rules.c */