chiark / gitweb /
[PATCH] make config files, sysfs root, and udev root configurable from config variables
authorgreg@kroah.com <greg@kroah.com>
Wed, 22 Oct 2003 03:19:09 +0000 (20:19 -0700)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:01:42 +0000 (21:01 -0700)
This will make running tests a lot simpler.

namedev.c
namedev.h
udev-add.c
udev-remove.c
udev.c
udev.h
udevdb.c
udevdb.h

index c21a5be7ad53549ba086b577de84b946d6bbf0bf..f2842ce436e5364396b0a11cbd52f532a58563d9 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -197,7 +197,6 @@ static int get_pair(char **orig_string, char **left, char **right)
 
 static int namedev_init_config(void)
 {
-       char filename[255];
        char line[255];
        char *temp;
        char *temp2;
@@ -206,11 +205,10 @@ static int namedev_init_config(void)
        int retval = 0;
        struct config_device dev;
 
-       strcpy(filename, UDEV_CONFIG_DIR NAMEDEV_CONFIG_FILE);
-       dbg("opening %s to read as permissions config", filename);
-       fd = fopen(filename, "r");
+       dbg("opening %s to read as permissions config", udev_config_filename);
+       fd = fopen(udev_config_filename, "r");
        if (fd == NULL) {
-               dbg("Can't open %s", filename);
+               dbg("Can't open %s", udev_config_filename);
                return -ENODEV;
        }
 
@@ -394,7 +392,6 @@ exit:
 
 static int namedev_init_permissions(void)
 {
-       char filename[255];
        char line[255];
        char *temp;
        char *temp2;
@@ -402,11 +399,10 @@ static int namedev_init_permissions(void)
        int retval = 0;
        struct config_device dev;
 
-       strcpy(filename, UDEV_CONFIG_DIR NAMEDEV_CONFIG_PERMISSION_FILE);
-       dbg("opening %s to read as permissions config", filename);
-       fd = fopen(filename, "r");
+       dbg("opening %s to read as permissions config", udev_config_permission_filename);
+       fd = fopen(udev_config_permission_filename, "r");
        if (fd == NULL) {
-               dbg("Can't open %s", filename);
+               dbg("Can't open %s", udev_config_permission_filename);
                return -ENODEV;
        }
 
index 567756c827f0931d7a31bcb824e09cf135e13533..d5aaae202cf28e4fa7eefb9f6a9b5e26850ae45f 100644 (file)
--- a/namedev.h
+++ b/namedev.h
 
 struct sysfs_class_device;
 
-/* namedev config files */
 #define COMMENT_CHARACTER              '#'
-#define NAMEDEV_CONFIG_PERMISSION_FILE "namedev.permissions"
-#define NAMEDEV_CONFIG_FILE            "namedev.config"
 
 enum config_type {
        KERNEL_NAME     = 0,    /* must be 0 to let memset() default to this value */
index 7906638a7f066670fbd2bea6d5a603d523fdb309..d9d7cab103098a35b14d95f384ade479399cb269 100644 (file)
@@ -34,8 +34,6 @@
 #include "udevdb.h"
 #include "libsysfs/libsysfs.h"
 
-static char sysfs_path[SYSFS_PATH_MAX];
-
 /* 
  * Right now the major/minor of a device is stored in a file called
  * "dev" in sysfs.
@@ -75,7 +73,7 @@ static int create_node(struct udevice *dev)
        char filename[255];
        int retval = 0;
 
-       strncpy(filename, UDEV_ROOT, sizeof(filename));
+       strncpy(filename, udev_root, sizeof(filename));
        strncat(filename, dev->name, sizeof(filename));
 
        switch (dev->type) {
@@ -171,13 +169,6 @@ int udev_add_device(char *path, char *subsystem)
        else
                dev.type = 'c';
 
-       retval = sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX);
-       dbg("sysfs_path = %s", sysfs_path);
-       if (retval) {
-               dbg("sysfs_get_mnt_path failed");
-               goto exit;
-       }
-
        retval = sleep_for_dev(path);
        if (retval)
                goto exit;
index c61a948fa0b179ba987063d922995f703b5cc3c5..666928f318fa7699062f75009f503179262a1ce0 100644 (file)
@@ -70,7 +70,7 @@ static int delete_node(char *name)
 {
        char filename[255];
 
-       strncpy(filename, UDEV_ROOT, sizeof(filename));
+       strncpy(filename, udev_root, sizeof(filename));
        strncat(filename, name, sizeof(filename));
 
        dbg("unlinking %s", filename);
diff --git a/udev.c b/udev.c
index a3984771188a50d33a3e6b02fcf38922868ea8df..8d650c2561ddaa1f5d11bfb8d0340d59b1761810 100644 (file)
--- a/udev.c
+++ b/udev.c
 #include "udevdb.h"
 #include "libsysfs/libsysfs.h"
 
+/* global variables */
+char **main_argv;
+char **main_envp;
+
+char sysfs_path[SYSFS_PATH_MAX];
+char *udev_config_dir;
+char *udev_root;
+char udev_db_filename[PATH_MAX+NAME_MAX];
+char udev_config_permission_filename[PATH_MAX+NAME_MAX];
+char udev_config_filename[PATH_MAX+NAME_MAX];
+
 
-static char *get_action(void)
+static inline char *get_action(void)
 {
        char *action;
 
@@ -43,22 +54,60 @@ static char *get_action(void)
        return action;
 }
 
+static inline char *get_devpath(void)
+{
+       char *devpath;
+
+       devpath = getenv("DEVPATH");
+       return devpath;
+}
 
-static char *get_device(void)
+static inline char *get_seqnum(void)
 {
-       char *device;
+       char *seqnum;
 
-       device = getenv("DEVPATH");
-       return device;
+       seqnum = getenv("SEQNUM");
+       return seqnum;
 }
 
-char **main_argv;
-char **main_envp;
+static void get_dirs(void)
+{
+       char *udev_test;
+       char *temp;
+       int retval;
+
+       udev_test = getenv("UDEV_TEST");
+       if (udev_test == NULL) {
+               /* normal operation, use the compiled in defaults */
+               udev_config_dir = UDEV_CONFIG_DIR;
+               udev_root = UDEV_ROOT;
+               retval = sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX);
+               dbg("sysfs_path = %s", sysfs_path);
+               if (retval)
+                       dbg("sysfs_get_mnt_path failed");
+
+       } else {
+               /* hm testing is happening, use the specified values */
+               temp = getenv("UDEV_SYSFS_PATH");
+               strncpy(sysfs_path, temp, sizeof(sysfs_path));
+               udev_config_dir = getenv("UDEV_CONFIG_DIR");
+               udev_root = getenv("UDEV_ROOT");
+       }
+
+       strncpy(udev_db_filename, udev_config_dir, sizeof(udev_db_filename));
+       strncat(udev_db_filename, UDEV_DB, sizeof(udev_db_filename));
+
+       strncpy(udev_config_filename, udev_config_dir, sizeof(udev_config_filename));
+       strncat(udev_config_filename, NAMEDEV_CONFIG_FILE, sizeof(udev_config_filename));
+       
+       strncpy(udev_config_permission_filename, udev_config_dir, sizeof(udev_config_permission_filename));
+       strncat(udev_config_permission_filename, NAMEDEV_CONFIG_PERMISSION_FILE, sizeof(udev_config_permission_filename));
+}
 
 int main(int argc, char **argv, char **envp)
 {
        char *action;
-       char *device;
+       char *devpath;
        char *subsystem;
        int retval = -EINVAL;
        
@@ -74,16 +123,16 @@ int main(int argc, char **argv, char **envp)
 
        subsystem = argv[1];
 
-       device = get_device();
-       if (!device) {
-               dbg ("no device?");
+       devpath = get_devpath();
+       if (!devpath) {
+               dbg ("no devpath?");
                goto exit;
        }
-       dbg("looking at %s", device);
+       dbg("looking at %s", devpath);
 
        /* we only care about class devices and block stuff */
-       if (!strstr(device, "class") &&
-           !strstr(device, "block")) {
+       if (!strstr(devpath, "class") &&
+           !strstr(devpath, "block")) {
                dbg("not block or class");
                goto exit;
        }
@@ -101,6 +150,7 @@ int main(int argc, char **argv, char **envp)
        }
 
        /* initialize udev database */
+       get_dirs();
        retval = udevdb_init(UDEVDB_DEFAULT);
        if (retval != 0) {
                dbg("Unable to initialize database.");
@@ -111,10 +161,10 @@ int main(int argc, char **argv, char **envp)
        namedev_init();
 
        if (strcmp(action, "add") == 0)
-               retval = udev_add_device(device, argv[1]);
+               retval = udev_add_device(devpath, subsystem);
 
        else if (strcmp(action, "remove") == 0)
-               retval = udev_remove_device(device, argv[1]);
+               retval = udev_remove_device(devpath, subsystem);
 
        else {
                dbg("Unknown action: %s", action);
diff --git a/udev.h b/udev.h
index 6d7017ff511b07bdaee729e5368e505e3d2dbb58..4c8914f1e2b4727d32d7976d743f94b6609f76bd 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -24,6 +24,7 @@
 #define UDEV_H
 
 #include "libsysfs/libsysfs.h"
+#include <limits.h>
 
 #ifdef DEBUG
 #include <syslog.h>
@@ -50,7 +51,10 @@ extern int log_message (int level, const char *format, ...)
        __attribute__ ((format (printf, 2, 3)));
 
 
-/* Lots of constants that should be in a config file sometime */
+/* filenames for the config and database files */
+#define UDEV_DB                                "udevdb.tdb"
+#define NAMEDEV_CONFIG_PERMISSION_FILE "namedev.permissions"
+#define NAMEDEV_CONFIG_FILE            "namedev.config"
 
 #define NAME_SIZE      100
 #define OWNER_SIZE     30
@@ -78,5 +82,12 @@ extern int udev_remove_device(char *path, char *subsystem);
 
 extern char **main_argv;
 extern char **main_envp;
+extern char sysfs_path[SYSFS_PATH_MAX];
+extern char *udev_config_dir;
+extern char *udev_root;
+extern char udev_db_filename[PATH_MAX+NAME_MAX];
+extern char udev_config_permission_filename[PATH_MAX+NAME_MAX];
+extern char udev_config_filename[PATH_MAX+NAME_MAX];
+
 #endif
 
index b75bf8048f1dd3633dea0844bfa7faae5f585018..ec67a079627df09cec9cdf5a1733d99e87139051 100644 (file)
--- a/udevdb.c
+++ b/udevdb.c
@@ -124,12 +124,12 @@ int udevdb_init(int init_flag)
        if (init_flag != UDEVDB_DEFAULT && init_flag != UDEVDB_INTERNAL)
                return -EINVAL;
 
-       udevdb = tdb_open(UDEV_CONFIG_DIR UDEV_DB, 0, init_flag, O_RDWR | O_CREAT, 0644);
+       udevdb = tdb_open(udev_db_filename, 0, init_flag, O_RDWR | O_CREAT, 0644);
        if (udevdb == NULL) {
                if (init_flag == UDEVDB_INTERNAL)
                        dbg("Unable to initialize in-memory database");
                else
-                       dbg("Unable to initialize database at %s", UDEV_CONFIG_DIR UDEV_DB);
+                       dbg("Unable to initialize database at %s", udev_db_filename);
                return -EINVAL;
        }
        return 0;
index 12f66483694be8ddbe244e9635670bdee504e259..9935e80e9c4edbaa7075e1a9c806c7a95c313c47 100644 (file)
--- a/udevdb.h
+++ b/udevdb.h
@@ -4,8 +4,6 @@
 #ifndef _UDEVDB_H_
 #define _UDEVDB_H_
 
-#define UDEV_DB                "udevdb.tdb" 
-
 /* Udevdb initialization flags */
 #define UDEVDB_DEFAULT 0       /* Defaults database to use file */
 #define UDEVDB_INTERNAL        1       /* Don't store db on disk, use in memory */