rpms/udev/devel udev-075-daemon.patch, NONE, 1.1 start_udev, 1.45, 1.46 udev.spec, 1.129, 1.130 udevstart2.patch, 1.2, NONE

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Tue Dec 13 15:36:49 UTC 2005


Author: harald

Update of /cvs/dist/rpms/udev/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv9983

Modified Files:
	start_udev udev.spec 
Added Files:
	udev-075-daemon.patch 
Removed Files:
	udevstart2.patch 
Log Message:
- version 077
- patch to include udevstart2 in udevd and delay daemonize until queue is empty


udev-075-daemon.patch:
 udevd.c |  362 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 340 insertions(+), 22 deletions(-)

--- NEW FILE udev-075-daemon.patch ---
--- udev-077/udevd.c.udevstart2	2005-12-04 03:01:48.000000000 +0100
+++ udev-077/udevd.c	2005-12-13 15:08:46.000000000 +0100
@@ -42,14 +42,15 @@
 #include <linux/types.h>
 #include <linux/netlink.h>
 
-#include "list.h"
+#include "libsysfs/sysfs/libsysfs.h"
 #include "udev_libc_wrapper.h"
 #include "udev.h"
 #include "udev_version.h"
-#include "udev_rules.h"
+#include "logging.h"
 #include "udev_utils.h"
+#include "udev_rules.h"
+#include "list.h"
 #include "udevd.h"
-#include "logging.h"
 
 struct udev_rules rules;
 static int udevd_sock;
@@ -71,6 +72,277 @@
 static LIST_HEAD(running_list);
 
 
