summaryrefslogtreecommitdiff
path: root/extras
diff options
context:
space:
mode:
authorGreg KH <greg@press.(none)>2005-06-21 16:36:29 -0700
committerGreg Kroah-Hartman <gregkh@suse.de>2005-06-21 16:36:29 -0700
commit972d318a3123b00d0ed6b78bbcf70a0965841a8e (patch)
tree8322245ad8e488ad3da9575e2d90b219a99880ea /extras
parentae8d5e161fe916e39f226ce53f2c5f8b31f582a0 (diff)
parentd27d3bb05288fb5e70bc3f3fc7da1dc8ee5413a8 (diff)
Merge gregkh@ehlo.org:/home/kay/public_html/pub/scm/linux/hotplug/udev-kay
Diffstat (limited to 'extras')
-rw-r--r--extras/run_directory/Makefile55
-rw-r--r--extras/run_directory/run_directory.c79
-rw-r--r--extras/run_directory/udev_run_devd.c78
-rw-r--r--extras/run_directory/udev_run_hotplugd.c76
-rw-r--r--extras/volume_id/Makefile2
-rw-r--r--extras/volume_id/udev_volume_id.c18
6 files changed, 305 insertions, 3 deletions
diff --git a/extras/run_directory/Makefile b/extras/run_directory/Makefile
new file mode 100644
index 0000000000..12dccf0749
--- /dev/null
+++ b/extras/run_directory/Makefile
@@ -0,0 +1,55 @@
+# Makefile for udev_volume_id
+#
+# Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+
+DEVD = udev_run_devd
+HOTPLUGD = udev_run_hotplugd
+
+all: $(DEVD) $(HOTPLUGD)
+
+prefix =
+exec_prefix = ${prefix}
+etcdir = ${prefix}/etc
+sbindir = ${exec_prefix}/sbin
+usrbindir = ${exec_prefix}/usr/bin
+usrsbindir = ${exec_prefix}/usr/sbin
+mandir = ${prefix}/usr/share/man
+devddir = ${etcdir}/dev.d/default
+configdir = ${etcdir}/udev/
+initdir = ${etcdir}/init.d/
+srcdir = .
+
+INSTALL = /usr/bin/install -c
+INSTALL_PROGRAM = ${INSTALL}
+INSTALL_DATA = ${INSTALL} -m 644
+INSTALL_SCRIPT = ${INSTALL_PROGRAM}
+
+override CFLAGS+=-D_FILE_OFFSET_BITS=64
+
+OBJS = ../../udev.a ../../libsysfs/sysfs.a
+
+.c.o:
+ $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
+
+$(DEVD): $(HEADERS) $(DEVD).o run_directory.o
+ $(QUIET) $(LD) $(LDFLAGS) -o $(DEVD) $(DEVD).o run_directory.o $(OBJS)
+
+$(HOTPLUGD): $(HEADERS) $(HOTPLUGD).o run_directory.o
+ $(QUIET) $(LD) $(LDFLAGS) -o $(HOTPLUGD) $(HOTPLUGD).o run_directory.o $(OBJS)
+
+clean:
+ rm -f $(DEVD) $(HOTPLUGD) run_directory.o
+
+spotless: clean
+
+install: all
+ $(INSTALL_PROGRAM) $(DEVD) $(DESTDIR)$(sbindir)/$(DEVD)
+ $(INSTALL_PROGRAM) $(HOTPLUGD) $(DESTDIR)$(sbindir)/$(HOTPLUGD)
+
+uninstall:
+ - rm $(DESTDIR)$(sbindir)/$(DEVD)
diff --git a/extras/run_directory/run_directory.c b/extras/run_directory/run_directory.c
new file mode 100644
index 0000000000..e6c6173eca
--- /dev/null
+++ b/extras/run_directory/run_directory.c
@@ -0,0 +1,79 @@
+/*
+ * udev_run_directory.c - directory multiplexer
+ *
+ * Copyright (C) 2005 Kay Sievers <kay@vrfy.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+
+#include "../../udev_utils.h"
+#include "../../list.h"
+#include "../../logging.h"
+
+int run_directory(const char *dir, const char *suffix, const char *subsystem);
+
+static int run_program(const char *filename, const char *subsystem)
+{
+ pid_t pid;
+
+ dbg("running %s", filename);
+ pid = fork();
+ switch (pid) {
+ case 0:
+ /* child */
+ execl(filename, filename, subsystem, NULL);
+ dbg("exec of child failed");
+ _exit(1);
+ case -1:
+ dbg("fork of child failed");
+ break;
+ return -1;
+ default:
+ waitpid(pid, NULL, 0);
+ }
+
+ return 0;
+}
+
+int run_directory(const char *dir, const char *suffix, const char *subsystem)
+{
+ char dirname[NAME_SIZE];
+ struct name_entry *name_loop, *name_tmp;
+ LIST_HEAD(name_list);
+
+ if (subsystem) {
+ snprintf(dirname, sizeof(dirname), "%s/%s", dir, subsystem);
+ dirname[sizeof(dirname)-1] = '\0';
+ dbg("looking at '%s'", dirname);
+ add_matching_files(&name_list, dirname, suffix);
+ }
+
+ snprintf(dirname, sizeof(dirname), "%s/default", dir);
+ dirname[sizeof(dirname)-1] = '\0';
+ dbg("looking at '%s'", dirname);
+ add_matching_files(&name_list, dirname, suffix);
+
+ list_for_each_entry_safe(name_loop, name_tmp, &name_list, node) {
+ run_program(name_loop->name, subsystem);
+ list_del(&name_loop->node);
+ }
+
+ logging_close();
+ return 0;
+}
diff --git a/extras/run_directory/udev_run_devd.c b/extras/run_directory/udev_run_devd.c
new file mode 100644
index 0000000000..02bbc8c353
--- /dev/null
+++ b/extras/run_directory/udev_run_devd.c
@@ -0,0 +1,78 @@
+/*
+ * udev_run_devd.c - directory multiplexer
+ *
+ * Copyright (C) 2005 Kay Sievers <kay@vrfy.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+
+#include "../../udev_utils.h"
+#include "../../list.h"
+#include "../../logging.h"
+
+extern int run_directory(const char *dir, const char *suffix, const char *subsystem);
+
+#ifdef USE_LOG
+void log_message (int priority, const char *format, ...)
+{
+ va_list args;
+ static int udev_log = -1;
+
+ if (udev_log == -1) {
+ const char *value;
+
+ value = getenv("UDEV_LOG");
+ if (value)
+ udev_log = log_priority(value);
+ else
+ udev_log = LOG_ERR;
+ }
+
+ if (priority > udev_log)
+ return;
+
+ va_start(args, format);
+ vsyslog(priority, format, args);
+ va_end(args);
+}
+#endif
+
+int main(int argc, char *argv[], char *envp[])
+{
+ const char *subsystem;
+ int fd;
+
+ if (getenv("DEVNAME") == NULL)
+ exit(0);
+
+ subsystem = argv[1];
+ logging_init("udev_run_devd");
+
+ fd = open("/dev/null", O_RDWR);
+ if (fd >= 0) {
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDERR_FILENO);
+ close(fd);
+ }
+ dbg("running dev.d directory");
+
+ run_directory("/etc/dev.d", ".dev", subsystem);
+ exit(0);
+}
diff --git a/extras/run_directory/udev_run_hotplugd.c b/extras/run_directory/udev_run_hotplugd.c
new file mode 100644
index 0000000000..54b6bf44e3
--- /dev/null
+++ b/extras/run_directory/udev_run_hotplugd.c
@@ -0,0 +1,76 @@
+/*
+ * udev_run_hotplugd.c - directory multiplexer
+ *
+ * Copyright (C) 2005 Kay Sievers <kay@vrfy.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+
+#include "../../udev_utils.h"
+#include "../../list.h"
+#include "../../logging.h"
+
+extern int run_directory(const char *dir, const char *suffix, const char *subsystem);
+
+#ifdef USE_LOG
+void log_message (int priority, const char *format, ...)
+{
+ va_list args;
+ static int udev_log = -1;
+
+ if (udev_log == -1) {
+ const char *value;
+
+ value = getenv("UDEV_LOG");
+ if (value)
+ udev_log = log_priority(value);
+ else
+ udev_log = LOG_ERR;
+ }
+
+ if (priority > udev_log)
+ return;
+
+ va_start(args, format);
+ vsyslog(priority, format, args);
+ va_end(args);
+}
+#endif
+
+int main(int argc, char *argv[], char *envp[])
+{
+ const char *subsystem;
+ int fd;
+
+ subsystem = argv[1];
+ logging_init("udev_run_hotplugd");
+
+ fd = open("/dev/null", O_RDWR);
+ if (fd >= 0) {
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDERR_FILENO);
+ close(fd);
+ }
+
+ dbg("running dev.d directory");
+
+ run_directory("/etc/hotplug.d", ".hotplug", subsystem);
+ exit(0);
+}
diff --git a/extras/volume_id/Makefile b/extras/volume_id/Makefile
index 91527cc9f5..56fdf278b9 100644
--- a/extras/volume_id/Makefile
+++ b/extras/volume_id/Makefile
@@ -33,7 +33,7 @@ override CFLAGS+=-D_FILE_OFFSET_BITS=64
VOLUME_ID_BASE=volume_id
include $(VOLUME_ID_BASE)/Makefile.inc
-OBJS = udev_volume_id.o $(VOLUME_ID_OBJS) $(SYSFS)
+OBJS = udev_volume_id.o $(VOLUME_ID_OBJS) ../../udev.a
HEADERS = $(VOLUME_ID_HEADERS)
$(OBJS): $(HEADERS)
diff --git a/extras/volume_id/udev_volume_id.c b/extras/volume_id/udev_volume_id.c
index a00b01a27d..7c6fc4050d 100644
--- a/extras/volume_id/udev_volume_id.c
+++ b/extras/volume_id/udev_volume_id.c
@@ -40,12 +40,26 @@
#define BLKGETSIZE64 _IOR(0x12,114,size_t)
#ifdef USE_LOG
-void log_message(int level, const char *format, ...)
+void log_message(int priority, const char *format, ...)
{
va_list args;
+ static int udev_log = -1;
+
+ if (udev_log == -1) {
+ const char *value;
+
+ value = getenv("UDEV_LOG");
+ if (value)
+ udev_log = log_priority(value);
+ else
+ udev_log = LOG_ERR;
+ }
+
+ if (priority > udev_log)
+ return;
va_start(args, format);
- vsyslog(level, format, args);
+ vsyslog(priority, format, args);
va_end(args);
}
#endif