From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lindsay Haisley Date: Mon, 25 Oct 2004 06:30:19 +0000 Subject: udevstart.c -> kscan.c Message-Id: <20041025063019.GB23239@fmp.com> MIME-Version: 1 Content-Type: multipart/mixed; boundary="=_bailey-19580-1098685824-0001-2" List-Id: To: linux-hotplug@vger.kernel.org This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_bailey-19580-1098685824-0001-2 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline 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://www.fmp.com | dandelions" | | (Pamela Jones) | --=_bailey-19580-1098685824-0001-2 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="udevstart2kscan-030.diff" --- 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 * @@ -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 */ #include @@ -33,28 +34,15 @@ #include #include -#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; } --=_bailey-19580-1098685824-0001-2-- ------------------------------------------------------- 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