From: Lindsay Haisley <fmouse-gentoo@fmp.com>
To: linux-hotplug@vger.kernel.org
Subject: udevstart.c -> kscan.c
Date: Mon, 25 Oct 2004 06:30:19 +0000 [thread overview]
Message-ID: <20041025063019.GB23239@fmp.com> (raw)
[-- 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;
}
next reply other threads:[~2004-10-25 6:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-25 6:30 Lindsay Haisley [this message]
2004-10-25 6:45 ` udevstart.c -> kscan.c Greg KH
2004-10-25 7:22 ` Lindsay Haisley
2004-10-25 7:46 ` Lindsay Haisley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041025063019.GB23239@fmp.com \
--to=fmouse-gentoo@fmp.com \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.