* 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* Re: udevstart.c -> kscan.c
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
2 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2004-10-25 6:45 UTC (permalink / raw)
To: linux-hotplug
On Mon, Oct 25, 2004 at 01:30:19AM -0500, Lindsay Haisley wrote:
> Here's a rather more polished, less buggy version of kscan.c, as a diff
> against udevstart.c.
You do realize that the current version of udev is 042, not 030, right?
udevstart is radically different in the current version.
Also, what you are looking for (a list of all kernel class devices) can
be done with the following short bit of shell code. Feel free to add
the 'KERNEL=' portion to the beginning of every line if you think it's
necessary.
thanks,
greg k-h
------------------------
#! /bin/bash
#
# Directory where sysfs is mounted
SYSFS_DIR=/sys
# handle block devices and their partitions
for i in ${SYSFS_DIR}/block/*; do
# each drive
echo ${i#${SYSFS_DIR}/block/}
# each partition, on each device
for j in $i/*; do
if [ -f $j/dev ]; then
echo ${j#${SYSFS_DIR}} | cut --delimiter='/' --fields=4-
fi
done
done
# all other device classes
for i in ${SYSFS_DIR}/class/*; do
for j in $i/*; do
if [ -f $j/dev ]; then
echo ${j#${SYSFS_DIR}} | cut --delimiter='/' --fields=4-
fi
done
done
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
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] 4+ messages in thread* Re: udevstart.c -> kscan.c
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
2 siblings, 0 replies; 4+ messages in thread
From: Lindsay Haisley @ 2004-10-25 7:22 UTC (permalink / raw)
To: linux-hotplug
Thus spake Greg KH on Mon, Oct 25, 2004 at 01:45:10AM CDT
> On Mon, Oct 25, 2004 at 01:30:19AM -0500, Lindsay Haisley wrote:
> > Here's a rather more polished, less buggy version of kscan.c, as a diff
> > against udevstart.c.
>
> You do realize that the current version of udev is 042, not 030, right?
> udevstart is radically different in the current version.
Yes, I'm running gentoo stable, which is at 030. Unstable is at 042. If
I'm going to mess with this stuff and try to talk intelligently (?) about it
I should get on the same plane with everyone else :/
> Also, what you are looking for (a list of all kernel class devices) can
> be done with the following short bit of shell code. Feel free to add
> the 'KERNEL=' portion to the beginning of every line if you think it's
> necessary.
Not necessary, only convenient, as is the SYSFS{blah}="foo" output from
udevinfo.
This script works fine, and gives the required information. The C patch I
tossed out is slightly more informative in that it breaks devices down by
category and makes them easier to find in the output, but the end result is
the same.
If it's not already there, this script certainly belongs in the
distribution.
> thanks,
>
> greg k-h
And thank you for all your good work on this!
--
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) |
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
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] 4+ messages in thread* Re: udevstart.c -> kscan.c
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
2 siblings, 0 replies; 4+ messages in thread
From: Lindsay Haisley @ 2004-10-25 7:46 UTC (permalink / raw)
To: linux-hotplug
Thus spake Lindsay Haisley on Mon, Oct 25, 2004 at 02:22:28AM CDT
>
> > Also, what you are looking for (a list of all kernel class devices) can
> > be done with the following short bit of shell code. Feel free to add
> > the 'KERNEL=' portion to the beginning of every line if you think it's
> > necessary.
For what it's worth, this prettys it up a bit and adds copy 'n paste
convenience.
-------------------------------------
#! /bin/bash
#
# Directory where sysfs is mounted
SYSFS_DIR=/sys
# handle block devices and their partitions
echo "Block Devices:"
for i in ${SYSFS_DIR}/block/*; do
# each drive
echo -n " KERNEL=\""
echo -n ${i#${SYSFS_DIR}/block/}
echo \"
# each partition, on each device
for j in $i/*; do
if [ -f $j/dev ]; then
echo -n ${j#${SYSFS_DIR}} | awk -F/ '{printf(" KERNEL=\"%s\"\n", $4)}'
fi
done
done
echo; echo "Other Devices:"
# all other device classes
for i in ${SYSFS_DIR}/class/*; do
for j in $i/*; do
if [ -f $j/dev ]; then
echo -n ${j#${SYSFS_DIR}} | awk -F/ '{printf(" KERNEL=\"%s\"\n", $4)}'
fi
done
done
--
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) |
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
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] 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).