+struct device {
+	struct list_head node;
+	char path[PATH_SIZE];
+	char subsys[NAME_SIZE];
+};
+
+/* sort files in lexical order */
+static int device_list_insert(const char *path, char *subsystem, struct list_head *device_list)
+{
+	struct device *loop_device;
+	struct device *new_device;
+	const char *devpath = &path[strlen(sysfs_path)];
+
+	dbg("insert: '%s'\n", devpath);
+
+	list_for_each_entry(loop_device, device_list, node) {
+		if (strcmp(loop_device->path, devpath) > 0) {
+			break;
+		}
+	}
+
+	new_device = malloc(sizeof(struct device));
+	if (new_device == NULL) {
+		dbg("error malloc");
+		return -ENOMEM;
+	}
+
+	strlcpy(new_device->path, devpath, sizeof(new_device->path));
+	strlcpy(new_device->subsys, subsystem, sizeof(new_device->subsys));
+	list_add_tail(&new_device->node, &loop_device->node);
+	dbg("add '%s' from subsys '%s'", new_device->path, new_device->subsys);
+	return 0;
+}
+
+/* list of devices that we should run last due to any one of a number of reasons */
+static char *last_list[] = {
+	"/block/dm",	/* on here because dm wants to have the block devices around before it */
+	NULL,
+};
+
+/* list of devices that we should run first due to any one of a number of reasons */
+static char *first_list[] = {
+	"/class/mem",
+	"/class/tty",
+	"/bus",
+	NULL,
+};
+
+static int add_device(const char *devpath, const char *subsystem)
+{
+  char filename[PATH_SIZE];
+  int fd;
+
+  snprintf(filename, sizeof(filename), "%s/%s/uevent", sysfs_path, devpath);
+  filename[sizeof(filename)-1] = '\0';
+
+  dbg("Trigger %s", filename);
+  fd = open(filename, O_WRONLY);
+  if (fd > 0) {
+    write(fd, "add\n", 4);
+    close(fd);
+  }
+  else return 1;
+  
+  return 0;
+}
+
+static void do_exec_list(struct list_head *device_list)
+{
+	struct device *loop_device;
+	struct device *tmp_device;
+	int i;
+
+	/* handle the "first" type devices first */
+	list_for_each_entry_safe(loop_device, tmp_device, device_list, node) {
+		for (i = 0; first_list[i] != NULL; i++) {
+			if (strncmp(loop_device->path, first_list[i], strlen(first_list[i])) == 0) {
+				add_device(loop_device->path, loop_device->subsys);
+				list_del(&loop_device->node);
+				free(loop_device);
+				break;
+			}
+		}
+	}
+
+	/* handle the devices we are allowed to, excluding the "last" type devices */
+	list_for_each_entry_safe(loop_device, tmp_device, device_list, node) {
+		int found = 0;
+		for (i = 0; last_list[i] != NULL; i++) {
+			if (strncmp(loop_device->path, last_list[i], strlen(last_list[i])) == 0) {
+				found = 1;
+				break;
+			}
+		}
+		if (found)
+			continue;
+
+		add_device(loop_device->path, loop_device->subsys);
+		list_del(&loop_device->node);
+		free(loop_device);
+	}
+
+	/* handle the rest of the devices left over, if any */
+	list_for_each_entry_safe(loop_device, tmp_device, device_list, node) {
+		add_device(loop_device->path, loop_device->subsys);
+		list_del(&loop_device->node);
+		free(loop_device);
+	}
+}
+
+static int has_devt(const char *path)
+{
+	char filename[PATH_SIZE];
+	struct stat statbuf;
+
+	snprintf(filename, sizeof(filename), "%s/uevent", path);
+	filename[sizeof(filename)-1] = '\0';
+
+	if (stat(filename, &statbuf) == 0)
+		return 1;
+
+	return 0;
+}
+
+static void udev_scan_block(struct list_head *device_list)
+{
+	char base[PATH_SIZE];
+	DIR *dir;
+	struct dirent *dent;
+
+	snprintf(base, sizeof(base), "%s/block", sysfs_path);
+	base[sizeof(base)-1] = '\0';
+
+	dir = opendir(base);
+	if (dir != NULL) {
+		for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+			char dirname[PATH_SIZE];
+			DIR *dir2;
+			struct dirent *dent2;
+
+			if (dent->d_name[0] == '.')
+				continue;
+
+			snprintf(dirname, sizeof(dirname), "%s/%s", base, dent->d_name);
+			dirname[sizeof(dirname)-1] = '\0';
+			if (has_devt(dirname))
+				device_list_insert(dirname, "block", device_list);
+			else
+				continue;
+
+			/* look for partitions */
+			dir2 = opendir(dirname);
+			if (dir2 != NULL) {
+				for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
+					char dirname2[PATH_SIZE];
+
+					if (dent2->d_name[0] == '.')
+						continue;
+
+					snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
+					dirname2[sizeof(dirname2)-1] = '\0';
+
+					if (has_devt(dirname2))
+						device_list_insert(dirname2, "block", device_list);
+				}
+				closedir(dir2);
+			}
+		}
+		closedir(dir);
+	}
+}
+
+static void udev_scan_bus(struct list_head *device_list)
+{
+	char base[PATH_SIZE];
+	DIR *dir;
+	struct dirent *dent;
+
+	snprintf(base, sizeof(base), "%s/bus", sysfs_path);
+	base[sizeof(base)-1] = '\0';
+
+	dir = opendir(base);
+	if (dir != NULL) {
+		for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+			char dirname[PATH_SIZE];
+			DIR *dir2;
+			struct dirent *dent2;
+
+			if (dent->d_name[0] == '.')
+				continue;
+
+			snprintf(dirname, sizeof(dirname), "%s/%s/devices", base, dent->d_name);
+			dirname[sizeof(dirname)-1] = '\0';
+
+			dir2 = opendir(dirname);
+			if (dir2 != NULL) {
+				for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
+					char dirname2[PATH_SIZE];
+
+					if (dent2->d_name[0] == '.')
+						continue;
+
+					snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
+					dirname2[sizeof(dirname2)-1] = '\0';
+
+					if (has_devt(dirname2))
+						device_list_insert(dirname2, dent->d_name, device_list);
+				}
+				closedir(dir2);
+			}
+		}
+		closedir(dir);
+	}
+}
+
+
+static void udev_scan_class(struct list_head *device_list)
+{
+	char base[PATH_SIZE];
+	DIR *dir;
+	struct dirent *dent;
+
+	snprintf(base, sizeof(base), "%s/class", sysfs_path);
+	base[sizeof(base)-1] = '\0';
+
+	dir = opendir(base);
+	if (dir != NULL) {
+		for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+			char dirname[PATH_SIZE];
+			DIR *dir2;
+			struct dirent *dent2;
+
+			if (dent->d_name[0] == '.')
+				continue;
+
+			snprintf(dirname, sizeof(dirname), "%s/%s", base, dent->d_name);
+			dirname[sizeof(dirname)-1] = '\0';
+
+			dir2 = opendir(dirname);
+			if (dir2 != NULL) {
+				for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
+					char dirname2[PATH_SIZE];
+
+					if (dent2->d_name[0] == '.')
+						continue;
+
+					snprintf(dirname2, sizeof(dirname2), "%s/%s", dirname, dent2->d_name);
+					dirname2[sizeof(dirname2)-1] = '\0';
+
+					if (has_devt(dirname2))
+						device_list_insert(dirname2, dent->d_name, device_list);
+				}
+				closedir(dir2);
+			}
+		}
+		closedir(dir);
+	}
+}
+
+static int udevstart(void)
+{
+	LIST_HEAD(device_list);
+	udev_scan_bus(&device_list);
+	udev_scan_class(&device_list);
+	udev_scan_block(&device_list);
+	do_exec_list(&device_list);
+	return 0;
+}
+
+
+
 #ifdef USE_LOG
 void log_message(int priority, const char *format, ...)
 {
@@ -790,6 +1062,41 @@
 	return 0;
 }
 
