]> err.no Git - systemd/commitdiff
[PATCH] make the udev object available to more processing stages
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Fri, 12 Nov 2004 05:20:22 +0000 (06:20 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 05:24:38 +0000 (22:24 -0700)
Remove the overwriting of main_argv[] hack and use the values
from the udev object.

Pass the udev object to call_foreach_file().

In the udevstart case, export SUBSYSTEM and UDEVSTART to the
environment.

dev_d.c
namedev.c
namedev_parse.c
udev.c
udev.h
udev_lib.c
udev_lib.h
udevinfo.c
udevstart.c
udevtest.c

diff --git a/dev_d.c b/dev_d.c
index 6e35f55ca2ea380b9e822218bd07b1831013e523..1108c8cee40b8b68241dba4d9d9c2042d0384e8b 100644 (file)
--- a/dev_d.c
+++ b/dev_d.c
 #define DEVD_DIR                       "/etc/dev.d/"
 #define DEVD_SUFFIX                    ".dev"
 
-static int run_program(char *name)
+static int run_program(const char *filename, void *data)
 {
        pid_t pid;
        int fd;
-       char *argv[3];
+       struct udevice *udev = data;
 
-       dbg("running %s", name);
+       dbg("running %s", filename);
 
        pid = fork();
        switch (pid) {
@@ -55,11 +55,7 @@ static int run_program(char *name)
                }
                close(fd);
 
-               argv[0] = name;
-               argv[1] = main_argv[1];
-               argv[2] = NULL;
-
-               execv(name, argv);
+               execl(filename, filename, udev->subsystem, NULL);
                dbg("exec of child failed");
                _exit(1);
        case -1:
@@ -105,7 +101,7 @@ void dev_d_execute(struct udevice *udev)
                temp[0] = '\0';
                strcpy(dirname, DEVD_DIR);
                strfieldcat(dirname, devname);
-               call_foreach_file(run_program, dirname, DEVD_SUFFIX);
+               call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
 
                temp[0] = '/';
                ++temp;
@@ -114,12 +110,12 @@ void dev_d_execute(struct udevice *udev)
 
        strcpy(dirname, DEVD_DIR);
        strfieldcat(dirname, udev->name);
-       call_foreach_file(run_program, dirname, DEVD_SUFFIX);
+       call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
 
        strcpy(dirname, DEVD_DIR);
        strfieldcat(dirname, udev->subsystem);
-       call_foreach_file(run_program, dirname, DEVD_SUFFIX);
+       call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
 
        strcpy(dirname, DEVD_DIR "default");
-       call_foreach_file(run_program, dirname, DEVD_SUFFIX);
+       call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
 }
index d63e36e18a05b3e2c1ca9c5c689842d8c1779e89..268a3d5be667b0a4cbcbaf34817e24ca2521e8f8 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -358,7 +358,7 @@ static void fix_kernel_name(struct udevice *udev)
        }
 }
 
-static int execute_program(const char *path, char *value, int len)
+static int execute_program(struct udevice *udev, const char *path, char *value, int len)
 {
        int retval;
        int count;
@@ -391,7 +391,7 @@ static int execute_program(const char *path, char *value, int len)
                dbg("execute '%s' with parsed arguments", arg);
        } else {
                argv[0] = arg;
-               argv[1] = main_argv[1];
+               argv[1] = udev->subsystem;
                argv[2] = NULL;
                dbg("execute '%s' with subsystem '%s' argument", arg, argv[1]);
        }
