linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* udevstart.c -> kscan.c
@ 2004-10-25  6:30 Lindsay Haisley
  2004-10-25  6:45 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Lindsay Haisley @ 2004-10-25  6:30 UTC (permalink / raw)
  To: linux-hotplug

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

Here's a rather more polished, less buggy version of kscan.c, as a diff
against udevstart.c.

-- 
Lindsay Haisley       | "Fighting against human |     PGP public key
FMP Computer Services |    creativity is like   |      available at
512-259-1190          |    trying to eradicate  | <http://pubkeys.fmp.com>
http://www.fmp.com    |        dandelions"      |
                      |      (Pamela Jones)     |

[-- Attachment #2: udevstart2kscan-030.diff --]
[-- Type: text/plain, Size: 4120 bytes --]

--- udevstart.c	2004-07-09 12:59:10.000000000 -0500
+++ kscan.c	2004-10-25 01:12:00.000000000 -0500
@@ -1,5 +1,5 @@
 /*
- * udevstart.c
+ * kscan.c, based on udevstart.c
  *
  * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
  * 
@@ -20,6 +20,7 @@
  *	with this program; if not, write to the Free Software Foundation, Inc.,
  *	675 Mass Ave, Cambridge, MA 02139, USA.
  *
+ *      Mods to create kscan added by Lindsay Haisley <fmouse@fmp.com>
  */
 
 #include <stdlib.h>
@@ -33,28 +34,15 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#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
-
-
 #define MAX_PATHLEN		1024
 #define SYSBLOCK		"/sys/block"
 #define SYSCLASS		"/sys/class"
-#define UDEV_BIN		"/sbin/udev"
+#define OUTPUT_FORMAT		"%-15s KERNEL=\"%s\"\n"
+
 
 struct device {
 	struct list_head list;
@@ -62,6 +50,37 @@
 	char subsys[MAX_PATHLEN];
 };
 
+
+/* Display native kernel devices */
+static void print_dev(char *psubsys, char *path)
+{
+	char *strbuf, *tok, *utok, *cstr;
+	static char *last_subsys = NULL;
+
+	if (last_subsys == NULL) last_subsys = malloc(MAX_PATHLEN);
+	strbuf = malloc(MAX_PATHLEN);
+	strcpy(strbuf, path);
+	tok = strtok(strbuf, "/");
+	utok = tok;
+	while (1) {
+		if (!tok) break;
+		else utok = tok;
+		tok = strtok(NULL, "/");
+	}
+	if (strcmp(psubsys, last_subsys)) {
+		strcpy(last_subsys, psubsys);
+		cstr = malloc(strlen(psubsys) + 1);
+		strcpy(cstr, psubsys);
+		strcat(cstr, ":");
+		printf("\n" OUTPUT_FORMAT, cstr, utok);
+		free(cstr);
+	} else {
+		printf(OUTPUT_FORMAT, "", utok);
+	}
+	free(strbuf);
+}	
+
+
 /* sort files in lexical order */
 static int device_list_insert(char *path, char *subsystem, struct list_head *device_list)
 {
@@ -76,7 +95,6 @@
 
 	new_device = malloc(sizeof(struct device));
 	if (new_device == NULL) {
-		dbg("error malloc");
 		return -ENOMEM;
 	}
 
@@ -86,32 +104,6 @@
 	return 0;
 }
 
-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");
-		exit(1);
-		break;
-	case -1:
-		dbg("fork of child failed");
-		break;
-	default:
-		wait(NULL);
-	}
-}
 
 /* list of devices that we should run last due to any one of a number of reasons */
 static char *last_list[] = {
@@ -119,7 +111,7 @@
 	NULL,
 };
 
-static void exec_list(struct list_head *device_list)
+static void print_list(struct list_head *device_list)
 {
 	struct device *loop_device;
 	struct device *tmp_device;
@@ -137,20 +129,20 @@
 		if (found)
 			continue;
 
-		udev_exec(loop_device->path, loop_device->subsys);
+		print_dev(loop_device->subsys, loop_device->path);
 		list_del(&loop_device->list);
 		free(loop_device);
 	}
 
 	/* handle the rest of the devices left over, if any */
 	list_for_each_entry_safe(loop_device, tmp_device, device_list, list) {
-		udev_exec(loop_device->path, loop_device->subsys);
+		print_dev(loop_device->subsys, loop_device->path);
 		list_del(&loop_device->list);
 		free(loop_device);
 	}
 }
 
-static void udev_scan_block(void)
+static void p_udev_scan_block(void)
 {
 	DIR *dir;
 	struct dirent *dent;
@@ -207,10 +199,10 @@
 		closedir(dir);
 	}
 
-	exec_list(&device_list);
+	print_list(&device_list);
 }
 
-static void udev_scan_class(void)
+static void p_udev_scan_class(void)
 {
 	DIR *dir;
 	struct dirent *dent;
@@ -264,15 +256,12 @@
 		closedir(dir);
 	}
 
-	exec_list(&device_list);
+	print_list(&device_list);
 }
 
 int main(int argc, char *argv[], char *envp[])
 {
-	init_logging("udevstart");
-
-	udev_scan_class();
-	udev_scan_block();
-
+	p_udev_scan_block();
+	p_udev_scan_class();
 	return 0;
 }

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

end of thread, other threads:[~2004-10-25  7:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-25  6:30 udevstart.c -> kscan.c Lindsay Haisley
2004-10-25  6:45 ` Greg KH
2004-10-25  7:22 ` Lindsay Haisley
2004-10-25  7:46 ` Lindsay Haisley

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).