+
+static int do_daemonize(void)
+{
+  pid_t pid;
+  int rc = 0;
+
+  pid = fork();
+  switch (pid) {
+  case 0:
+    dbg("daemonized fork running");
+    break;
+  case -1:
+    err("fork of daemon failed: %s", strerror(errno));
+    rc = 4;
+    goto exit;
+  default:
+    dbg("child [%u] running, parent exits", pid);
+    exit(0);
+  }
+
+	/* set scheduling priority for the daemon */
+	setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY);
+
+	chdir("/");
+	umask(022);
+
+	/* become session leader */
+	sid = setsid();
+	dbg("our session is %d", sid);
+
+ exit:
+       return rc;
+
+}
+
 int main(int argc, char *argv[], char *envp[])
 {
 	int retval;
@@ -798,9 +1105,14 @@
 	fd_set readfds;
 	const char *value;
 	int daemonize = 0;
+	int wait_daemonize = 0;
 	int i;
 	int rc = 0;
 	int maxfd;
+	int daemonized = 0;
+
+	struct timeval timeout = { 0, 100000 };
+	struct timeval *ptimeout = &timeout;
 
 	/* redirect std fd's, if the kernel forks us, we don't have them at all */
 	fd = open("/dev/null", O_RDWR);
@@ -838,6 +1150,11 @@
 			info("will not execute events until START_EXEC_QUEUE is received");
 			stop_exec_q = 1;
 		}
+		if (strcmp(arg, "--wait") == 0 || strcmp(arg, "-w") == 0) {
+                        info("will wait with fork until queue is empty");
+                        wait_daemonize = 1;
+                        daemonize = 1;
+                }
 	}
 
 	/* init sockets to receive events */
@@ -861,24 +1178,6 @@
 	/* parse the rules and keep it in memory */
 	udev_rules_init(&rules, 1);
 
-	if (daemonize) {
-		pid_t pid;
-
-		pid = fork();
-		switch (pid) {
-		case 0:
-			dbg("daemonized fork running");
-			break;
-		case -1:
-			err("fork of daemon failed: %s", strerror(errno));
-			rc = 4;
-			goto exit;
-		default:
-			dbg("child [%u] running, parent exits", pid);
-			goto exit;
-		}
-	}
-
 	/* set scheduling priority for the daemon */
 	setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY);
 
@@ -958,6 +1257,8 @@
 	maxfd = UDEV_MAX(maxfd, signal_pipe[READ_END]);
 	maxfd = UDEV_MAX(maxfd, inotify_fd);
 