@@ -655,7 +655,7 @@ static int match_rule(struct config_device *dev, struct sysfs_class_device *clas
                        dbg("check " FIELD_PROGRAM);
                        strfieldcpy(program, dev->program);
                        apply_format(udev, program, sizeof(program), class_dev, sysfs_device);
-                       if (execute_program(program, udev->program_result, NAME_SIZE) != 0) {
+                       if (execute_program(udev, program, udev->program_result, NAME_SIZE) != 0) {
                                dbg(FIELD_PROGRAM " returned nonzero");
                                goto try_parent;
                        } else {
index 22e3523f3d8b67c474d245a15359f2d1e2157993..73828a83b2f864d436c222d1085779db74bacd78 100644 (file)
@@ -142,7 +142,7 @@ static char *get_key_attribute(char *str)
        return NULL;
 }
 
-static int namedev_parse_rules(char *filename)
+static int namedev_parse_rules(const char *filename, void *data)
 {
        char line[LINE_SIZE];
        char *bufline;
@@ -343,7 +343,7 @@ error:
        return retval;
 }
 
-static int namedev_parse_permissions(char *filename)
+static int namedev_parse_permissions(const char *filename, void *data)
 {
        char line[LINE_SIZE];
        char *bufline;
@@ -447,10 +447,10 @@ int namedev_init_rules(void)
 
        stat(udev_rules_filename, &stats);
        if ((stats.st_mode & S_IFMT) != S_IFDIR)
-               return namedev_parse_rules(udev_rules_filename);
+               return namedev_parse_rules(udev_rules_filename, NULL);
        else
-               return call_foreach_file(namedev_parse_rules,
-                                        udev_rules_filename, RULEFILE_SUFFIX);
+               return call_foreach_file(namedev_parse_rules, udev_rules_filename,
+                                        RULEFILE_SUFFIX, NULL);
 }
 
 int namedev_init_permissions(void)
@@ -459,8 +459,8 @@ int namedev_init_permissions(void)
 
        stat(udev_permissions_filename, &stats);
        if ((stats.st_mode & S_IFMT) != S_IFDIR)
-               return namedev_parse_permissions(udev_permissions_filename);
+               return namedev_parse_permissions(udev_permissions_filename, NULL);
        else
-               return call_foreach_file(namedev_parse_permissions,
-                                        udev_permissions_filename, PERMFILE_SUFFIX);
+               return call_foreach_file(namedev_parse_permissions, udev_permissions_filename,
+                                        PERMFILE_SUFFIX, NULL);
 }
diff --git a/udev.c b/udev.c
index 480a1cdca224e595ff171898affaf9e2858bb54f..300e85ceb0aa0737c74f589cc39de53e43ed6f41 100644 (file)
--- a/udev.c
+++ b/udev.c
 #include "udevdb.h"
 
 
-/* global variables */
-char **main_argv;
-char **main_envp;
-
 #ifdef LOG
 unsigned char logname[LOGNAME_SIZE];
 void log_message(int level, const char *format, ...)
@@ -83,12 +79,7 @@ int main(int argc, char *argv[], char *envp[])
        } act_type;
 
        dbg("version %s", UDEV_VERSION);
-
-       main_argv = argv;
-       main_envp = envp;
-
        logging_init("udev");
-
        udev_init_config();
 
        if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
diff --git a/udev.h b/udev.h
index 3f9f2c8612019e27f99c6849d72ab4a8778e916c..d031b9699c99f6beac79fe897d3924a634a02518 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -73,8 +73,6 @@ extern int udev_start(void);
 extern int parse_get_pair(char **orig_string, char **left, char **right);
 extern void dev_d_execute(struct udevice *udev);
 
-extern char **main_argv;
-extern char **main_envp;
 extern char sysfs_path[SYSFS_PATH_MAX];
 extern char udev_root[PATH_MAX];
 extern char udev_db_path[PATH_MAX+NAME_MAX];
index 84daf9fd19fba4bac7c5d3356c73ab6e27ca542e..012d60b0ea3138baa3082724a5308d90e27657db 100644 (file)
@@ -178,12 +178,12 @@ static int file_list_insert(char *filename, struct list_head *file_list)
 }
 
 /* calls function for every file found in specified directory */
