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.
10 * Based on the klibc version of hotplug written by:
11 * Author(s) Christian Borntraeger <cborntra@de.ibm.com>
12 * which was based on the shell script written by:
13 * Greg Kroah-Hartman <greg@kroah.com>
18 * This essentially emulates the following shell script logic in C:
20 export DEVNODE="whatever_dev_name_udev_just_gave"
21 for I in "${DIR}/$DEVNODE/"*.dev "${DIR}/$1/"*.dev "${DIR}/default/"*.dev ; do
22 if [ -f $I ]; then $I $1 ; fi
31 #include <sys/types.h>
38 #define HOTPLUGDIR "/etc/dev.d"
39 #define COMMENT_PREFIX '#'
41 static void run_program(char *name)
45 dbg("running %s", name);
59 execv(name, main_argv);
63 static void execute_dir (char *dirname)
69 dbg("opening %s", dirname);
70 directory = opendir(dirname);
74 while ((entry = readdir(directory))) {
75 if (entry->d_name[0] == '\0')
77 /* Don't run the files '.', '..', or hidden files,
78 * or files that start with a '#' */
79 if ((entry->d_name[0] == '.') ||
80 (entry->d_name[0] == COMMENT_PREFIX))
83 /* FIXME - need to use file_list_insert() here to run these in sorted order... */
84 snprintf(filename, sizeof(filename), "%s%s", dirname, entry->d_name);
85 filename[sizeof(filename)-1] = '\0';
86 run_program(filename);
92 /* runs files in these directories in order:
97 void dev_d_send(struct udevice *dev, char *subsystem)
100 char devnode[NAME_SIZE];
102 strfieldcpy(devnode, udev_root);
103 strfieldcat(devnode, dev->name);
104 setenv("DEVNODE", devnode, 1);
106 snprintf(dirname, sizeof(dirname), HOTPLUGDIR "/%s/", dev->name);
107 dirname[sizeof(dirname)-1] = '\0';
108 execute_dir(dirname);
110 snprintf(dirname, sizeof(dirname), HOTPLUGDIR "/%s/", subsystem);
111 dirname[sizeof(dirname)-1] = '\0';
112 execute_dir(dirname);
114 strcpy(dirname, HOTPLUGDIR "/default/");
115 execute_dir(dirname);