From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Marco d'Itri" Date: Sat, 21 Feb 2004 18:12:22 +0000 Subject: patches for udev 018 Message-Id: <20040221181222.GA14818@wonderland.linux.it> MIME-Version: 1 Content-Type: multipart/mixed; boundary="J2SCkAp4GZ/dPZZf" List-Id: To: linux-hotplug@vger.kernel.org --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline fix_expr: remove usage of expr in ide-devfs.sh, because it may be in /usr/bin and not available at early boot time. fix_segfault: fix a segfault when udev is started without the command line parameter. makefile_clean: delete all binaries when cleaning merge_symlinks: allow multiple KERNEL=... SYMLINK=... directives multiple_rules: allow listing more than one rules file in udev.conf no_error_on_enoent: do not exit with an error and delete all files remove_warnings: fix a compile time warning -- ciao, | Marco | [4695 sc.Be13Nezixw] --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=fix_expr diff -ruN udev-018.orig/extras/ide-devfs.sh udev-018/extras/ide-devfs.sh --- udev-018.orig/extras/ide-devfs.sh 2004-02-19 19:38:37.000000000 +0100 +++ udev-018/extras/ide-devfs.sh 2004-02-21 17:57:06.000000000 +0100 @@ -8,7 +8,7 @@ TARGET="${2#[0-9]\.}" if [ -z "${HOST#[13579]}" ]; then - HOST=`expr ${HOST} - 1` + HOST=$((${HOST} - 1)) BUS="1" else BUS="0" @@ -24,7 +24,7 @@ if [ -e "${x}" ]; then MEDIA=`cat ${x}` if [ "${MEDIA}" = "$2" ]; then - num=`expr ${num} + 1` + num=$((${num} + 1)) fi if [ "${x}" = "/proc/ide/${DRIVE}/media" ]; then break @@ -32,7 +32,7 @@ fi done - echo `expr ${num} - 1` + echo $((${num} - 1)) } if [ -z "$3" ]; then --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=fix_segfault diff -ruN udev-018.orig/udev.c udev-018/udev.c --- udev-018.orig/udev.c 2004-02-19 19:38:35.000000000 +0100 +++ udev-018/udev.c 2004-02-21 11:40:26.000000000 +0100 @@ -129,8 +129,13 @@ goto exit; } - /* skip blacklisted subsystems */ subsystem = argv[1]; + if (!subsystem) { + dbg ("no subsystem?"); + goto exit; + } + + /* skip blacklisted subsystems */ i = 0; while (subsystem_blacklist[i][0] != '\0') { if (strcmp(subsystem, subsystem_blacklist[i]) == 0) { --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=makefile_clean diff -ruN udev-018.orig/Makefile udev-018/Makefile --- udev-018.orig/Makefile 2004-02-19 19:38:36.000000000 +0100 +++ udev-018/Makefile 2004-02-21 13:41:36.000000000 +0100 @@ -278,7 +278,7 @@ clean: -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \ | xargs rm -f - -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(HELPER) $(DAEMON) $(SENDER) + -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(TESTER) $(HELPER) $(DAEMON) $(SENDER) $(MAKE) -C klibc clean @extras="$(EXTRAS)" ; for target in $$extras ; do \ echo $$target ; \ --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=merge_symlinks diff -ruN udev-018.orig/namedev.c udev-018/namedev.c --- udev-018.orig/namedev.c 2004-02-19 19:38:37.000000000 +0100 +++ udev-018/namedev.c 2004-02-21 12:57:35.000000000 +0100 @@ -805,30 +805,54 @@ list_for_each_entry(dev, &config_device_list, node) { dbg("process rule"); if (match_rule(dev, class_dev, udev, sysfs_device) == 0) { - if (dev->name[0] == '\0') { + if (dev->name[0] == '\0' && dev->name[0] == '\0' + && dev->symlink[0] == '\0') { info("configured rule in '%s' at line %i applied, '%s' is ignored", udev_rules_filename, dev->config_line, udev->kernel_name); return -1; } - info("configured rule in '%s' at line %i applied, '%s' becomes '%s'", - udev_rules_filename, dev->config_line, udev->kernel_name, dev->name); - strfieldcpy(udev->name, dev->name); - strfieldcpy(udev->symlink, dev->symlink); - goto found; + /* if everything matched add symlink to list of aliases */ + if (dev->symlink[0] != '\0') { + char temp[NAME_MAX]; + + /* do not clobber dev */ + strfieldcpy(temp, dev->symlink); + apply_format(udev, temp, class_dev, sysfs_device); + if (strlen(udev->symlink) + strlen(temp) + 2 + > sizeof(udev->symlink)) { + dbg("could not append symlink %s for %s", + dev->symlink, udev->kernel_name); + } else { + strfieldcat(udev->symlink, temp); + strfieldcat(udev->symlink, " "); + } + } + + /* is this symlink only rule? */ + if (dev->name[0] == '\0') + continue; + + /* Yup, this rule belongs to us! + * but continue to collect symlinks */ + if (udev->name[0] == '\0') { + info("configured rule line %i applied, '%s' becomes '%s'", + dev->config_line, udev->kernel_name, dev->name); + strfieldcpy(udev->name, dev->name); + /* substitute placeholder */ + apply_format(udev, udev->name, class_dev, sysfs_device); + } else { + dbg("conflicting rule for '%s' would become '%s'", + dev->kernel, dev->name); + } } } - /* no rule was found so we use the kernel name */ - strfieldcpy(udev->name, udev->kernel_name); - goto done; - -found: - /* substitute placeholder */ - apply_format(udev, udev->name, class_dev, sysfs_device); - apply_format(udev, udev->symlink, class_dev, sysfs_device); - udev->partitions = dev->partitions; -done: + /* no rule was found, so we use the kernel name */ + if (udev->name[0] == '\0') + strfieldcpy(udev->name, class_dev->name); + dbg("symlinks for '%s' are: '%s'", udev->name, udev->symlink); + perm = find_perm(udev->name); if (perm) { udev->mode = perm->mode; diff -ruN udev-018.orig/udev.h udev-018/udev.h --- udev-018.orig/udev.h 2004-02-19 19:38:37.000000000 +0100 +++ udev-018/udev.h 2004-02-21 12:12:58.000000000 +0100 @@ -61,6 +61,12 @@ strncpy(to, from, sizeof(to)-1); \ } while (0) +#define strfieldcat(to, from) \ +do { \ + to[sizeof(to)-1] = '\0'; \ + strncat(to, from, sizeof(to)-1); \ +} while (0) + extern int udev_add_device(char *path, char *subsystem, int fake); extern int udev_remove_device(char *path, char *subsystem); extern void udev_init_config(void); --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=multiple_rules diff -ruN udev-018.orig/namedev_parse.c udev-018/namedev_parse.c --- udev-018.orig/namedev_parse.c 2004-02-19 19:38:35.000000000 +0100 +++ udev-018/namedev_parse.c 2004-02-21 15:30:29.000000000 +0100 @@ -114,7 +114,32 @@ return NULL; } -int namedev_init_rules(void) +static int call_foreach_file(int parser (const char *f) , char *filenames) +{ + char *start = filenames; + int retval = 0; + + while (1) { + char *end, *file; + + for (end = start; !isspace(*end) && *end != '\0'; end++) + ; + + file = malloc(end - start + 1); + strncpy(file, start, end - start); + file[end - start] = '\0'; + retval += parser(file); + free(file); + + if (*end == '\0') + break; + start = end + 1; + } + + return retval; +} + +static int namedev_parse_rules(const char *filename) { char line[255]; int lineno; @@ -127,11 +152,11 @@ int retval = 0; struct config_device dev; - fd = fopen(udev_rules_filename, "r"); + fd = fopen(filename, "r"); if (fd != NULL) { - dbg("reading '%s' as rules file", udev_rules_filename); + dbg("reading '%s' as rules file", filename); } else { - dbg("can't open '%s' as a rules file", udev_rules_filename); + dbg("can't open '%s' as a rules file", filename); return -ENODEV; } @@ -262,7 +287,7 @@ continue; error: dbg("%s:%d:%d: parse error, rule skipped", - udev_rules_filename, lineno, temp - line); + filename, lineno, temp - line); } } exit: @@ -270,6 +295,11 @@ return retval; } +int namedev_init_rules(void) +{ + return call_foreach_file(namedev_parse_rules, udev_rules_filename); +} + int namedev_init_permissions(void) { char line[255]; --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=no_error_on_enoent diff -ruN udev-018.orig/udev-remove.c udev-018/udev-remove.c --- udev-018.orig/udev-remove.c 2004-02-19 19:38:35.000000000 +0100 +++ udev-018/udev-remove.c 2004-02-21 13:40:21.000000000 +0100 @@ -51,6 +51,8 @@ /* remove if empty */ retval = rmdir(path); + if (errno == ENOENT) + retval = 0; if (retval) { if (errno == ENOTEMPTY) return 0; @@ -77,6 +79,8 @@ info("removing device node '%s'", filename); retval = unlink(filename); + if (errno == ENOENT) + retval = 0; if (retval) { dbg("unlink(%s) failed with error '%s'", filename, strerror(errno)); @@ -108,6 +112,8 @@ dbg("unlinking symlink '%s'", filename); retval = unlink(filename); + if (errno == ENOENT) + retval = 0; if (retval) { dbg("unlink(%s) failed with error '%s'", filename, strerror(errno)); --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=remove_warnings diff -ruN udev-016.orig/logging.h udev-016/logging.h --- udev-016.orig/logging.h 2004-02-02 10:34:49.000000000 +0100 +++ udev-016/logging.h 2004-02-03 22:27:43.000000000 +0100 @@ -32,6 +32,7 @@ #ifdef LOG #include #include +#include #undef info #define info(format, arg...) \ --J2SCkAp4GZ/dPZZf-- ------------------------------------------------------- SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now! http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel