]>
Commit | Line | Data |
---|---|---|
dd64e26b | 1 | /* |
4a539daf | 2 | * dev_d.c - dev.d/ multiplexer |
dd64e26b GKH |
3 | * |
4 | * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com> | |
5 | * | |
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. | |
dd64e26b GKH |
9 | */ |
10 | ||
4a539daf | 11 | /* |
dd64e26b | 12 | * This essentially emulates the following shell script logic in C: |
4a539daf | 13 | * DIR="/etc/dev.d" |
4b06c852 | 14 | * export DEVNAME="whatever_dev_name_udev_just_gave" |
15 | * for I in "${DIR}/$DEVNAME/"*.dev "${DIR}/$1/"*.dev "${DIR}/default/"*.dev ; do | |
4a539daf KS |
16 | * if [ -f $I ]; then $I $1 ; fi |
17 | * done | |
18 | * exit 1; | |
dd64e26b GKH |
19 | */ |
20 | ||
dd64e26b GKH |
21 | #include <stdio.h> |
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
24 | #include <sys/types.h> | |
25 | #include <sys/wait.h> | |
26 | #include <unistd.h> | |
27 | #include "udev.h" | |
28 | #include "udev_lib.h" | |
29 | #include "logging.h" | |
30 | ||
4a539daf KS |
31 | #define DEVD_DIR "/etc/dev.d/" |
32 | #define DEVD_SUFFIX ".dev" | |
dd64e26b | 33 | |
4a539daf | 34 | static int run_program(char *name) |
dd64e26b GKH |
35 | { |
36 | pid_t pid; | |
37 | ||
38 | dbg("running %s", name); | |
39 | ||
40 | pid = fork(); | |
4a539daf KS |
41 | switch (pid) { |
42 | case 0: | |
43 | /* child */ | |
44 | execv(name, main_argv); | |
45 | dbg("exec of child failed"); | |
46 | exit(1); | |
47 | case -1: | |
48 | dbg("fork of child failed"); | |
49 | break; | |
50 | return -1; | |
51 | default: | |
dd64e26b | 52 | wait(NULL); |
dd64e26b GKH |
53 | } |
54 | ||
4a539daf | 55 | return 0; |
dd64e26b GKH |
56 | } |
57 | ||
4a539daf KS |
58 | /* |
59 | * runs files in these directories in order: | |
60 | * <node name given by udev>/ | |
61 | * subsystem/ | |
62 | * default/ | |
dd64e26b | 63 | */ |
eb6c7cd0 | 64 | void dev_d_send(struct udevice *dev, const char *subsystem, const char *devpath) |
dd64e26b GKH |
65 | { |
66 | char dirname[256]; | |
a3e6c800 GKH |
67 | char env_devname[NAME_SIZE]; |
68 | char *devname; | |
69 | char *temp; | |
dd64e26b | 70 | |
bbbe503e KS |
71 | if (udev_dev_d == 0) |
72 | return; | |
73 | ||
74 | if (dev->type == 'b' || dev->type == 'c') { | |
a3e6c800 GKH |
75 | strfieldcpy(env_devname, udev_root); |
76 | strfieldcat(env_devname, dev->name); | |
bbbe503e | 77 | } else if (dev->type == 'n') { |
a3e6c800 | 78 | strfieldcpy(env_devname, dev->name); |
9b28a52a | 79 | setenv("DEVPATH", devpath, 1); |
bbbe503e | 80 | } |
a3e6c800 GKH |
81 | setenv("DEVNAME", env_devname, 1); |
82 | dbg("DEVNAME='%s'", env_devname); | |
83 | ||
84 | devname = strdup(dev->name); | |
85 | if (!devname) { | |
86 | dbg("out of memory"); | |
87 | return; | |
88 | } | |
89 | ||
90 | /* Chop the device name up into pieces based on '/' */ | |
91 | temp = strchr(devname, '/'); | |
92 | while (temp != NULL) { | |
93 | *temp = 0x00; | |
94 | strcpy(dirname, DEVD_DIR); | |
95 | strfieldcat(dirname, devname); | |
96 | call_foreach_file(run_program, dirname, DEVD_SUFFIX); | |
97 | ||
98 | *temp = '/'; | |
99 | ++temp; | |
100 | temp = strchr(temp, '/'); | |
101 | } | |
dd64e26b | 102 | |
4a539daf KS |
103 | strcpy(dirname, DEVD_DIR); |
104 | strfieldcat(dirname, dev->name); | |
105 | call_foreach_file(run_program, dirname, DEVD_SUFFIX); | |
dd64e26b | 106 | |
4a539daf KS |
107 | strcpy(dirname, DEVD_DIR); |
108 | strfieldcat(dirname, subsystem); | |
109 | call_foreach_file(run_program, dirname, DEVD_SUFFIX); | |
dd64e26b | 110 | |
4a539daf KS |
111 | strcpy(dirname, DEVD_DIR "default"); |
112 | call_foreach_file(run_program, dirname, DEVD_SUFFIX); | |
dd64e26b | 113 | } |