+	udevstart();
+
 	while (!udev_exit) {
 		struct uevent_msg *msg;
 		int fdcount;
@@ -969,13 +1270,30 @@
 		if (inotify_fd > 0)
 			FD_SET(inotify_fd, &readfds);
 
-		fdcount = select(maxfd+1, &readfds, NULL, NULL, NULL);
+		fdcount = select(maxfd+1, &readfds, NULL, NULL, ptimeout);
+
 		if (fdcount < 0) {
 			if (errno != EINTR)
 				err("error in select: %s", strerror(errno));
 			continue;
 		}
 
+		if (ptimeout) {
+		  ptimeout->tv_sec = 0;
+		  ptimeout->tv_usec = 200000;
+		}
+
+		if ((fdcount == 0) || (wait_daemonize == 0)) {
+		  if (list_empty(&running_list) || (wait_daemonize == 0)) {
+		    if ((daemonized == 0) && daemonize) {
+		      do_daemonize();
+		      daemonized++;
+		    }
+		    ptimeout = NULL;
+		  }
+		  continue;
+		}
+
 		/* get user socket message */
 		if (FD_ISSET(udevd_sock, &readfds)) {
 			msg = get_udevd_msg();


Index: start_udev
===================================================================
RCS file: /cvs/dist/rpms/udev/devel/start_udev,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- start_udev	29 Nov 2005 13:25:51 -0000	1.45
+++ start_udev	13 Dec 2005 15:36:46 -0000	1.46
@@ -193,12 +193,13 @@
 	if [ -f "/sys/class/tty/console/uevent" ]; then
 		# trigger the sorted events
 		echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
-		/sbin/udevstart2
+		/sbin/udevd -w -d
 		return $?
 	else
 	        sysctl -w kernel.hotplug="/sbin/udevsend" >/dev/null 2>&1
 		scsi_replay > "$udev_root/null" 2>&1
 		ide_scan > "$udev_root/null" 2>&1
+		udevd -d
 		/sbin/udevstart 
 		return $?
 	fi
@@ -238,7 +239,6 @@
 }
 make_extra_nodes
 kill_udevd > "$udev_root/null" 2>&1
-udevd -d
 event_replay
 ret=$[$ret + $?]
 [ $ret -eq 0 ] && success $"$STRING" || failure $"$STRING"


Index: udev.spec
===================================================================
RCS file: /cvs/dist/rpms/udev/devel/udev.spec,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -r1.129 -r1.130
--- udev.spec	9 Dec 2005 22:43:40 -0000	1.129
+++ udev.spec	13 Dec 2005 15:36:46 -0000	1.130
@@ -4,8 +4,8 @@
 
 Summary: A userspace implementation of devfs
 Name: udev
-Version: 076
-Release: 1.1
+Version: 077
+Release: 1
 License: GPL
 Group: System Environment/Base
 Provides: udev-persistent = 0:%{version}-%{release}
@@ -32,7 +32,8 @@
 
 Source30: firmware_helper.c
 
-Patch2: udevstart2.patch
+Patch2: udev-075-daemon.patch
+
 Patch3: udev-075-selinux.patch
 
 ExclusiveOS: Linux
@@ -59,7 +60,7 @@
 
 %prep
 %setup -q  
-%patch2 -p1 -b .udevstart2
+%patch2 -p1 -b .waitdaemon
 %patch3 -p1 -b .selinux
 
 cp %{SOURCE21} .
@@ -240,7 +241,6 @@
 %attr(0755,root,root) /sbin/udevsend
 %attr(0755,root,root) /sbin/udevd
 %attr(0755,root,root) /sbin/udevstart
-%attr(0755,root,root) /sbin/udevstart2
 %attr(0755,root,root) /sbin/start_udev
 #%attr(755,root,root) /sbin/udev_volume_id
 %attr(0755,root,root) %{udev_scriptdir}/udev_run_devd
@@ -303,6 +303,10 @@
 %attr(0644,root,root) %{_mandir}/man8/vol_id*.8*
 
 %changelog
+* Mon Dec 13 2005 Harald Hoyer <harald at redhat.com> - 077-1
+- version 077
+- patch to include udevstart2 in udevd and delay daemonize until queue is empty
+
 * Fri Dec 09 2005 Jesse Keating <jkeating at redhat.com>
 - rebuilt
 


--- udevstart2.patch DELETED ---




More information about the fedora-cvs-commits mailing list