From: kay.sievers@vrfy.org Date: Fri, 4 Mar 2005 20:33:57 +0000 (+0100) Subject: [PATCH] remove typedef for call_foreach_file() handler function X-Git-Tag: 055~54 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=f0308095c78fd68c29be9b3b391bc1c077afa04c [PATCH] remove typedef for call_foreach_file() handler function --- diff --git a/namedev_parse.c b/namedev_parse.c index ed38db4b1..e36056595 100644 --- a/namedev_parse.c +++ b/namedev_parse.c @@ -98,7 +98,7 @@ static char *get_key_attribute(char *str) return NULL; } -static int namedev_parse(const char *filename, void *data) +static int namedev_parse(struct udevice *udev, const char *filename) { char line[LINE_SIZE]; char *bufline; @@ -354,9 +354,9 @@ int namedev_init(void) return -1; if ((stats.st_mode & S_IFMT) != S_IFDIR) - retval = namedev_parse(udev_rules_filename, NULL); + retval = namedev_parse(NULL, udev_rules_filename); else - retval = call_foreach_file(namedev_parse, udev_rules_filename, RULEFILE_SUFFIX, NULL); + retval = call_foreach_file(namedev_parse, NULL, udev_rules_filename, RULEFILE_SUFFIX); return retval; } @@ -364,8 +364,9 @@ int namedev_init(void) void namedev_close(void) { struct config_device *dev; + struct config_device *temp_dev; - list_for_each_entry(dev, &config_device_list, node) { + list_for_each_entry_safe(dev, temp_dev, &config_device_list, node) { list_del(&dev->node); free(dev); } diff --git a/udev.h b/udev.h index ddcfa81c8..f1236194d 100644 --- a/udev.h +++ b/udev.h @@ -4,6 +4,7 @@ * Userspace devfs * * Copyright (C) 2003 Greg Kroah-Hartman + * Copyright (C) 2003-2005 Kay Sievers * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/udev_db.h b/udev_db.h index 6a0647f20..2fce06be7 100644 --- a/udev_db.h +++ b/udev_db.h @@ -28,7 +28,7 @@ extern int udev_db_add_device(struct udevice *dev); extern int udev_db_delete_device(struct udevice *dev); -extern int udev_db_get_device_by_devpath(struct udevice *dev, const char *devpath); +extern int udev_db_get_device_by_devpath(struct udevice *udev, const char *devpath); extern int udev_db_get_device_by_name(struct udevice *udev, const char *name); extern int udev_db_call_foreach(int (*handler_function)(struct udevice *udev)); diff --git a/udev_multiplex.c b/udev_multiplex.c index 3a484068f..6d7852dbc 100644 --- a/udev_multiplex.c +++ b/udev_multiplex.c @@ -31,11 +31,10 @@ #include "udev_utils.h" #include "logging.h" -static int run_program(const char *filename, void *data) +static int run_program(struct udevice *udev, const char *filename) { pid_t pid; int fd; - struct udevice *udev = data; dbg("running %s", filename); @@ -89,7 +88,7 @@ void udev_multiplex_directory(struct udevice *udev, const char *basedir, const c if (strcmp(devname, udev->subsystem) != 0) { snprintf(dirname, PATH_MAX, "%s/%s", basedir, devname); dirname[PATH_MAX-1] = '\0'; - call_foreach_file(run_program, dirname, suffix, udev); + call_foreach_file(run_program, udev, dirname, suffix); } temp[0] = '/'; @@ -101,16 +100,16 @@ void udev_multiplex_directory(struct udevice *udev, const char *basedir, const c if (udev->name[0] != '\0') { snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name); dirname[PATH_MAX-1] = '\0'; - call_foreach_file(run_program, dirname, suffix, udev); + call_foreach_file(run_program, udev, dirname, suffix); } if (udev->subsystem[0] != '\0') { snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem); dirname[PATH_MAX-1] = '\0'; - call_foreach_file(run_program, dirname, suffix, udev); + call_foreach_file(run_program, udev, dirname, suffix); } snprintf(dirname, PATH_MAX, "%s/default", basedir); dirname[PATH_MAX-1] = '\0'; - call_foreach_file(run_program, dirname, suffix, udev); + call_foreach_file(run_program, udev, dirname, suffix); } diff --git a/udev_utils.c b/udev_utils.c index f2534dd33..cfa4ab51b 100644 --- a/udev_utils.c +++ b/udev_utils.c @@ -259,13 +259,7 @@ void no_trailing_slash(char *path) path[--len] = '\0'; } -struct name_entry { - struct list_head node; - char name[NAME_SIZE]; -}; - -/* sort files in lexical order */ -static int name_list_add(struct list_head *name_list, const char *name, int sort) +int name_list_add(struct list_head *name_list, const char *name, int sort) { struct name_entry *loop_name; struct name_entry *new_name; @@ -288,11 +282,13 @@ static int name_list_add(struct list_head *name_list, const char *name, int sort strfieldcpy(new_name->name, name); list_add_tail(&new_name->node, &loop_name->node); + return 0; } /* calls function for every file found in specified directory */ -int call_foreach_file(file_fnct_t fnct, const char *dirname, const char *suffix, void *data) +int call_foreach_file(int (*handler_function)(struct udevice *udev, const char *string), + struct udevice *udev, const char *dirname, const char *suffix) { struct dirent *ent; DIR *dir; @@ -335,7 +331,7 @@ int call_foreach_file(file_fnct_t fnct, const char *dirname, const char *suffix, snprintf(filename, NAME_SIZE, "%s/%s", dirname, loop_file->name); filename[NAME_SIZE-1] = '\0'; - fnct(filename, data); + handler_function(udev, filename); list_del(&loop_file->node); free(loop_file); diff --git a/udev_utils.h b/udev_utils.h index 268c2075d..1ab4752cd 100644 --- a/udev_utils.h +++ b/udev_utils.h @@ -76,6 +76,11 @@ do { \ # define asmlinkage /* nothing */ #endif +struct name_entry { + struct list_head node; + char name[NAME_SIZE]; +}; + extern int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem); extern int kernel_release_satisfactory(unsigned int version, unsigned int patchlevel, unsigned int sublevel); extern int create_path(const char *path); @@ -85,8 +90,7 @@ extern int file_map(const char *filename, char **buf, size_t *bufsize); extern void file_unmap(char *buf, size_t bufsize); extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur); extern void no_trailing_slash(char *path); -typedef int (*file_fnct_t)(const char *filename, void *data); -extern int call_foreach_file(file_fnct_t fnct, const char *dirname, - const char *suffix, void *data); - +extern int name_list_add(struct list_head *name_list, const char *name, int sort); +extern int call_foreach_file(int (*handler_function)(struct udevice *udev, const char *string), + struct udevice *udev, const char *dirname, const char *suffix); #endif