linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] make udevtest a real program :)
@ 2004-03-13  0:42 Kay Sievers
  2004-03-13 15:11 ` Bob Barry
  2004-03-22 22:18 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Kay Sievers @ 2004-03-13  0:42 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 586 bytes --]

Here are the missing pieces for udevtest. A simple man page is added,
the blacklist is removed, cause it can't work without having a subsystem.
The Makefile removes all manpages now with a uninstall and installs
udevtest in /usr/bin/.
Any old version from /sbin/ should be deleted by hand.

The only expected argument is the sysfs devpath, here I changed it to be
more tolerant to the input. The path may now be specified with or
without a leading slash and optionally with the /sys moutpoint prepended.

I hope this will end the confusion about the use of this program :)

thanks,
Kay

[-- Attachment #2: 01-udevinfo.patch --]
[-- Type: text/plain, Size: 4257 bytes --]

diff -Nru a/Makefile b/Makefile
--- a/Makefile	Sat Mar 13 01:25:21 2004
+++ b/Makefile	Sat Mar 13 01:25:21 2004
@@ -380,10 +380,11 @@
 	$(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
 	$(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
 	$(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
-	$(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(sbindir)/$(TESTER)
+	$(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
 	$(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
 	$(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
 	$(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
+	$(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
 	$(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
 	$(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
 	- ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
@@ -406,6 +407,10 @@
 	- rm $(initdir)/udev
 	- rm $(mandir)/man8/udev.8
 	- rm $(mandir)/man8/udevinfo.8
+	- rm $(mandir)/man8/udevtest.8
+	- rm $(mandir)/man8/udevstart.8
+	- rm $(mandir)/man8/udevd.8
+	- rm $(mandir)/man8/udevsend.8
 	- rm $(sbindir)/$(ROOT)
 	- rm $(sbindir)/$(DAEMON)
 	- rm $(sbindir)/$(SENDER)
diff -Nru a/udevtest.8 b/udevtest.8
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/udevtest.8	Sat Mar 13 01:25:21 2004
@@ -0,0 +1,17 @@
+.TH UDEVTEST 8 "March 2004" "" "Linux Administrator's Manual"
+.SH NAME
+udevtest \- simulates a udev run to test the configured rules
+.SH SYNOPSIS
+.BI udevtest " sysfs_device_path"
+.SH "DESCRIPTION"
+.B udevtest
+simulates a
+.B udev
+run for the given device, and prints out the node names
+for the given device, the real udev would have created.
+.SH "SEE ALSO"
+.BR udev (8)
+.SH AUTHORS
+.B udevtest
+was developed by Greg Kroah-Hartman <greg@kroah.com> with much help
+from others.
diff -Nru a/udevtest.c b/udevtest.c
--- a/udevtest.c	Sat Mar 13 01:25:21 2004
+++ b/udevtest.c	Sat Mar 13 01:25:21 2004
@@ -37,6 +37,7 @@
 char **main_argv;
 char **main_envp;
 
+
 #ifdef LOG
 unsigned char logname[LOGNAME_SIZE];
 void log_message (int level, const char *format, ...)
@@ -51,72 +52,54 @@
 }
 #endif
 
-static char *subsystem_blacklist[] = {
-	"net",
-	"scsi_host",
-	"scsi_device",
-	"usb_host",
-	"pci_bus",
-	"pcmcia_socket",
-	""
-};
-
-static int udev_hotplug(void)
+int main(int argc, char *argv[], char *envp[])
 {
 	char *devpath;
-	char *subsystem;
-	int retval = -EINVAL;
-	int i;
-
-	devpath = main_argv[1];
-	if (!devpath) {
-		dbg("no devpath?");
+	char temp[NAME_SIZE];
+	char subsystem[] = "";
+	const int fake = 1;
+
+	main_argv = argv;
+	main_envp = envp;
+
+	info("version %s", UDEV_VERSION);
+
+	if (argv[1] == NULL) {
+		info("udevinfo expects the DEVPATH of the sysfs device as a argument");
 		goto exit;
 	}
-	dbg("looking at '%s'", devpath);
+
+	/* initialize our configuration */
+	udev_init_config();
+
+	/* remove sysfs_path if given */
+	if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0)
+		devpath = argv[1] + strlen(sysfs_path);
+	else
+		if (argv[1][0] != '/') {
+			/* prepend '/' if missing */
+			strfieldcpy(temp, "/");
+			strfieldcat(temp, argv[1]);
+			devpath = temp;
+		} else {
+			devpath = argv[1];
+		}
+
+	info("looking at '%s'", devpath);
 
 	/* we only care about class devices and block stuff */
 	if (!strstr(devpath, "class") &&
 	    !strstr(devpath, "block")) {
-		dbg("not a block or class device");
+		info("not a block or class device");
 		goto exit;
 	}
 
-	/* skip blacklisted subsystems */
-	subsystem = main_argv[1];
-	i = 0;
-	while (subsystem_blacklist[i][0] != '\0') {
-		if (strcmp(subsystem, subsystem_blacklist[i]) == 0) {
-			dbg("don't care about '%s' devices", subsystem);
-			goto exit;
-		}
-		i++;
-	}
-
-	/* initialize our configuration */
-	udev_init_config();
-
 	/* initialize the naming deamon */
 	namedev_init();
 
 	/* simulate node creation with fake flag */
-	retval = udev_add_device(devpath, subsystem, 1);
+	udev_add_device(devpath, subsystem, fake);
 
 exit:
-	if (retval > 0)
-		retval = 0;
-
-	return -retval;
+	return 0;
 }
-
-int main(int argc, char *argv[], char *envp[])
-{
-	main_argv = argv;
-	main_envp = envp;
-
-	dbg("version %s", UDEV_VERSION);
-
-	return udev_hotplug();
-}
-
-

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] make udevtest a real program :)
  2004-03-13  0:42 [PATCH] make udevtest a real program :) Kay Sievers
@ 2004-03-13 15:11 ` Bob Barry
  2004-03-22 22:18 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Bob Barry @ 2004-03-13 15:11 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 268 bytes --]

On Saturday 13 March 2004, Kay Sievers wrote:
> Here are the missing pieces for udevtest. 

Thanks!  The attached script uses udevtest to list all devices.
It could be done more efficiently by integrating it into the
udevtest code and making it a command line option.

[-- Attachment #2: udevtest.all --]
[-- Type: application/x-shellscript, Size: 136 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] make udevtest a real program :)
  2004-03-13  0:42 [PATCH] make udevtest a real program :) Kay Sievers
  2004-03-13 15:11 ` Bob Barry
@ 2004-03-22 22:18 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2004-03-22 22:18 UTC (permalink / raw)
  To: linux-hotplug

On Sat, Mar 13, 2004 at 01:42:59AM +0100, Kay Sievers wrote:
> Here are the missing pieces for udevtest. A simple man page is added,
> the blacklist is removed, cause it can't work without having a subsystem.
> The Makefile removes all manpages now with a uninstall and installs
> udevtest in /usr/bin/.
> Any old version from /sbin/ should be deleted by hand.
> 
> The only expected argument is the sysfs devpath, here I changed it to be
> more tolerant to the input. The path may now be specified with or
> without a leading slash and optionally with the /sys moutpoint prepended.
> 
> I hope this will end the confusion about the use of this program :)

Nice, thanks for doing this.

Applied.

greg k-h


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-03-22 22:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-13  0:42 [PATCH] make udevtest a real program :) Kay Sievers
2004-03-13 15:11 ` Bob Barry
2004-03-22 22:18 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).