diff options
-rw-r--r-- | namedev.c | 16 | ||||
-rw-r--r-- | namedev.h | 3 | ||||
-rw-r--r-- | udev-add.c | 11 | ||||
-rw-r--r-- | udev-remove.c | 2 | ||||
-rw-r--r-- | udev.c | 82 | ||||
-rw-r--r-- | udev.h | 13 | ||||
-rw-r--r-- | udevdb.c | 4 | ||||
-rw-r--r-- | udevdb.h | 2 |
8 files changed, 88 insertions, 45 deletions
@@ -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; } @@ -28,10 +28,7 @@ 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 */ diff --git a/udev-add.c b/udev-add.c index 7906638a7f..d9d7cab103 100644 --- a/udev-add.c +++ b/udev-add.c @@ -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; diff --git a/udev-remove.c b/udev-remove.c index c61a948fa0..666928f318 100644 --- a/udev-remove.c +++ b/udev-remove.c @@ -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); @@ -34,8 +34,19 @@ #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); @@ -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 @@ -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; @@ -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 */ |