2 * dev_d.c - dev.d/ 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>
35 #define DEVD_DIR "/etc/dev.d/"
36 #define DEVD_SUFFIX ".dev"
38 static int run_program(char *name)
43 dbg("running %s", name);
49 udevdb_exit(); /* close udevdb */
50 fd = open("/dev/null", O_RDWR);
52 dup2(fd, STDOUT_FILENO);
53 dup2(fd, STDIN_FILENO);
54 dup2(fd, STDERR_FILENO);
57 execv(name, main_argv);
58 dbg("exec of child failed");
61 dbg("fork of child failed");
72 * runs files in these directories in order:
73 * <node name given by udev>/
77 void dev_d_send(struct udevice *dev, const char *subsystem, const char *devpath)
80 char env_devname[NAME_SIZE];
87 memset(env_devname, 0x00, sizeof(env_devname));
88 if (dev->type == 'b' || dev->type == 'c') {
89 strfieldcpy(env_devname, udev_root);
90 strfieldcat(env_devname, dev->name);
91 } else if (dev->type == 'n') {
92 strfieldcpy(env_devname, dev->name);
93 setenv("DEVPATH", devpath, 1);
95 setenv("DEVNAME", env_devname, 1);
96 dbg("DEVNAME='%s'", env_devname);
98 devname = strdup(dev->name);
100 dbg("out of memory");
104 /* Chop the device name up into pieces based on '/' */
105 temp = strchr(devname, '/');
106 while (temp != NULL) {
108 strcpy(dirname, DEVD_DIR);
109 strfieldcat(dirname, devname);
110 call_foreach_file(run_program, dirname, DEVD_SUFFIX);
114 temp = strchr(temp, '/');
117 strcpy(dirname, DEVD_DIR);
118 strfieldcat(dirname, dev->name);
119 call_foreach_file(run_program, dirname, DEVD_SUFFIX);
121 strcpy(dirname, DEVD_DIR);
122 strfieldcat(dirname, subsystem);
123 call_foreach_file(run_program, dirname, DEVD_SUFFIX);
125 strcpy(dirname, DEVD_DIR "default");
126 call_foreach_file(run_program, dirname, DEVD_SUFFIX);