Skip to contentSkip to conversation

move udev-rules parsing into the daemon

PATCH Kay Sievers 2 participants 10 messages Jul 31, 2005 – Aug 18, 2005 Kbuild

lore
Share & tools
lore
#0 lore raw

Here we move the parsed rules into the udev daemon, which will no longer execute the udev binary. This saves us the rule parsing, cause the parsed rules will be inherited from the daemon process, which will fork() a child which imediately becomes the event process without doing an exec(). It's basically a retry of this old patch:
http://marc.theaimsgroup.com/?l=linux-hotplug-devel&m=109814301613236&w=2

Changes to /etc/udev/rules.d/* will automatically recognized and will cause a reload of the rules, also the usual -HUP should work.

Would be nice if someone brave enough can give it a try, we want to put that upstream if it works as expected. The patch applies on top of v064.

Thanks,
Kay

RELEASE-NOTES +18 -0
@@ -1,3 +1,21 @@
+udev 065
+========
+
+
+udev 064
+========
+Mostly bugfixes and see ChangeLog.
+
+The test for the existence of an environment value should be
+switched from:
+  ENV{KEY}=="*" to ENV{KEY}=="?*"
+cause "*" will not fail anymore, if the key does not exist or
+is empty.
+
+udev 063
+========
+Bugfixes and a few tweaks described in the ChangeLog.
+
 udev 062
 ========
 Mostly a Bugfix release.
udevcontrol.c +3 -1
@@ -97,7 +97,9 @@ int main(int argc, char *argv[], char *e
 		usend_msg.type = UDEVD_SET_MAX_CHILDS;
 		*intval = atoi(val);
 		info("send max_childs=%i", *intval);
-	} else {
+	} else if (!strcmp(argv[1], "reload_rules"))
+		usend_msg.type = UDEVD_RELOAD_RULES;
+	else {
 		err("error parsing command\n");
 		goto exit;
 	}
udevd.c +89 -7

166 lines not on this page · raw message

udevd.h +1 -0
@@ -54,6 +54,7 @@ enum udevd_msg_type {
 	UDEVD_START_EXEC_QUEUE,
 	UDEVD_SET_LOG_LEVEL,
 	UDEVD_SET_MAX_CHILDS,
+	UDEVD_RELOAD_RULES,
 };
 
 
#1 lore raw
Quoted 7 lines · Kay Sievers

Here we move the parsed rules into the udev daemon, which will no longer execute the udev binary. This saves us the rule parsing, cause the parsed rules will be inherited from the daemon process, which will fork() a child which imediately becomes the event process without doing an exec(). It's basically a retry of this old patch:
http://marc.theaimsgroup.com/?l=linux-hotplug-devel&m=109814301613236&w=2

Quoted 5 lines

Changes to /etc/udev/rules.d/* will automatically recognized and will cause a reload of the rules, also the usual -HUP should work.

Would be nice if someone brave enough can give it a try, we want to put that upstream if it works as expected. The patch applies on top of v064.

New patch with a few fixes on top of the current git tree.

Thanks,
Kay

udevcontrol.c +3 -1
@@ -97,7 +97,9 @@ int main(int argc, char *argv[], char *e
 		usend_msg.type = UDEVD_SET_MAX_CHILDS;
 		*intval = atoi(val);
 		info("send max_childs=%i", *intval);
-	} else {
+	} else if (!strcmp(argv[1], "reload_rules"))
+		usend_msg.type = UDEVD_RELOAD_RULES;
+	else {
 		err("error parsing command\n");
 		goto exit;
 	}
udevd.c +104 -15

218 lines not on this page · raw message

udevd.h +1 -0
@@ -54,6 +54,7 @@ enum udevd_msg_type {
 	UDEVD_START_EXEC_QUEUE,
 	UDEVD_SET_LOG_LEVEL,
 	UDEVD_SET_MAX_CHILDS,
+	UDEVD_RELOAD_RULES,
 };
 
 
#2 lore raw
In reply to Kay Sievers
Quoted 7 lines · Kay Sievers
udevd.c +7 -0
+static int watch_directory(const char *dir)
+{
+	int fd;
+
+	fd = open(dir, O_RDONLY);
+	if (fd < 0) {
+		err("could not open '%s' to watch it", dir);

udevd.c static int init_uevent_netlink_sock(void · line 859

Quoted 10 lines
udevd.c +10 -0
+		return -1;
+	}
+	if (fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_DELETE | DN_MULTISHOT) = -1) {
+		err("could not set dnotify on '%s'", dir);
+		return -1;
+		close(fd);
+	}
+
+	return 0;
+}

Why dnotify and not inotify?

thanks,

greg k-h

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Kay Sievers
Quoted 12 lines · Greg KH
Quoted 11 lines · Kay Sievers
udevd.c +11 -0
+static int watch_directory(const char *dir)
+{
+	int fd;
+
+	fd = open(dir, O_RDONLY);
+	if (fd < 0) {
+		err("could not open '%s' to watch it", dir);
+		return -1;
+	}
+	if (fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_DELETE | DN_MULTISHOT) = -1) {
+		err("could not set dnotify on '%s'", dir);
Quoted 8 lines

udevd.c static int init_uevent_netlink_sock(void · line 859

Quoted 6 lines
udevd.c +6 -0
+		return -1;
+		close(fd);
+	}
+
+	return 0;
+}

Why dnotify and not inotify?

The patch is just older than inotify is in mainline. :) If we can require the latest kernel, I will happily change it.

Thanks,
Kay

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#4 lore raw
In reply to Kay Sievers
Quoted 22 lines · Kay Sievers
Quoted 12 lines · Greg KH
Quoted 11 lines · Kay Sievers
(quoted diff) +11 -0
+static int watch_directory(const char *dir)
+{
+	int fd;
+
+	fd = open(dir, O_RDONLY);
+	if (fd < 0) {
+		err("could not open '%s' to watch it", dir);
+		return -1;
+	}
+	if (fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_DELETE | DN_MULTISHOT) == -1) {
+		err("could not set dnotify on '%s'", dir);
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+		return -1;
+		close(fd);
+	}
+
+	return 0;
+}

Why dnotify and not inotify?

Quoted 2 lines

The patch is just older than inotify is in mainline. :) If we can require the latest kernel, I will happily change it.

Here we go with the Inotify version on top of the current tree. I've added some stuff to our libc-wrapper file until the inotify headers have reached glibc and we can just add an #include to udevd.c for it.

Thanks,
Kay

Makefile +0 -0
klibc/klibc/SYSCALLS.def +3 -0
@@ -114,6 +114,9 @@ int lchown32,lchown::lchown(const char *
 int getcwd::__getcwd(char *, size_t)
 <?> int utime(const char *, const struct utimbuf *)
 <?> int utimes(const char *, const struct timeval *)
+<?> int inotify_init(void)
+<?> int inotify_add_watch(int, const char *, __u32)
+<?> int inotify_rm_watch(int, __u32)
 
 ;
 ; I/O operations
udev_libc_wrapper.h +49 -2

73 lines not on this page · raw message

udevcontrol.c +3 -1
@@ -97,7 +97,9 @@ int main(int argc, char *argv[], char *e
 		usend_msg.type = UDEVD_SET_MAX_CHILDS;
 		*intval = atoi(val);
 		info("send max_childs=%i", *intval);
-	} else {
+	} else if (!strcmp(argv[1], "reload_rules"))
+		usend_msg.type = UDEVD_RELOAD_RULES;
+	else {
 		err("error parsing command\n");
 		goto exit;
 	}
udevd.c +120 -17

268 lines not on this page · raw message

udevd.h +1 -0
@@ -54,6 +54,7 @@ enum udevd_msg_type {
 	UDEVD_START_EXEC_QUEUE,
 	UDEVD_SET_LOG_LEVEL,
 	UDEVD_SET_MAX_CHILDS,
+	UDEVD_RELOAD_RULES,
 };
 
 
#5 lore raw
In reply to Kay Sievers
Quoted 4 lines · Kay Sievers

Here we go with the Inotify version on top of the current tree. I've added some stuff to our libc-wrapper file until the inotify headers have reached glibc and we can just add an #include to udevd.c for it.

Looks good to me.

greg k-h

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw
In reply to Kay Sievers
Quoted 7 lines · Greg KH
Quoted 4 lines · Kay Sievers

Here we go with the Inotify version on top of the current tree. I've added some stuff to our libc-wrapper file until the inotify headers have reached glibc and we can just add an #include to udevd.c for it.

Looks good to me.

Here is a version on top of the new 066.

Thanks,
Kay

klibc/klibc/SYSCALLS.def +3 -0
@@ -114,6 +114,9 @@ int lchown32,lchown::lchown(const char *
 int getcwd::__getcwd(char *, size_t)
 <?> int utime(const char *, const struct utimbuf *)
 <?> int utimes(const char *, const struct timeval *)
+<?> int inotify_init(void)
+<?> int inotify_add_watch(int, const char *, __u32)
+<?> int inotify_rm_watch(int, __u32)
 
 ;
 ; I/O operations
udev_libc_wrapper.h +49 -2

73 lines not on this page · raw message

udevcontrol.c +3 -0
@@ -89,6 +89,8 @@ int main(int argc, char *argv[], char *e
 			usend_msg.type = UDEVD_STOP_EXEC_QUEUE;
 		else if (!strcmp(arg, "start_exec_queue"))
 			usend_msg.type = UDEVD_START_EXEC_QUEUE;
+		else if (!strcmp(arg, "reload_rules"))
+			usend_msg.type = UDEVD_RELOAD_RULES;
 		else if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
 			intval = (int *) usend_msg.envbuf;
 			val = &arg[strlen("log_priority=")];
@@ -106,6 +108,7 @@ int main(int argc, char *argv[], char *e
 				"  log_priority=<level> set the udev log level for the daemon\n"
 				"  stop_exec_queue      keep udevd from executing events, queue only\n"
 				"  start_exec_queue     execute events, flush queue\n"
+				"  reload_rules         reloads the rules files\n"
 				"  max_childs=<N>       maximum number of childs running at the same time\n"
 				"  --help               print this help text\n\n");
 			exit(0);
udevd.c +122 -16

277 lines not on this page · raw message

udevd.h +1 -0
@@ -54,6 +54,7 @@ enum udevd_msg_type {
 	UDEVD_START_EXEC_QUEUE,
 	UDEVD_SET_LOG_LEVEL,
 	UDEVD_SET_MAX_CHILDS,
+	UDEVD_RELOAD_RULES,
 };
 
 
#7 lore raw
In reply to Kay Sievers
Quoted 10 lines · Kay Sievers
Quoted 7 lines · Greg KH
Quoted 4 lines · Kay Sievers

Here we go with the Inotify version on top of the current tree. I've added some stuff to our libc-wrapper file until the inotify headers have reached glibc and we can just add an #include to udevd.c for it.

Looks good to me.

Here is a version on top of the new 066.

New version to compile successfully with glibc and klibc on:
i386, x86_64, ppc, ppc64, ia64, s390, s390x

Thanks,
Kay

klibc/klibc/SYSCALLS.def +3 -0
@@ -114,6 +114,9 @@ int lchown32,lchown::lchown(const char *
 int getcwd::__getcwd(char *, size_t)
 <?> int utime(const char *, const struct utimbuf *)
 <?> int utimes(const char *, const struct timeval *)
+<?> int inotify_init(void)
+<?> int inotify_add_watch(int, const char *, __u32)
+<?> int inotify_rm_watch(int, __u32)
 
 ;
 ; I/O operations
udev_libc_wrapper.h +76 -2

100 lines not on this page · raw message

udevcontrol.c +3 -0
@@ -89,6 +89,8 @@ int main(int argc, char *argv[], char *e
 			usend_msg.type = UDEVD_STOP_EXEC_QUEUE;
 		else if (!strcmp(arg, "start_exec_queue"))
 			usend_msg.type = UDEVD_START_EXEC_QUEUE;
+		else if (!strcmp(arg, "reload_rules"))
+			usend_msg.type = UDEVD_RELOAD_RULES;
 		else if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
 			intval = (int *) usend_msg.envbuf;
 			val = &arg[strlen("log_priority=")];
@@ -106,6 +108,7 @@ int main(int argc, char *argv[], char *e
 				"  log_priority=<level> set the udev log level for the daemon\n"
 				"  stop_exec_queue      keep udevd from executing events, queue only\n"
 				"  start_exec_queue     execute events, flush queue\n"
+				"  reload_rules         reloads the rules files\n"
 				"  max_childs=<N>       maximum number of childs running at the same time\n"
 				"  --help               print this help text\n\n");
 			exit(0);
udevd.c +123 -16

278 lines not on this page · raw message

udevd.h +1 -0
@@ -54,6 +54,7 @@ enum udevd_msg_type {
 	UDEVD_START_EXEC_QUEUE,
 	UDEVD_SET_LOG_LEVEL,
 	UDEVD_SET_MAX_CHILDS,
+	UDEVD_RELOAD_RULES,
 };
 
 
#8 lore raw
In reply to Kay Sievers
Quoted 8 lines · Kay Sievers
Quoted 7 lines · Kay Sievers
Quoted 6 lines · Greg KH
Quoted 4 lines · Kay Sievers

Here we go with the Inotify version on top of the current tree. I've added some stuff to our libc-wrapper file until the inotify headers have reached glibc and we can just add an #include to udevd.c for it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Looks good to me.

Here is a version on top of the new 066.

New version to compile successfully with glibc and klibc on:
i386, x86_64, ppc, ppc64, ia64, s390, s390x

I'm happy with this, care to add this to your git tree, so I can add it to mainline? Any one else have any objections to this?

thanks,

greg k-h

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#9 lore raw
In reply to Kay Sievers
Quoted 11 lines · Greg KH
Quoted 10 lines · Kay Sievers
Quoted 9 lines · Kay Sievers
Quoted 7 lines · Greg KH
Quoted 4 lines · Kay Sievers

Here we go with the Inotify version on top of the current tree. I've added some stuff to our libc-wrapper file until the inotify headers have reached glibc and we can just add an #include to udevd.c for it.

Looks good to me.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Here is a version on top of the new 066.

New version to compile successfully with glibc and klibc on:
i386, x86_64, ppc, ppc64, ia64, s390, s390x

I'm happy with this, care to add this to your git tree, so I can add it to mainline? Any one else have any objections to this?

Here is a version on top of the current release. We hopefully fixed all remaining issues with today's version 068 so this can go into mainline next week.

Thanks,
Kay

etc/udev/udev.conf.in +3 -1
@@ -9,6 +9,8 @@ udev_db="@udevdir@/.udevdb"
 # The name and location of the udev rules file(s).
 udev_rules="@configdir@/rules.d"
 
-# The syslog(3) priority: "err", "info", or the numerical value.
+# The initial syslog(3) priority: "err", "info", "debug" or its
+# numerical equivalent. For runtime debugging, change the daemons
+# internal state with: "udevcontrol log_priority=<value>".
 udev_log="err"
 
klibc/klibc/SYSCALLS.def +3 -0
@@ -114,6 +114,9 @@ int lchown32,lchown::lchown(const char *
 int getcwd::__getcwd(char *, size_t)
 <?> int utime(const char *, const struct utimbuf *)
 <?> int utimes(const char *, const struct timeval *)
+<?> int inotify_init(void)
+<?> int inotify_add_watch(int, const char *, __u32)
+<?> int inotify_rm_watch(int, __u32)
 
 ;
 ; I/O operations
udev_libc_wrapper.h +69 -0

75 lines not on this page · raw message

udevcontrol.c +3 -0
@@ -89,6 +89,8 @@ int main(int argc, char *argv[], char *e
 			usend_msg.type = UDEVD_STOP_EXEC_QUEUE;
 		else if (!strcmp(arg, "start_exec_queue"))
 			usend_msg.type = UDEVD_START_EXEC_QUEUE;
+		else if (!strcmp(arg, "reload_rules"))
+			usend_msg.type = UDEVD_RELOAD_RULES;
 		else if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
 			intval = (int *) usend_msg.envbuf;
 			val = &arg[strlen("log_priority=")];
@@ -106,6 +108,7 @@ int main(int argc, char *argv[], char *e
 				"  log_priority=<level> set the udev log level for the daemon\n"
 				"  stop_exec_queue      keep udevd from executing events, queue only\n"
 				"  start_exec_queue     execute events, flush queue\n"
+				"  reload_rules         reloads the rules files\n"
 				"  max_childs=<N>       maximum number of childs running at the same time\n"
 				"  --help               print this help text\n\n");
 			exit(0);
udevd.c +116 -24

268 lines not on this page · raw message

udevd.h +1 -0
@@ -54,6 +54,7 @@ enum udevd_msg_type {
 	UDEVD_START_EXEC_QUEUE,
 	UDEVD_SET_LOG_LEVEL,
 	UDEVD_SET_MAX_CHILDS,
+	UDEVD_RELOAD_RULES,
 };