From 17fcfb5972977b6a3aedca6ad2aa8d1fbfbc761d Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Wed, 10 Sep 2008 21:50:21 +0200 Subject: [PATCH] use size definitions from libudev --- configure.ac | 4 --- extras/edd_id/edd_id.c | 2 +- udev/lib/libudev-device.c | 6 ++-- udev/lib/libudev-private.h | 3 +- udev/udev.h | 33 ++++++++------------ udev/udev_db.c | 22 +++++++------- udev/udev_node.c | 24 +++++++-------- udev/udev_rules.c | 62 +++++++++++++++++++------------------- udev/udev_rules_parse.c | 12 ++++---- udev/udev_sysfs.c | 62 +++++++++----------------------------- udev/udev_utils.c | 4 +-- udev/udev_utils_file.c | 4 +-- udev/udevadm-info.c | 20 ++++++------ udev/udevadm-settle.c | 6 ++-- udev/udevadm-test.c | 4 +-- udev/udevadm-trigger.c | 42 +++++++++++++------------- udev/udevd.c | 12 ++++---- 17 files changed, 139 insertions(+), 183 deletions(-) diff --git a/configure.ac b/configure.ac index c24da97a3..43babff12 100644 --- a/configure.ac +++ b/configure.ac @@ -31,10 +31,6 @@ AC_CHECK_LIB(c, inotify_init, [AC_DEFINE([HAVE_INOTIFY], 1, [inotify available])], [AC_MSG_WARN([inotify support disabled])]) -AC_CHECK_LIB(c, strlcpy, - [AC_DEFINE([HAVE_STRLCPY], 1, [strlcpy available])], - []) - AC_ARG_WITH(udev-prefix, AS_HELP_STRING([--with-udev-prefix=DIR], [add prefix to internal udev path names]), [], [with_udev_prefix='${exec_prefix}']) diff --git a/extras/edd_id/edd_id.c b/extras/edd_id/edd_id.c index 4ba60393a..d7aec1488 100644 --- a/extras/edd_id/edd_id.c +++ b/extras/edd_id/edd_id.c @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) /* lookup signature in sysfs to determine the name */ for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char file[PATH_SIZE]; + char file[UTIL_PATH_SIZE]; char sysfs_id_buf[256]; uint32_t sysfs_id; ssize_t size; diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c index a182750e6..0405e1c98 100644 --- a/udev/lib/libudev-device.c +++ b/udev/lib/libudev-device.c @@ -332,7 +332,7 @@ const char *udev_device_get_devname(struct udev_device *udev_device) **/ const char *udev_device_get_subsystem(struct udev_device *udev_device) { - char subsystem[UTIL_PATH_SIZE]; + char subsystem[UTIL_NAME_SIZE]; if (udev_device == NULL) return NULL; @@ -398,7 +398,7 @@ int udev_device_get_properties(struct udev_device *udev_device, if (udev_device == NULL) return -1; list_for_each_entry(name_loop, &udev_device->env_list, node) { - char name[UTIL_PATH_SIZE]; + char name[UTIL_NAME_SIZE]; char *val; strncpy(name, name_loop->name, sizeof(name)); @@ -416,7 +416,7 @@ int udev_device_get_properties(struct udev_device *udev_device, const char *udev_device_get_driver(struct udev_device *udev_device) { - char driver[UTIL_PATH_SIZE]; + char driver[UTIL_NAME_SIZE]; if (udev_device == NULL) return NULL; diff --git a/udev/lib/libudev-private.h b/udev/lib/libudev-private.h index 1f4abc07b..8ca441639 100644 --- a/udev/lib/libudev-private.h +++ b/udev/lib/libudev-private.h @@ -105,7 +105,8 @@ extern int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg); /* libudev-utils */ #define UTIL_PATH_SIZE 1024 -#define UTIL_LINE_SIZE 1024 +#define UTIL_LINE_SIZE 2048 +#define UTIL_NAME_SIZE 512 struct util_name_entry { struct list_head node; char *name; diff --git a/udev/udev.h b/udev/udev.h index 0bf06bedb..ae50213fd 100644 --- a/udev/udev.h +++ b/udev/udev.h @@ -30,12 +30,6 @@ #include "lib/libudev-private.h" #include "lib/list.h" -#define COMMENT_CHARACTER '#' -#define LINE_SIZE 512 -#define PATH_SIZE 512 -#define NAME_SIZE 256 -#define VALUE_SIZE 128 - #define ALLOWED_CHARS "#+-.:=@_" #define ALLOWED_CHARS_FILE ALLOWED_CHARS "/" #define ALLOWED_CHARS_INPUT ALLOWED_CHARS_FILE " $%?," @@ -60,11 +54,11 @@ struct udev_rules; struct sysfs_device { struct list_head node; /* for device cache */ struct sysfs_device *parent; /* already cached parent*/ - char devpath[PATH_SIZE]; - char subsystem[NAME_SIZE]; /* $class, $bus, drivers, module */ - char kernel[NAME_SIZE]; /* device instance name */ - char kernel_number[NAME_SIZE]; - char driver[NAME_SIZE]; /* device driver name */ + char devpath[UTIL_PATH_SIZE]; + char subsystem[UTIL_NAME_SIZE]; + char kernel[UTIL_NAME_SIZE]; /* device instance name */ + char kernel_number[UTIL_NAME_SIZE]; + char driver[UTIL_NAME_SIZE]; }; struct udevice { @@ -74,16 +68,16 @@ struct udevice { struct sysfs_device *dev; /* points to dev_local by default */ struct sysfs_device dev_local; struct sysfs_device *dev_parent; /* current parent device used for matching */ - char action[NAME_SIZE]; + char action[UTIL_NAME_SIZE]; char *devpath_old; /* node */ - char name[PATH_SIZE]; + char name[UTIL_PATH_SIZE]; struct list_head symlink_list; int symlink_final; - char owner[NAME_SIZE]; + char owner[UTIL_NAME_SIZE]; int owner_final; - char group[NAME_SIZE]; + char group[UTIL_NAME_SIZE]; int group_final; mode_t mode; int mode_final; @@ -93,11 +87,11 @@ struct udevice { struct list_head run_list; int run_final; struct list_head env_list; - char tmp_node[PATH_SIZE]; + char tmp_node[UTIL_PATH_SIZE]; int partitions; int ignore_device; int ignore_remove; - char program_result[PATH_SIZE]; + char program_result[UTIL_PATH_SIZE]; int link_priority; int event_timeout; int test_run; @@ -138,7 +132,6 @@ extern struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devp extern struct sysfs_device *sysfs_device_get_parent(struct udev *udev, struct sysfs_device *dev); extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct udev *udev, struct sysfs_device *dev, const char *subsystem); extern char *sysfs_attr_get_value(struct udev *udev, const char *devpath, const char *attr_name); -extern int sysfs_resolve_link(struct udev *udev, char *path, size_t size); extern int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath, size_t len, const char *subsystem, const char *id); /* udev_node.c */ @@ -158,11 +151,9 @@ extern int udev_db_get_all_entries(struct udev *udevconst, struct list_head *nam /* udev_utils.c */ struct name_entry { struct list_head node; - char name[PATH_SIZE]; + char name[UTIL_PATH_SIZE]; unsigned int ignore_error:1; }; - -extern int log_priority(const char *priority); extern struct name_entry *name_list_add(struct udev *udev, struct list_head *name_list, const char *name, int sort); extern struct name_entry *name_list_key_add(struct udev *udev, struct list_head *name_list, const char *key, const char *value); extern int name_list_key_remove(struct udev *udev, struct list_head *name_list, const char *key); diff --git a/udev/udev_db.c b/udev/udev_db.c index 763178d50..432aa6cbb 100644 --- a/udev/udev_db.c +++ b/udev/udev_db.c @@ -44,8 +44,8 @@ static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *f /* reverse mapping from the device file name to the devpath */ static int name_index(struct udev *udev, const char *devpath, const char *name, int add) { - char device[PATH_SIZE]; - char filename[PATH_SIZE * 2]; + char device[UTIL_PATH_SIZE]; + char filename[UTIL_PATH_SIZE * 2]; size_t start; int fd; @@ -96,7 +96,7 @@ int udev_db_get_devices_by_name(struct udev *udev, const char *name, struct list info(udev, "found index directory '%s'\n", dirname); while (1) { struct dirent *ent; - char device[PATH_SIZE]; + char device[UTIL_PATH_SIZE]; ent = readdir(dir); if (ent == NULL || ent->d_name[0] == '\0') @@ -116,8 +116,8 @@ out: int udev_db_rename(struct udev *udev, const char *devpath_old, const char *devpath) { - char filename[PATH_SIZE]; - char filename_old[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; + char filename_old[UTIL_PATH_SIZE]; devpath_to_db_path(udev, devpath_old, filename_old, sizeof(filename_old)); devpath_to_db_path(udev, devpath, filename, sizeof(filename)); @@ -126,7 +126,7 @@ int udev_db_rename(struct udev *udev, const char *devpath_old, const char *devpa int udev_db_add_device(struct udevice *udevice) { - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; if (udevice->test_run) return 0; @@ -190,8 +190,8 @@ int udev_db_add_device(struct udevice *udevice) int udev_db_get_device(struct udevice *udevice, const char *devpath) { struct stat stats; - char filename[PATH_SIZE]; - char line[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; + char line[UTIL_PATH_SIZE]; unsigned int maj, min; char *bufline; char *buf; @@ -207,7 +207,7 @@ int udev_db_get_device(struct udevice *udevice, const char *devpath) return -1; } if ((stats.st_mode & S_IFMT) == S_IFLNK) { - char target[NAME_SIZE]; + char target[UTIL_NAME_SIZE]; int target_len; info(udevice->udev, "found a symlink as db file\n"); @@ -277,7 +277,7 @@ int udev_db_get_device(struct udevice *udevice, const char *devpath) int udev_db_delete_device(struct udevice *udevice) { - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; struct name_entry *name_loop; if (udevice->test_run) @@ -308,7 +308,7 @@ int udev_db_get_all_entries(struct udev *udev, struct list_head *name_list) while (1) { struct dirent *ent; - char device[PATH_SIZE]; + char device[UTIL_PATH_SIZE]; ent = readdir(dir); if (ent == NULL || ent->d_name[0] == '\0') diff --git a/udev/udev_node.c b/udev/udev_node.c index 0319b2f87..8971f9ff3 100644 --- a/udev/udev_node.c +++ b/udev/udev_node.c @@ -34,7 +34,7 @@ int udev_node_mknod(struct udevice *udevice, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid) { - char file_tmp[PATH_SIZE + sizeof(TMP_FILE_EXT)]; + char file_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)]; struct stat stats; int preserve = 0; int err = 0; @@ -104,8 +104,8 @@ exit: static int node_symlink(struct udevice *udevice, const char *node, const char *slink) { struct stat stats; - char target[PATH_SIZE] = ""; - char slink_tmp[PATH_SIZE + sizeof(TMP_FILE_EXT)]; + char target[UTIL_PATH_SIZE] = ""; + char slink_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)]; int i = 0; int tail = 0; int len; @@ -140,7 +140,7 @@ static int node_symlink(struct udevice *udevice, const char *node, const char *s } } } else if (S_ISLNK(stats.st_mode)) { - char buf[PATH_SIZE]; + char buf[UTIL_PATH_SIZE]; info(udevice->udev, "found existing symlink '%s'\n", slink); len = readlink(slink, buf, sizeof(buf)); @@ -186,11 +186,11 @@ exit: static int update_link(struct udevice *udevice, const char *name) { LIST_HEAD(name_list); - char slink[PATH_SIZE]; - char node[PATH_SIZE]; + char slink[UTIL_PATH_SIZE]; + char node[UTIL_PATH_SIZE]; struct udevice *udevice_db; struct name_entry *device; - char target[PATH_MAX] = ""; + char target[UTIL_PATH_SIZE] = ""; int count; int priority = 0; int rc = 0; @@ -271,7 +271,7 @@ out: void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udevice_old) { struct name_entry *name_loop; - char symlinks[PATH_SIZE] = ""; + char symlinks[UTIL_PATH_SIZE] = ""; list_for_each_entry(name_loop, &udevice->symlink_list, node) { info(udevice->udev, "update symlink '%s' of '%s'\n", name_loop->name, udevice->dev->devpath); @@ -321,7 +321,7 @@ void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udevice_ int udev_node_add(struct udevice *udevice) { - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; uid_t uid; gid_t gid; int i; @@ -371,7 +371,7 @@ int udev_node_add(struct udevice *udevice) /* create all_partitions if requested */ if (udevice->partitions) { - char partitionname[PATH_SIZE]; + char partitionname[UTIL_PATH_SIZE]; char *attr; int range; @@ -400,8 +400,8 @@ exit: int udev_node_remove(struct udevice *udevice) { - char filename[PATH_SIZE]; - char partitionname[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; + char partitionname[UTIL_PATH_SIZE]; struct stat stats; int retval = 0; int num; diff --git a/udev/udev_rules.c b/udev/udev_rules.c index 72c859348..d4dcb0680 100644 --- a/udev/udev_rules.c +++ b/udev/udev_rules.c @@ -123,8 +123,8 @@ static int run_program(struct udev *udev, const char *command, const char *subsy int outpipe[2] = {-1, -1}; int errpipe[2] = {-1, -1}; pid_t pid; - char arg[PATH_SIZE]; - char program[PATH_SIZE]; + char arg[UTIL_PATH_SIZE]; + char program[UTIL_PATH_SIZE]; char *argv[(sizeof(arg) / 2) + 1]; int devnull; int i; @@ -331,7 +331,7 @@ static int run_program(struct udev *udev, const char *command, const char *subsy static int import_keys_into_env(struct udevice *udevice, const char *buf, size_t bufsize) { - char line[LINE_SIZE]; + char line[UTIL_LINE_SIZE]; const char *bufline; char *linepos; char *variable; @@ -358,7 +358,7 @@ static int import_keys_into_env(struct udevice *udevice, const char *buf, size_t continue; /* see if this is a comment */ - if (bufline[0] == COMMENT_CHARACTER) + if (bufline[0] == '#') continue; if (count >= sizeof(line)) { @@ -429,7 +429,7 @@ static int import_parent_into_env(struct udevice *udevice, const char *filter) if (udev_db_get_device(udev_parent, dev_parent->devpath) == 0) { dbg(udevice->udev, "import stored parent env '%s'\n", udev_parent->name); list_for_each_entry(name_loop, &udev_parent->env_list, node) { - char name[NAME_SIZE]; + char name[UTIL_NAME_SIZE]; char *pos; util_strlcpy(name, name_loop->name, sizeof(name)); @@ -512,7 +512,7 @@ int udev_rules_run(struct udevice *udevice) if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0) { pass_env_to_socket(udevice->udev, &name_loop->name[strlen("socket:")], udevice->dev->devpath, udevice->action); } else { - char program[PATH_SIZE]; + char program[UTIL_PATH_SIZE]; util_strlcpy(program, name_loop->name, sizeof(program)); udev_rules_apply_format(udevice, program, sizeof(program)); @@ -528,8 +528,8 @@ int udev_rules_run(struct udevice *udevice) #define WAIT_LOOP_PER_SECOND 50 static int wait_for_file(struct udevice *udevice, const char *file, int timeout) { - char filepath[PATH_SIZE]; - char devicepath[PATH_SIZE] = ""; + char filepath[UTIL_PATH_SIZE]; + char devicepath[UTIL_PATH_SIZE] = ""; struct stat stats; int loop = timeout * WAIT_LOOP_PER_SECOND; @@ -566,7 +566,7 @@ static int wait_for_file(struct udevice *udevice, const char *file, int timeout) /* handle "[$SUBSYSTEM/$KERNEL]" lookup */ static int attr_get_by_subsys_id(struct udev *udev, const char *attrstr, char *devpath, size_t len, char **attr) { - char subsys[NAME_SIZE]; + char subsys[UTIL_NAME_SIZE]; char *pos; char *id; char *attrib; @@ -610,7 +610,7 @@ static int attr_subst_subdir(char *attr, size_t len) pos = strstr(attr, "/*/"); if (pos != NULL) { - char str[PATH_SIZE]; + char str[UTIL_PATH_SIZE]; DIR *dir; pos[1] = '\0'; @@ -643,8 +643,8 @@ static int attr_subst_subdir(char *attr, size_t len) void udev_rules_apply_format(struct udevice *udevice, char *string, size_t maxsize) { - char temp[PATH_SIZE]; - char temp2[PATH_SIZE]; + char temp[UTIL_PATH_SIZE]; + char temp2[UTIL_PATH_SIZE]; char *head, *tail, *pos, *cpos, *attr, *rest; int len; int i; @@ -825,7 +825,7 @@ found: if (attr == NULL) err(udevice->udev, "missing file parameter for attr\n"); else { - char devpath[PATH_SIZE]; + char devpath[UTIL_PATH_SIZE]; char *attrib; const char *value = NULL; size_t size; @@ -915,7 +915,7 @@ found: case SUBST_LINKS: if (!list_empty(&udevice->symlink_list)) { struct name_entry *name_loop; - char symlinks[PATH_SIZE] = ""; + char symlinks[UTIL_PATH_SIZE] = ""; list_for_each_entry(name_loop, &udevice->symlink_list, node) { util_strlcat(symlinks, name_loop->name, sizeof(symlinks)); @@ -971,7 +971,7 @@ static char *key_pair_name(struct udev_rule *rule, struct key_pair *pair) static int match_key(struct udev *udev, const char *key_name, struct udev_rule *rule, struct key *key, const char *val) { - char value[PATH_SIZE]; + char value[UTIL_PATH_SIZE]; char *key_value; char *pos; int match = 0; @@ -1070,8 +1070,8 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) if (rule->test.operation == KEY_OP_MATCH || rule->test.operation == KEY_OP_NOMATCH) { - char filename[PATH_SIZE]; - char devpath[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; + char devpath[UTIL_PATH_SIZE]; char *attr; struct stat statbuf; int match; @@ -1087,7 +1087,7 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) util_strlcat(filename, attr, sizeof(filename)); } } else if (filename[0] != '/') { - char tmp[PATH_SIZE]; + char tmp[UTIL_PATH_SIZE]; util_strlcpy(tmp, udev_get_sys_path(udevice->udev), sizeof(tmp)); util_strlcat(tmp, udevice->dev->devpath, sizeof(tmp)); @@ -1114,7 +1114,7 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) } if (rule->wait_for.operation != KEY_OP_UNSET) { - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; int found; util_strlcpy(filename, key_val(rule, &rule->wait_for), sizeof(filename)); @@ -1132,10 +1132,10 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) pair->key.operation == KEY_OP_NOMATCH) { const char *key_name = key_pair_name(rule, pair); const char *key_value = key_val(rule, &pair->key); - char devpath[PATH_SIZE]; + char devpath[UTIL_PATH_SIZE]; char *attrib; const char *value = NULL; - char val[VALUE_SIZE]; + char val[UTIL_NAME_SIZE]; size_t len; if (attr_get_by_subsys_id(udevice->udev, key_name, devpath, sizeof(devpath), &attrib)) { @@ -1188,7 +1188,7 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) const char *key_name = key_pair_name(rule, pair); const char *key_value = key_val(rule, &pair->key); const char *value; - char val[VALUE_SIZE]; + char val[UTIL_NAME_SIZE]; size_t len; value = sysfs_attr_get_value(udevice->udev, udevice->dev_parent->devpath, key_name); @@ -1226,8 +1226,8 @@ try_parent: /* execute external program */ if (rule->program.operation != KEY_OP_UNSET) { - char program[PATH_SIZE]; - char result[PATH_SIZE]; + char program[UTIL_PATH_SIZE]; + char result[UTIL_PATH_SIZE]; util_strlcpy(program, key_val(rule, &rule->program), sizeof(program)); udev_rules_apply_format(udevice, program, sizeof(program)); @@ -1262,7 +1262,7 @@ try_parent: /* import variables returned from program or or file into environment */ if (rule->import.operation != KEY_OP_UNSET) { - char import[PATH_SIZE]; + char import[UTIL_PATH_SIZE]; int rc = -1; util_strlcpy(import, key_val(rule, &rule->import), sizeof(import)); @@ -1291,13 +1291,13 @@ try_parent: struct key_pair *pair = &rule->env.keys[i]; if (pair->key.operation == KEY_OP_ASSIGN) { - char temp_value[NAME_SIZE]; + char temp_value[UTIL_NAME_SIZE]; const char *key_name = key_pair_name(rule, pair); const char *value = key_val(rule, &pair->key); /* make sure we don't write to the same string we possibly read from */ util_strlcpy(temp_value, value, sizeof(temp_value)); - udev_rules_apply_format(udevice, temp_value, NAME_SIZE); + udev_rules_apply_format(udevice, temp_value, sizeof(temp_value)); if (temp_value[0] == '\0') { name_list_key_remove(udevice->udev, &udevice->env_list, key_name); @@ -1321,10 +1321,10 @@ try_parent: if (pair->key.operation == KEY_OP_ASSIGN) { const char *key_name = key_pair_name(rule, pair); - char devpath[PATH_SIZE]; + char devpath[UTIL_PATH_SIZE]; char *attrib; - char attr[PATH_SIZE] = ""; - char value[NAME_SIZE]; + char attr[UTIL_PATH_SIZE] = ""; + char value[UTIL_NAME_SIZE]; FILE *f; if (attr_get_by_subsys_id(udevice->udev, key_name, devpath, sizeof(devpath), &attrib)) { @@ -1445,7 +1445,7 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice) (rule->symlink.operation == KEY_OP_ASSIGN || rule->symlink.operation == KEY_OP_ASSIGN_FINAL || rule->symlink.operation == KEY_OP_ADD)) { - char temp[PATH_SIZE]; + char temp[UTIL_PATH_SIZE]; char *pos, *next; int count; diff --git a/udev/udev_rules_parse.c b/udev/udev_rules_parse.c index 1c5f36d49..a46eff98e 100644 --- a/udev/udev_rules_parse.c +++ b/udev/udev_rules_parse.c @@ -204,7 +204,7 @@ static char *get_key_attribute(struct udev_rules *rules, char *str) static int add_rule_key(struct udev_rule *rule, struct key *key, enum key_operation operation, const char *value) { - size_t val_len = strnlen(value, PATH_SIZE); + size_t val_len = strnlen(value, UTIL_PATH_SIZE); key->operation = operation; @@ -218,7 +218,7 @@ static int add_rule_key(struct udev_rule *rule, struct key *key, static int add_rule_key_pair(struct udev_rules *rules, struct udev_rule *rule, struct key_pairs *pairs, enum key_operation operation, const char *key, const char *value) { - size_t key_len = strnlen(key, PATH_SIZE); + size_t key_len = strnlen(key, UTIL_PATH_SIZE); if (pairs->count >= PAIRS_MAX) { err(rules->udev, "skip, too many keys of the same type in a single rule\n"); @@ -239,7 +239,7 @@ static int add_rule_key_pair(struct udev_rules *rules, struct udev_rule *rule, s static int add_to_rules(struct udev_rules *rules, char *line, const char *filename, unsigned int lineno) { - char buf[sizeof(struct udev_rule) + LINE_SIZE]; + char buf[sizeof(struct udev_rule) + UTIL_LINE_SIZE]; struct udev_rule *rule; size_t rule_size; int valid; @@ -444,7 +444,7 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena rule->import_type = IMPORT_PARENT; } else { /* figure it out if it is executable */ - char file[PATH_SIZE]; + char file[UTIL_PATH_SIZE]; char *pos; struct stat statbuf; @@ -668,7 +668,7 @@ invalid: static int parse_file(struct udev_rules *rules, const char *filename) { - char line[LINE_SIZE]; + char line[UTIL_LINE_SIZE]; char *bufline; unsigned int lineno; char *buf; @@ -703,7 +703,7 @@ static int parse_file(struct udev_rules *rules, const char *filename) continue; /* see if this is a comment */ - if (bufline[0] == COMMENT_CHARACTER) + if (bufline[0] == '#') continue; if (count >= sizeof(line)) { diff --git a/udev/udev_sysfs.c b/udev/udev_sysfs.c index 0d4a97118..97dcd0311 100644 --- a/udev/udev_sysfs.c +++ b/udev/udev_sysfs.c @@ -35,9 +35,9 @@ static LIST_HEAD(attr_list); struct sysfs_attr { struct list_head node; - char path[PATH_SIZE]; + char path[UTIL_PATH_SIZE]; char *value; /* points to value_local if value is cached */ - char value_local[NAME_SIZE]; + char value_local[UTIL_NAME_SIZE]; }; int sysfs_init(void) @@ -100,47 +100,15 @@ void sysfs_device_set_values(struct udev *udev, dbg(udev, "kernel_number='%s'\n", dev->kernel_number); } -int sysfs_resolve_link(struct udev *udev, char *devpath, size_t size) -{ - char link_path[PATH_SIZE]; - char link_target[PATH_SIZE]; - int len; - int i; - int back; - - util_strlcpy(link_path, udev_get_sys_path(udev), sizeof(link_path)); - util_strlcat(link_path, devpath, sizeof(link_path)); - len = readlink(link_path, link_target, sizeof(link_target)); - if (len <= 0) - return -1; - link_target[len] = '\0'; - dbg(udev, "path link '%s' points to '%s'\n", devpath, link_target); - - for (back = 0; strncmp(&link_target[back * 3], "../", 3) == 0; back++) - ; - dbg(udev, "base '%s', tail '%s', back %i\n", devpath, &link_target[back * 3], back); - for (i = 0; i <= back; i++) { - char *pos = strrchr(devpath, '/'); - - if (pos == NULL) - return -1; - pos[0] = '\0'; - } - dbg(udev, "after moving back '%s'\n", devpath); - util_strlcat(devpath, "/", size); - util_strlcat(devpath, &link_target[back * 3], size); - return 0; -} - struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devpath) { - char path[PATH_SIZE]; - char devpath_real[PATH_SIZE]; + char path[UTIL_PATH_SIZE]; + char devpath_real[UTIL_PATH_SIZE]; struct sysfs_device *dev; struct sysfs_device *dev_loop; struct stat statbuf; - char link_path[PATH_SIZE]; - char link_target[PATH_SIZE]; + char link_path[UTIL_PATH_SIZE]; + char link_target[UTIL_PATH_SIZE]; int len; char *pos; @@ -176,7 +144,7 @@ struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devpath) return NULL; } if (S_ISLNK(statbuf.st_mode)) { - if (sysfs_resolve_link(udev, devpath_real, sizeof(devpath_real)) != 0) + if (util_resolve_sys_link(udev, devpath_real, sizeof(devpath_real)) != 0) return NULL; /* now look for device in cache after path translation */ @@ -248,7 +216,7 @@ struct sysfs_device *sysfs_device_get(struct udev *udev, const char *devpath) struct sysfs_device *sysfs_device_get_parent(struct udev *udev, struct sysfs_device *dev) { - char parent_devpath[PATH_SIZE]; + char parent_devpath[UTIL_PATH_SIZE]; char *pos; dbg(udev, "open '%s'\n", dev->devpath); @@ -290,7 +258,7 @@ struct sysfs_device *sysfs_device_get_parent(struct udev *udev, struct sysfs_dev device_link: util_strlcpy(parent_devpath, dev->devpath, sizeof(parent_devpath)); util_strlcat(parent_devpath, "/device", sizeof(parent_devpath)); - if (sysfs_resolve_link(udev, parent_devpath, sizeof(parent_devpath)) != 0) + if (util_resolve_sys_link(udev, parent_devpath, sizeof(parent_devpath)) != 0) return NULL; /* get parent and remember it */ @@ -313,9 +281,9 @@ struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct udev *udev, s char *sysfs_attr_get_value(struct udev *udev, const char *devpath, const char *attr_name) { - char path_full[PATH_SIZE]; + char path_full[UTIL_PATH_SIZE]; const char *path; - char value[NAME_SIZE]; + char value[UTIL_NAME_SIZE]; struct sysfs_attr *attr_loop; struct sysfs_attr *attr; struct stat statbuf; @@ -357,7 +325,7 @@ char *sysfs_attr_get_value(struct udev *udev, const char *devpath, const char *a if (S_ISLNK(statbuf.st_mode)) { /* links return the last element of the target path */ - char link_target[PATH_SIZE]; + char link_target[UTIL_PATH_SIZE]; int len; const char *pos; @@ -409,7 +377,7 @@ out: int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath_full, size_t len, const char *subsystem, const char *id) { size_t sysfs_len; - char path_full[PATH_SIZE]; + char path_full[UTIL_PATH_SIZE]; char *path; struct stat statbuf; @@ -443,7 +411,7 @@ int sysfs_lookup_devpath_by_subsys_id(struct udev *udev, char *devpath_full, siz } if (strcmp(subsystem, "drivers") == 0) { - char subsys[NAME_SIZE]; + char subsys[UTIL_NAME_SIZE]; char *driver; util_strlcpy(subsys, id, sizeof(subsys)); @@ -492,7 +460,7 @@ out: return 0; found: if (S_ISLNK(statbuf.st_mode)) - sysfs_resolve_link(udev, path, sizeof(path_full) - sysfs_len); + util_resolve_sys_link(udev, path, sizeof(path_full) - sysfs_len); util_strlcpy(devpath_full, path, len); return 1; } diff --git a/udev/udev_utils.c b/udev/udev_utils.c index c051b20ab..09b965ef3 100644 --- a/udev/udev_utils.c +++ b/udev/udev_utils.c @@ -127,7 +127,7 @@ int add_matching_files(struct udev *udev, struct list_head *name_list, const cha { struct dirent *ent; DIR *dir; - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; dbg(udev, "open directory '%s'\n", dirname); dir = opendir(dirname); @@ -141,7 +141,7 @@ int add_matching_files(struct udev *udev, struct list_head *name_list, const cha if (ent == NULL || ent->d_name[0] == '\0') break; - if ((ent->d_name[0] == '.') || (ent->d_name[0] == COMMENT_CHARACTER)) + if ((ent->d_name[0] == '.') || (ent->d_name[0] == '#')) continue; /* look for file matching with specified suffix */ diff --git a/udev/udev_utils_file.c b/udev/udev_utils_file.c index abe17eb30..1c7b07347 100644 --- a/udev/udev_utils_file.c +++ b/udev/udev_utils_file.c @@ -31,7 +31,7 @@ int create_path(struct udev *udev, const char *path) { - char p[PATH_SIZE]; + char p[UTIL_PATH_SIZE]; char *pos; struct stat stats; int ret; @@ -67,7 +67,7 @@ int create_path(struct udev *udev, const char *path) int delete_path(struct udev *udev, const char *path) { - char p[PATH_SIZE]; + char p[UTIL_PATH_SIZE]; char *pos; int retval; diff --git a/udev/udevadm-info.c b/udev/udevadm-info.c index 172d5638c..22f3d49d4 100644 --- a/udev/udevadm-info.c +++ b/udev/udevadm-info.c @@ -34,7 +34,7 @@ static void print_all_attributes(struct udev *udev, const char *devpath, const char *key) { - char path[PATH_SIZE]; + char path[UTIL_PATH_SIZE]; DIR *dir; struct dirent *dent; @@ -45,9 +45,9 @@ static void print_all_attributes(struct udev *udev, const char *devpath, const c if (dir != NULL) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { struct stat statbuf; - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; char *attr_value; - char value[NAME_SIZE]; + char value[UTIL_NAME_SIZE]; size_t len; if (dent->d_name[0] == '.') @@ -180,7 +180,7 @@ static int lookup_device_by_name(struct udev *udev, struct udevice **udevice, co /* select the device that seems to match */ list_for_each_entry(device, &name_list, node) { struct udevice *udevice_loop; - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; struct stat statbuf; udevice_loop = udev_device_init(udev); @@ -269,8 +269,8 @@ int udevadm_info(struct udev *udev, int argc, char *argv[]) QUERY_ALL, } query = QUERY_NONE; - char path[PATH_SIZE] = ""; - char name[PATH_SIZE] = ""; + char path[UTIL_PATH_SIZE] = ""; + char name[UTIL_PATH_SIZE] = ""; struct name_entry *name_loop; int rc = 0; @@ -301,19 +301,19 @@ int udevadm_info(struct udev *udev, int argc, char *argv[]) util_remove_trailing_chars(path, '/'); /* possibly resolve to real devpath */ - if (sysfs_resolve_link(udev, path, sizeof(path)) != 0) { - char temp[PATH_SIZE]; + if (util_resolve_sys_link(udev, path, sizeof(path)) != 0) { + char temp[UTIL_PATH_SIZE]; char *pos; /* also check if the parent is a link */ util_strlcpy(temp, path, sizeof(temp)); pos = strrchr(temp, '/'); if (pos != 0) { - char tail[PATH_SIZE]; + char tail[UTIL_PATH_SIZE]; util_strlcpy(tail, pos, sizeof(tail)); pos[0] = '\0'; - if (sysfs_resolve_link(udev, temp, sizeof(temp)) == 0) { + if (util_resolve_sys_link(udev, temp, sizeof(temp)) == 0) { util_strlcpy(path, temp, sizeof(path)); util_strlcat(path, tail, sizeof(path)); } diff --git a/udev/udevadm-settle.c b/udev/udevadm-settle.c index ed67bbbdf..78ac47ff4 100644 --- a/udev/udevadm-settle.c +++ b/udev/udevadm-settle.c @@ -44,7 +44,7 @@ static void print_queue(struct udev *udev, const char *dir) printf("\n\nAfter the udevadm settle timeout, the events queue contains:\n\n"); list_for_each_entry(item, &files, node) { - char target[NAME_SIZE]; + char target[UTIL_NAME_SIZE]; size_t len; const char *filename = strrchr(item->name, '/'); @@ -67,8 +67,8 @@ static void print_queue(struct udev *udev, const char *dir) int udevadm_settle(struct udev *udev, int argc, char *argv[]) { - char queuename[PATH_SIZE]; - char filename[PATH_SIZE]; + char queuename[UTIL_PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; unsigned long long seq_kernel; unsigned long long seq_udev; char seqnum[32]; diff --git a/udev/udevadm-test.c b/udev/udevadm-test.c index b6fccf34e..ba0852871 100644 --- a/udev/udevadm-test.c +++ b/udev/udevadm-test.c @@ -33,7 +33,7 @@ static int import_uevent_var(struct udev *udev, const char *devpath) { - char path[PATH_SIZE]; + char path[UTIL_PATH_SIZE]; static char value[4096]; /* must stay, used with putenv */ ssize_t size; int fd; @@ -189,7 +189,7 @@ int udevadm_test(struct udev *udev, int argc, char *argv[]) struct name_entry *name_loop; list_for_each_entry(name_loop, &udevice->run_list, node) { - char program[PATH_SIZE]; + char program[UTIL_PATH_SIZE]; util_strlcpy(program, name_loop->name, sizeof(program)); udev_rules_apply_format(udevice, program, sizeof(program)); diff --git a/udev/udevadm-trigger.c b/udev/udevadm-trigger.c index 04fb9bcbc..f0535f5eb 100644 --- a/udev/udevadm-trigger.c +++ b/udev/udevadm-trigger.c @@ -64,8 +64,8 @@ static int delay_device(const char *devpath) static int device_list_insert(struct udev *udev, const char *path) { - char filename[PATH_SIZE]; - char devpath[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; + char devpath[UTIL_PATH_SIZE]; struct stat statbuf; dbg(udev, "add '%s'\n" , path); @@ -84,7 +84,7 @@ static int device_list_insert(struct udev *udev, const char *path) if (lstat(path, &statbuf) < 0) return -1; if (S_ISLNK(statbuf.st_mode)) - if (sysfs_resolve_link(udev, devpath, sizeof(devpath)) != 0) + if (util_resolve_sys_link(udev, devpath, sizeof(devpath)) != 0) return -1; name_list_add(udev, &device_list, devpath, 1); @@ -93,7 +93,7 @@ static int device_list_insert(struct udev *udev, const char *path) static void trigger_uevent(struct udev *udev, const char *devpath, const char *action) { - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; int fd; util_strlcpy(filename, udev_get_sys_path(udev), sizeof(filename)); @@ -125,9 +125,9 @@ static int pass_to_socket(struct udev *udev, const char *devpath, const char *ac char buf[4096]; size_t bufpos = 0; ssize_t count; - char path[PATH_SIZE]; + char path[UTIL_PATH_SIZE]; int fd; - char link_target[PATH_SIZE]; + char link_target[UTIL_PATH_SIZE]; int len; int err = 0; @@ -285,8 +285,8 @@ static int subsystem_filtered(const char *subsystem) static int attr_match(const char *path, const char *attr_value) { - char attr[NAME_SIZE]; - char file[PATH_SIZE]; + char attr[UTIL_NAME_SIZE]; + char file[UTIL_PATH_SIZE]; char *match_value; util_strlcpy(attr, attr_value, sizeof(attr)); @@ -304,7 +304,7 @@ static int attr_match(const char *path, const char *attr_value) if (match_value != NULL) { /* match file content */ - char value[NAME_SIZE]; + char value[UTIL_NAME_SIZE]; int fd; ssize_t size; @@ -357,7 +357,7 @@ enum scan_type { static void scan_subsystem(struct udev *udev, const char *subsys, enum scan_type scan) { - char base[PATH_SIZE]; + char base[UTIL_PATH_SIZE]; DIR *dir; struct dirent *dent; const char *subdir; @@ -376,7 +376,7 @@ static void scan_subsystem(struct udev *udev, const char *subsys, enum scan_type dir = opendir(base); if (dir != NULL) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char dirname[PATH_SIZE]; + char dirname[UTIL_PATH_SIZE]; DIR *dir2; struct dirent *dent2; @@ -406,7 +406,7 @@ static void scan_subsystem(struct udev *udev, const char *subsys, enum scan_type dir2 = opendir(dirname); if (dir2 != NULL) { for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) { - char dirname2[PATH_SIZE]; + char dirname2[UTIL_PATH_SIZE]; if (dent2->d_name[0] == '.') continue; @@ -427,7 +427,7 @@ static void scan_subsystem(struct udev *udev, const char *subsys, enum scan_type static void scan_block(struct udev *udev) { - char base[PATH_SIZE]; + char base[UTIL_PATH_SIZE]; DIR *dir; struct dirent *dent; @@ -440,7 +440,7 @@ static void scan_block(struct udev *udev) dir = opendir(base); if (dir != NULL) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char dirname[PATH_SIZE]; + char dirname[UTIL_PATH_SIZE]; DIR *dir2; struct dirent *dent2; @@ -459,7 +459,7 @@ static void scan_block(struct udev *udev) dir2 = opendir(dirname); if (dir2 != NULL) { for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) { - char dirname2[PATH_SIZE]; + char dirname2[UTIL_PATH_SIZE]; if (dent2->d_name[0] == '.') continue; @@ -483,7 +483,7 @@ static void scan_block(struct udev *udev) static void scan_class(struct udev *udev) { - char base[PATH_SIZE]; + char base[UTIL_PATH_SIZE]; DIR *dir; struct dirent *dent; @@ -493,7 +493,7 @@ static void scan_class(struct udev *udev) dir = opendir(base); if (dir != NULL) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char dirname[PATH_SIZE]; + char dirname[UTIL_PATH_SIZE]; DIR *dir2; struct dirent *dent2; @@ -509,7 +509,7 @@ static void scan_class(struct udev *udev) dir2 = opendir(dirname); if (dir2 != NULL) { for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) { - char dirname2[PATH_SIZE]; + char dirname2[UTIL_PATH_SIZE]; if (dent2->d_name[0] == '.') continue; @@ -533,7 +533,7 @@ static void scan_class(struct udev *udev) static void scan_failed(struct udev *udev) { - char base[PATH_SIZE]; + char base[UTIL_PATH_SIZE]; DIR *dir; struct dirent *dent; @@ -543,7 +543,7 @@ static void scan_failed(struct udev *udev) dir = opendir(base); if (dir != NULL) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char device[PATH_SIZE]; + char device[UTIL_PATH_SIZE]; size_t start; if (dent->d_name[0] == '.') @@ -671,7 +671,7 @@ int udevadm_trigger(struct udev *udev, int argc, char *argv[]) scan_failed(udev); exec_list(udev, action, env); } else { - char base[PATH_SIZE]; + char base[UTIL_PATH_SIZE]; struct stat statbuf; /* if we have /sys/subsystem, forget all the old stuff */ diff --git a/udev/udevd.c b/udev/udevd.c index 59866afde..d64beef3a 100644 --- a/udev/udevd.c +++ b/udev/udevd.c @@ -168,8 +168,8 @@ enum event_state { static void export_event_state(struct udevd_uevent_msg *msg, enum event_state state) { - char filename[PATH_SIZE]; - char filename_failed[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; + char filename_failed[UTIL_PATH_SIZE]; size_t start; /* location of queue file */ @@ -194,7 +194,7 @@ static void export_event_state(struct udevd_uevent_msg *msg, enum event_state st case EVENT_FINISHED: if (msg->devpath_old != NULL) { /* "move" event - rename failed file to current name, do not delete failed */ - char filename_failed_old[PATH_SIZE]; + char filename_failed_old[UTIL_PATH_SIZE]; util_strlcpy(filename_failed_old, udev_get_dev_path(msg->udev), sizeof(filename_failed_old)); util_strlcat(filename_failed_old, "/", sizeof(filename_failed_old)); @@ -279,7 +279,7 @@ static void udev_event_run(struct udevd_uevent_msg *msg) static void msg_queue_insert(struct udevd_uevent_msg *msg) { - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; int fd; msg->queue_time = time(NULL); @@ -346,7 +346,7 @@ static int compare_devpath(const char *running, const char *waiting) { int i; - for (i = 0; i < PATH_SIZE; i++) { + for (i = 0; i < UTIL_PATH_SIZE; i++) { /* identical device event found */ if (running[i] == '\0' && waiting[i] == '\0') return 1; @@ -750,7 +750,7 @@ static int init_uevent_netlink_sock(struct udev *udev) static void export_initial_seqnum(struct udev *udev) { - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; int fd; char seqnum[32]; ssize_t len = 0; -- 2.30.2