[PATCH] make config files, sysfs root, and udev root configurable from config variables

This will make running tests a lot simpler.
This commit is contained in:
greg@kroah.com 2003-10-21 20:19:09 -07:00 committed by Greg KH
parent d4e52dd0d9
commit c056c5141b
8 changed files with 89 additions and 46 deletions

View File

@ -197,7 +197,6 @@ static int get_pair(char **orig_string, char **left, char **right)
static int namedev_init_config(void) static int namedev_init_config(void)
{ {
char filename[255];
char line[255]; char line[255];
char *temp; char *temp;
char *temp2; char *temp2;
@ -206,11 +205,10 @@ static int namedev_init_config(void)
int retval = 0; int retval = 0;
struct config_device dev; struct config_device dev;
strcpy(filename, UDEV_CONFIG_DIR NAMEDEV_CONFIG_FILE); dbg("opening %s to read as permissions config", udev_config_filename);
dbg("opening %s to read as permissions config", filename); fd = fopen(udev_config_filename, "r");
fd = fopen(filename, "r");
if (fd == NULL) { if (fd == NULL) {
dbg("Can't open %s", filename); dbg("Can't open %s", udev_config_filename);
return -ENODEV; return -ENODEV;
} }
@ -394,7 +392,6 @@ exit:
static int namedev_init_permissions(void) static int namedev_init_permissions(void)
{ {
char filename[255];
char line[255]; char line[255];
char *temp; char *temp;
char *temp2; char *temp2;
@ -402,11 +399,10 @@ static int namedev_init_permissions(void)
int retval = 0; int retval = 0;
struct config_device dev; struct config_device dev;
strcpy(filename, UDEV_CONFIG_DIR NAMEDEV_CONFIG_PERMISSION_FILE); dbg("opening %s to read as permissions config", udev_config_permission_filename);
dbg("opening %s to read as permissions config", filename); fd = fopen(udev_config_permission_filename, "r");
fd = fopen(filename, "r");
if (fd == NULL) { if (fd == NULL) {
dbg("Can't open %s", filename); dbg("Can't open %s", udev_config_permission_filename);
return -ENODEV; return -ENODEV;
} }

View File

@ -28,10 +28,7 @@
struct sysfs_class_device; struct sysfs_class_device;
/* namedev config files */
#define COMMENT_CHARACTER '#' #define COMMENT_CHARACTER '#'
#define NAMEDEV_CONFIG_PERMISSION_FILE "namedev.permissions"
#define NAMEDEV_CONFIG_FILE "namedev.config"
enum config_type { enum config_type {
KERNEL_NAME = 0, /* must be 0 to let memset() default to this value */ KERNEL_NAME = 0, /* must be 0 to let memset() default to this value */

View File

@ -34,8 +34,6 @@
#include "udevdb.h" #include "udevdb.h"
#include "libsysfs/libsysfs.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 * Right now the major/minor of a device is stored in a file called
* "dev" in sysfs. * "dev" in sysfs.
@ -75,7 +73,7 @@ static int create_node(struct udevice *dev)
char filename[255]; char filename[255];
int retval = 0; int retval = 0;
strncpy(filename, UDEV_ROOT, sizeof(filename)); strncpy(filename, udev_root, sizeof(filename));
strncat(filename, dev->name, sizeof(filename)); strncat(filename, dev->name, sizeof(filename));
switch (dev->type) { switch (dev->type) {
@ -171,13 +169,6 @@ int udev_add_device(char *path, char *subsystem)
else else
dev.type = 'c'; 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); retval = sleep_for_dev(path);
if (retval) if (retval)
goto exit; goto exit;

View File

@ -70,7 +70,7 @@ static int delete_node(char *name)
{ {
char filename[255]; char filename[255];
strncpy(filename, UDEV_ROOT, sizeof(filename)); strncpy(filename, udev_root, sizeof(filename));
strncat(filename, name, sizeof(filename)); strncat(filename, name, sizeof(filename));
dbg("unlinking %s", filename); dbg("unlinking %s", filename);

84
udev.c
View File

@ -34,8 +34,19 @@
#include "udevdb.h" #include "udevdb.h"
#include "libsysfs/libsysfs.h" #include "libsysfs/libsysfs.h"
/* global variables */
char **main_argv;
char **main_envp;
static char *get_action(void) 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 inline char *get_action(void)
{ {
char *action; char *action;
@ -43,22 +54,60 @@ static char *get_action(void)
return action; return action;
} }
static inline char *get_devpath(void)
static char *get_device(void)
{ {
char *device; char *devpath;
device = getenv("DEVPATH"); devpath = getenv("DEVPATH");
return device; return devpath;
} }
char **main_argv; static inline char *get_seqnum(void)
char **main_envp; {
char *seqnum;
seqnum = getenv("SEQNUM");
return seqnum;
}
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) int main(int argc, char **argv, char **envp)
{ {
char *action; char *action;
char *device; char *devpath;
char *subsystem; char *subsystem;
int retval = -EINVAL; int retval = -EINVAL;
@ -74,16 +123,16 @@ int main(int argc, char **argv, char **envp)
subsystem = argv[1]; subsystem = argv[1];
device = get_device(); devpath = get_devpath();
if (!device) { if (!devpath) {
dbg ("no device?"); dbg ("no devpath?");
goto exit; goto exit;
} }
dbg("looking at %s", device); dbg("looking at %s", devpath);
/* we only care about class devices and block stuff */ /* we only care about class devices and block stuff */
if (!strstr(device, "class") && if (!strstr(devpath, "class") &&
!strstr(device, "block")) { !strstr(devpath, "block")) {
dbg("not block or class"); dbg("not block or class");
goto exit; goto exit;
} }
@ -101,6 +150,7 @@ int main(int argc, char **argv, char **envp)
} }
/* initialize udev database */ /* initialize udev database */
get_dirs();
retval = udevdb_init(UDEVDB_DEFAULT); retval = udevdb_init(UDEVDB_DEFAULT);
if (retval != 0) { if (retval != 0) {
dbg("Unable to initialize database."); dbg("Unable to initialize database.");
@ -111,10 +161,10 @@ int main(int argc, char **argv, char **envp)
namedev_init(); namedev_init();
if (strcmp(action, "add") == 0) if (strcmp(action, "add") == 0)
retval = udev_add_device(device, argv[1]); retval = udev_add_device(devpath, subsystem);
else if (strcmp(action, "remove") == 0) else if (strcmp(action, "remove") == 0)
retval = udev_remove_device(device, argv[1]); retval = udev_remove_device(devpath, subsystem);
else { else {
dbg("Unknown action: %s", action); dbg("Unknown action: %s", action);

13
udev.h
View File

@ -24,6 +24,7 @@
#define UDEV_H #define UDEV_H
#include "libsysfs/libsysfs.h" #include "libsysfs/libsysfs.h"
#include <limits.h>
#ifdef DEBUG #ifdef DEBUG
#include <syslog.h> #include <syslog.h>
@ -50,7 +51,10 @@ extern int log_message (int level, const char *format, ...)
__attribute__ ((format (printf, 2, 3))); __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 NAME_SIZE 100
#define OWNER_SIZE 30 #define OWNER_SIZE 30
@ -78,5 +82,12 @@ extern int udev_remove_device(char *path, char *subsystem);
extern char **main_argv; extern char **main_argv;
extern char **main_envp; 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 #endif

View File

@ -124,12 +124,12 @@ int udevdb_init(int init_flag)
if (init_flag != UDEVDB_DEFAULT && init_flag != UDEVDB_INTERNAL) if (init_flag != UDEVDB_DEFAULT && init_flag != UDEVDB_INTERNAL)
return -EINVAL; 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 (udevdb == NULL) {
if (init_flag == UDEVDB_INTERNAL) if (init_flag == UDEVDB_INTERNAL)
dbg("Unable to initialize in-memory database"); dbg("Unable to initialize in-memory database");
else 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 -EINVAL;
} }
return 0; return 0;

View File

@ -4,8 +4,6 @@
#ifndef _UDEVDB_H_ #ifndef _UDEVDB_H_
#define _UDEVDB_H_ #define _UDEVDB_H_
#define UDEV_DB "udevdb.tdb"
/* Udevdb initialization flags */ /* Udevdb initialization flags */
#define UDEVDB_DEFAULT 0 /* Defaults database to use file */ #define UDEVDB_DEFAULT 0 /* Defaults database to use file */
#define UDEVDB_INTERNAL 1 /* Don't store db on disk, use in memory */ #define UDEVDB_INTERNAL 1 /* Don't store db on disk, use in memory */