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(const char *filename, void *data)
42 struct udevice *udev = data;
44 dbg("running %s", filename);
50 fd = open("/dev/null", O_RDWR);
52 dup2(fd, STDOUT_FILENO);
53 dup2(fd, STDIN_FILENO);
54 dup2(fd, STDERR_FILENO);
58 execl(filename, filename, udev->subsystem, NULL);
59 dbg("exec of child failed");
62 dbg("fork of child failed");
66 waitpid(pid, NULL, 0);
73 * runs files in these directories in order:
74 * <node name given by udev>/
78 void dev_d_execute(struct udevice *udev)
80 char dirname[PATH_MAX];
81 char devname[NAME_SIZE];
84 /* skip if UDEV_NO_DEVD is set */
88 /* skip if udev did nothing, like unchanged netif or no "dev" file */
89 if (udev->devname[0] == '\0')
92 /* add the node name or the netif name to the environment */
93 setenv("DEVNAME", udev->devname, 1);
94 dbg("DEVNAME='%s'", udev->devname);
96 strfieldcpy(devname, udev->name);
98 /* Chop the device name up into pieces based on '/' */
99 temp = strchr(devname, '/');
100 while (temp != NULL) {
102 strcpy(dirname, DEVD_DIR);
103 strfieldcat(dirname, devname);
104 call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
108 temp = strchr(temp, '/');
111 strcpy(dirname, DEVD_DIR);
112 strfieldcat(dirname, udev->name);
113 call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
115 strcpy(dirname, DEVD_DIR);
116 strfieldcat(dirname, udev->subsystem);
117 call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
119 strcpy(dirname, DEVD_DIR "default");
120 call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);