#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) {
}
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:
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;
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);
}
}
}
-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;
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]);
}
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 {
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;
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;
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)
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);
}
#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, ...)
} 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"))) {
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];
}
/* 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);
/* 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);
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
#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];
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;
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;
/* get command line options */
while (1) {
- option = getopt(main_argc, main_argv, short_options);
+ option = getopt(argc, argv, short_options);
if (option == -1)
break;
{
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);
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);
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;
}
#include "logging.h"
#include "namedev.h"
-/* global variables */
-char **main_argv;
-char **main_envp;
-
#ifdef LOG
unsigned char logname[LOGNAME_SIZE];
char *subsystem = "";
struct udevice udev;
- main_argv = argv;
- main_envp = envp;
-
info("version %s", UDEV_VERSION);
if (argv[1] == NULL) {