2 * udev_multiplex.c directory multiplexer
4 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
12 * This essentially emulates the following shell script logic in C:
14 * export DEVNAME="whatever_dev_name_udev_just_gave"
15 * for I in "${DIR}/$DEVNAME/"*.dev "${DIR}/$1/"*.dev "${DIR}/default/"*.dev ; do
16 * if [ -f $I ]; then $I $1 ; fi
24 #include <sys/types.h>
31 #include "udev_libc_wrapper.h"
32 #include "udev_utils.h"
37 * runs files in these directories in order:
38 * <node name given by udev>/
42 void udev_multiplex_directory(struct udevice *udev, const char *basedir, const char *suffix)
44 char dirname[PATH_SIZE];
45 struct name_entry *name_loop, *name_tmp;
48 /* chop the device name up into pieces based on '/' */
49 if (udev->name[0] != '\0') {
50 char devname[PATH_SIZE];
53 strlcpy(devname, udev->name, sizeof(devname));
54 temp = strchr(devname, '/');
55 while (temp != NULL) {
58 /* don't call the subsystem directory here */
59 if (strcmp(devname, udev->subsystem) != 0) {
60 snprintf(dirname, sizeof(dirname), "%s/%s", basedir, devname);
61 dirname[sizeof(dirname)-1] = '\0';
62 add_matching_files(&name_list, dirname, suffix);
67 temp = strchr(temp, '/');
71 if (udev->name[0] != '\0') {
72 snprintf(dirname, sizeof(dirname), "%s/%s", basedir, udev->name);
73 dirname[sizeof(dirname)-1] = '\0';
74 add_matching_files(&name_list, dirname, suffix);
77 if (udev->subsystem[0] != '\0') {
78 snprintf(dirname, sizeof(dirname), "%s/%s", basedir, udev->subsystem);
79 dirname[sizeof(dirname)-1] = '\0';
80 add_matching_files(&name_list, dirname, suffix);
83 snprintf(dirname, sizeof(dirname), "%s/default", basedir);
84 dirname[sizeof(dirname)-1] = '\0';
85 add_matching_files(&name_list, dirname, suffix);
87 list_for_each_entry_safe(name_loop, name_tmp, &name_list, node) {
88 execute_command(name_loop->name, udev->subsystem);
89 list_del(&name_loop->node);