-int call_foreach_file(int fnct(char *f) , char *dirname, char *suffix)
+int call_foreach_file(file_fnct_t fnct, const char *dirname,
+                     const char *suffix, void *data)
 {
        struct dirent *ent;
        DIR *dir;
        char *ext;
-       char file[NAME_SIZE];
        struct files *loop_file;
        struct files *tmp_file;
        LIST_HEAD(file_list);
@@ -217,10 +217,12 @@ int call_foreach_file(int fnct(char *f) , char *dirname, char *suffix)
 
        /* call function for every file in the list */
        list_for_each_entry_safe(loop_file, tmp_file, &file_list, list) {
-               snprintf(file, NAME_SIZE-1, "%s/%s", dirname, loop_file->name);
-               file[NAME_SIZE-1] = '\0';
+               char filename[NAME_SIZE];
 
-               fnct(file);
+               snprintf(filename, NAME_SIZE-1, "%s/%s", dirname, loop_file->name);
+               filename[NAME_SIZE-1] = '\0';
+
+               fnct(filename, data);
 
                list_del(&loop_file->list);
                free(loop_file);
index 3777a7caa338b088342a6bac88c0bceb8f6c2a5e..2bc9ba82ab74e2d534e0d5981fadf1df8bf32c2d 100644 (file)
@@ -84,6 +84,9 @@ 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(char *buf, size_t buflen, size_t cur);
 extern void no_trailing_slash(char *path);
-extern int  call_foreach_file(int fnct(char *f) , char *filename, char *extension);
+
+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);
 
 #endif
index 290a09e880aee1dc7c95c03417fab4ee39e4eea6..11482727436d31a9e78432ac531c4e4cd48bd5b5 100644 (file)
 #include "udevdb.h"
 
 
-# define SYSFS_VALUE_MAX 200
-
-char **main_argv;
-int main_argc;
+#define SYSFS_VALUE_SIZE               256
 
 #ifdef LOG
 unsigned char logname[LOGNAME_SIZE];
@@ -58,7 +55,7 @@ static int print_all_attributes(const char *path)
        struct dlist *attributes;
        struct sysfs_attribute *attr;
        struct sysfs_directory *sysfs_dir;
-       char value[SYSFS_VALUE_MAX];
+       char value[SYSFS_VALUE_SIZE];
        int len;
        int retval = 0;
 
@@ -257,7 +254,7 @@ static int print_sysfs_devices(void)
        return 0;
 }
 
-static int process_options(void)
+static int process_options(int argc, char *argv[])
 {
        static const char short_options[] = "adn:p:q:rsVh";
        int option;
@@ -274,7 +271,7 @@ static int process_options(void)
 
        /* get command line options */
        while (1) {
-               option = getopt(main_argc, main_argv, short_options);
+               option = getopt(argc, argv, short_options);
                if (option == -1)
                        break;
 
@@ -479,15 +476,12 @@ int main(int argc, char *argv[], char *envp[])
 {
        int rc = 0;
 
-       main_argv = argv;
-       main_argc = argc;
-
        logging_init("udevinfo");
 
        /* initialize our configuration */
        udev_init_config();
 
-       rc = process_options();
+       rc = process_options(argc, argv);
 
        logging_close();
        exit(rc);
index e05680aa93d051859c46f8508901b655358376e8..0433e568d448ebbde9f2fd9a23cb7f0f28fa6b1a 100644 (file)
@@ -92,16 +92,10 @@ static int add_device(char *devpath, char *subsystem)
        struct udevice udev;
        char path[SYSFS_PATH_MAX];
        struct sysfs_class_device *class_dev;
-       char *argv[3];
 
-       /* fake argument vector and environment for callouts and dev.d/ */
-       argv[0] = "udev";
-       argv[1] = subsystem;
-       argv[2] = NULL;
-
-       main_argv = argv;
+       /* set environment for callouts and dev.d/ */
        setenv("DEVPATH", devpath, 1);
-       setenv("ACTION", "add", 1);
+       setenv("SUBSYSTEM", subsystem, 1);
 
        snprintf(path, SYSFS_PATH_MAX-1, "%s%s", sysfs_path, devpath);
        class_dev = sysfs_open_class_device_path(path);
@@ -291,7 +285,12 @@ static void udev_scan_class(void)
 
 int udev_start(void)
 {
+       /* set environment for callouts and dev.d/ */
+       setenv("ACTION", "add", 1);
+       setenv("UDEVSTART", "1", 1);
+
        udev_scan_class();
        udev_scan_block();
+
        return 0;
 }
index e67af0df673fb05dd3378afb056f95f79f7dd697..14c511584ba8ad362861b6313f3409d4242d3ea3 100644 (file)
 #include "logging.h"
 #include "namedev.h"
 
-/* global variables */
-char **main_argv;
-char **main_envp;
-
 
 #ifdef LOG
 unsigned char logname[LOGNAME_SIZE];
@@ -62,9 +58,6 @@ int main(int argc, char *argv[], char *envp[])
        char *subsystem = "";
        struct udevice udev;
 
-       main_argv = argv;
-       main_envp = envp;
-
        info("version %s", UDEV_VERSION);
 
        if (argv[1] == NULL) {