]>
git.ipfire.org Git - thirdparty/systemd.git/blob - udevstart.c
4 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
6 * Quick and dirty way to populate a /dev with udev if your system
7 * does not have access to a shell. Based originally on a patch to udev
8 * from Harald Hoyer <harald@redhat.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation version 2 of the License.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
37 unsigned char logname
[LOGNAME_SIZE
];
38 void log_message(int level
, const char *format
, ...)
42 va_start(args
, format
);
43 vsyslog(level
, format
, args
);
49 #define MAX_PATHLEN 1024
50 #define SYSBLOCK "/sys/block"
51 #define SYSCLASS "/sys/class"
52 #define UDEV_BIN "/sbin/udev"
54 static void udev_exec(const char *path
, const char* subsystem
)
57 char action
[] = "ACTION=add";
58 char devpath
[MAX_PATHLEN
];
59 char nosleep
[] = "UDEV_NO_SLEEP=1";
60 char *env
[] = { action
, devpath
, nosleep
, NULL
};
62 snprintf(devpath
, MAX_PATHLEN
, "DEVPATH=%s", path
);
63 devpath
[MAX_PATHLEN
-1] = '\0';
69 execle(UDEV_BIN
, "udev", subsystem
, NULL
, env
);
70 dbg("exec of child failed");
74 dbg("fork of child failed");
81 static int udev_scan(void)
89 dir
= opendir(SYSBLOCK
);
91 for (dent
= readdir(dir
); dent
!= NULL
; dent
= readdir(dir
)) {
92 char dirname
[MAX_PATHLEN
];
96 if ((strcmp(dent
->d_name
, ".") == 0) ||
97 (strcmp(dent
->d_name
, "..") == 0))
100 snprintf(dirname
, MAX_PATHLEN
, "/block/%s", dent
->d_name
);
101 dirname
[MAX_PATHLEN
-1] = '\0';
102 udev_exec(dirname
, "block");
104 snprintf(dirname
, MAX_PATHLEN
, "%s/%s", SYSBLOCK
, dent
->d_name
);
105 dir2
= opendir(dirname
);
107 for (dent2
= readdir(dir2
); dent2
!= NULL
; dent2
= readdir(dir2
)) {
108 char dirname2
[MAX_PATHLEN
];
110 struct dirent
*dent3
;
112 if ((strcmp(dent2
->d_name
, ".") == 0) ||
113 (strcmp(dent2
->d_name
, "..") == 0))
116 snprintf(dirname2
, MAX_PATHLEN
, "%s/%s", dirname
, dent2
->d_name
);
117 dirname2
[MAX_PATHLEN
-1] = '\0';
119 dir3
= opendir(dirname2
);
121 for (dent3
= readdir(dir3
); dent3
!= NULL
; dent3
= readdir(dir3
)) {
122 char filename
[MAX_PATHLEN
];
124 if (strcmp(dent3
->d_name
, "dev") == 0) {
125 snprintf(filename
, MAX_PATHLEN
, "/block/%s/%s",
126 dent
->d_name
, dent2
->d_name
);
127 filename
[MAX_PATHLEN
-1] = '\0';
128 udev_exec(filename
, "block");
138 dir
= opendir(SYSCLASS
);
140 for (dent
= readdir(dir
); dent
!= NULL
; dent
= readdir(dir
)) {
141 char dirname
[MAX_PATHLEN
];
143 struct dirent
*dent2
;
145 if ((strcmp(dent
->d_name
, ".") == 0) ||
146 (strcmp(dent
->d_name
, "..") == 0))
149 snprintf(dirname
, MAX_PATHLEN
, "%s/%s", SYSCLASS
, dent
->d_name
);
150 dirname
[MAX_PATHLEN
] = '\0';
151 dir2
= opendir(dirname
);
153 for (dent2
= readdir(dir2
); dent2
!= NULL
; dent2
= readdir(dir2
)) {
154 char dirname2
[MAX_PATHLEN
-1];
156 struct dirent
*dent3
;
158 if ((strcmp(dent2
->d_name
, ".") == 0) ||
159 (strcmp(dent2
->d_name
, "..") == 0))
162 snprintf(dirname2
, MAX_PATHLEN
, "%s/%s", dirname
, dent2
->d_name
);
163 dirname2
[MAX_PATHLEN
-1] = '\0';
165 dir3
= opendir(dirname2
);
167 for (dent3
= readdir(dir3
); dent3
!= NULL
; dent3
= readdir(dir3
)) {
168 char filename
[MAX_PATHLEN
];
170 if (strcmp(dent3
->d_name
, "dev") == 0) {
171 snprintf(filename
, MAX_PATHLEN
, "/class/%s/%s",
172 dent
->d_name
, dent2
->d_name
);
173 filename
[MAX_PATHLEN
-1] = '\0';
174 udev_exec(filename
, dent
->d_name
);
190 int main(int argc
, char *argv
[], char *envp
[])
192 init_logging("udevstart");