CFLAGS += -I$(PWD)/libsysfs
-all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(STARTER)
+all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER)
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
$(MAKE) prefix=$(prefix) \
$(SENDER).o: $(GEN_HEADERS)
$(STARTER).o: $(GEN_HEADERS)
-$(ROOT): $(ROOT).o $(OBJS) $(HEADERS) $(LIBC) $(GEN_MANPAGES)
- $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
+$(ROOT): $(ROOT).o $(STARTER).o $(OBJS) $(HEADERS) $(LIBC) $(GEN_MANPAGES)
+ $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o udevstart.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $@
$(TESTER): $(TESTER).o $(OBJS) $(HEADERS) $(LIBC)
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o udev_lib.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $@
-$(STARTER): $(STARTER).o $(HEADERS) $(LIBC)
- $(LD) $(LDFLAGS) -o $@ $(CRT0) udevstart.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
- $(STRIPCMD) $@
-
$(RULER): $(RULER).o $(OBJS) $(HEADERS) $(LIBC)
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevruler.o udev_lib.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS) -lnewt
$(STRIPCMD) $@
clean:
-find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
| xargs rm -f
- -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) $(SENDER) $(TESTER) $(STARTER) $(RULER)
+ -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) $(SENDER) $(TESTER) $(RULER)
$(MAKE) -C klibc clean
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
$(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
$(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
$(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
- $(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
+ ln -sf $(sbindir)/udev $(DESTDIR)$(sbindir)/$(STARTER)
- ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/$(ROOT).hotplug
ifndef DESTDIR
- killall udevd
* subsystem/
* default/
*/
-void dev_d_send(struct udevice *dev, char *subsystem, char *devpath)
+void dev_d_send(struct udevice *dev, const char *subsystem, const char *devpath)
{
char dirname[256];
char env_devname[NAME_SIZE];
return -1;
}
-static struct sysfs_class_device *get_class_dev(char *device_name)
+static struct sysfs_class_device *get_class_dev(const char *device_name)
{
char dev_path[SYSFS_PATH_MAX];
struct sysfs_class_device *class_dev = NULL;
* If it doesn't happen in about 10 seconds, give up.
*/
#define SECONDS_TO_WAIT_FOR_FILE 10
-static int sleep_for_file(char *path, char* file)
+static int sleep_for_file(const char *path, char* file)
{
char filename[SYSFS_PATH_MAX + 6];
int loop = SECONDS_TO_WAIT_FOR_FILE;
return retval;
}
-int udev_add_device(char *path, char *subsystem, int fake)
+int udev_add_device(const char *path, const char *subsystem, int fake)
{
struct sysfs_class_device *class_dev;
struct udevice dev;
* something different from the kernel name. If we have, us it. If not, use
* the default kernel name for lack of anything else to know to do.
*/
-int udev_remove_device(char *path, char *subsystem)
+int udev_remove_device(const char *path, const char *subsystem)
{
struct udevice dev;
char *temp;
char **main_argv;
char **main_envp;
+/* local variables */
+static int is_udevstart;
+
#ifdef LOG
unsigned char logname[LOGNAME_SIZE];
void log_message(int level, const char *format, ...)
""
};
-static int udev_hotplug(void)
+int __udev_hotplug(char *action, const char *devpath, const char *subsystem)
{
- char *action;
- char *devpath;
- char *subsystem;
int retval = -EINVAL;
int i;
struct sigaction act;
const int nofake = 0;
- action = get_action();
- if (!action) {
- dbg("no action?");
- goto exit;
- }
-
- devpath = get_devpath();
- if (!devpath) {
- dbg("no devpath?");
- goto exit;
- }
dbg("looking at '%s'", devpath);
/* we only care about class devices and block stuff */
goto exit;
}
- /* skip blacklisted subsystems */
- subsystem = get_subsystem(main_argv[1]);
- if (!subsystem) {
- dbg("no subsystem?");
- goto exit;
- }
i = 0;
while (subsystem_blacklist[i][0] != '\0') {
if (strcmp(subsystem, subsystem_blacklist[i]) == 0) {
sigaction(SIGTERM, &act, NULL);
if (strcmp(action, "add") == 0) {
- namedev_init();
+ /* Already done. */
+ if (!is_udevstart)
+ namedev_init();
retval = udev_add_device(devpath, subsystem, nofake);
goto action_done;
}
return retval;
}
+static int udev_hotplug(void)
+{
+ char *action;
+ char *devpath;
+ char *subsystem;
+
+ action = get_action();
+ if (!action) {
+ dbg("no action?");
+ return -EINVAL;
+ }
+
+ devpath = get_devpath();
+ if (!devpath) {
+ dbg("no devpath?");
+ return -EINVAL;
+ }
+
+ /* skip blacklisted subsystems */
+ subsystem = get_subsystem(main_argv[1]);
+ if (!subsystem) {
+ dbg("no subsystem?");
+ return -EINVAL;
+ }
+
+ return __udev_hotplug(action, devpath, subsystem);
+}
+
int main(int argc, char *argv[], char *envp[])
{
main_argv = argv;
main_envp = envp;
- init_logging("udev");
+ if (strstr(argv[0], "udevstart"))
+ is_udevstart = 1;
/* initialize our configuration */
udev_init_config();
dbg("version %s", UDEV_VERSION);
- return udev_hotplug();
+ if (is_udevstart) {
+ namedev_init();
+ return udev_start();
+ } else
+ return udev_hotplug();
}
char kernel_name[NAME_SIZE];
};
-extern int udev_add_device(char *path, char *subsystem, int fake);
-extern int udev_remove_device(char *path, char *subsystem);
+extern int udev_add_device(const char *path, const char *subsystem, int fake);
+extern int udev_remove_device(const char *path, const char *subsystem);
extern void udev_init_config(void);
+extern int udev_start(void);
+extern int __udev_hotplug(char *action, const char *devpath,
+ const char *subsystem);
extern int parse_get_pair(char **orig_string, char **left, char **right);
-extern void dev_d_send(struct udevice *dev, char *subsystem, char *devpath);
+extern void dev_d_send(struct udevice *dev, const char *subsystem,
+ const char *devpath);
extern char **main_argv;
extern char **main_envp;
#include "logging.h"
#include "udev_lib.h"
#include "list.h"
-
-
-#ifdef LOG
-unsigned char logname[LOGNAME_SIZE];
-void log_message(int level, const char *format, ...)
-{
- va_list args;
-
- va_start(args, format);
- vsyslog(level, format, args);
- va_end(args);
-}
-#endif
+#include "udev.h"
#define MAX_PATHLEN 1024
#define SYSBLOCK "/sys/block"
#define SYSCLASS "/sys/class"
-#define UDEV_BIN "/sbin/udev"
struct device {
struct list_head list;
static void udev_exec(const char *path, const char* subsystem)
{
- pid_t pid;
- char action[] = "ACTION=add";
- char devpath[MAX_PATHLEN];
- char nosleep[] = "UDEV_NO_SLEEP=1";
- char *env[] = { action, devpath, nosleep, NULL };
-
- strcpy(devpath, "DEVPATH=");
- strfieldcat(devpath, path);
-
- pid = fork();
- switch (pid) {
- case 0:
- /* child */
- execle(UDEV_BIN, "udev", subsystem, NULL, env);
- dbg("exec of child failed");
+ /* Setup env variables. */
+ setenv("UDEV_NO_SLEEP", "1", 1);
+
+ /* Now call __udev_hotplug(). */
+ if (__udev_hotplug("add", path, subsystem)) {
+ dbg("Calling of udev_hotplug failed");
exit(1);
- break;
- case -1:
- dbg("fork of child failed");
- break;
- default:
- wait(NULL);
}
}
exec_list(&device_list);
}
-int main(int argc, char *argv[], char *envp[])
+int udev_start(void)
{
- init_logging("udevstart");
-
udev_scan_class();
udev_scan_block();
-
return 0;
}