X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev.c;h=17eade221ec867a8420c56bc77f6b28c9c5f8a44;hp=094905ecc2025a90288c9eb5e0fb901bc0b951e3;hb=3fd52a7694d94b57fc5a0dc380673a78683118fe;hpb=49d72e43487164194263d2c80dd27a4627f2169c diff --git a/udev.c b/udev.c index 094905ecc..17eade221 100644 --- a/udev.c +++ b/udev.c @@ -27,9 +27,12 @@ #include #include #include +#include +#include #include "udev.h" #include "udev_version.h" +#include "udev_dbus.h" #include "namedev.h" #include "udevdb.h" #include "libsysfs/libsysfs.h" @@ -38,13 +41,21 @@ char **main_argv; char **main_envp; -char sysfs_path[SYSFS_PATH_MAX]; -char *udev_config_dir = UDEV_CONFIG_DIR; -char *udev_root = 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 void sig_handler(int signum) +{ + dbg("caught signal %d", signum); + switch (signum) { + case SIGINT: + case SIGTERM: + case SIGKILL: + sysbus_disconnect(); + udevdb_exit(); + exit(20 + signum); + break; + default: + dbg("unhandled signal"); + } +} static inline char *get_action(void) { @@ -70,60 +81,13 @@ static inline char *get_seqnum(void) return seqnum; } -static void get_dirs(void) -{ - char *temp; - char *udev_db = UDEV_DB; - char *udev_config = UDEV_CONFIG_FILE; - char *udev_permission = UDEV_CONFIG_PERMISSION_FILE; - int retval; - - retval = sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX); - if (retval) - dbg("sysfs_get_mnt_path failed"); - - /* see if we should try to override any of the default values */ - temp = getenv("UDEV_TEST"); - if (temp != NULL) { - /* hm testing is happening, use the specified values, if they are present */ - temp = getenv("SYSFS_PATH"); - if (temp) - strncpy(sysfs_path, temp, sizeof(sysfs_path)); - temp = getenv("UDEV_CONFIG_DIR"); - if (temp) - udev_config_dir = temp; - temp = getenv("UDEV_ROOT"); - if (temp) - udev_root = temp; - temp = getenv("UDEV_DB"); - if (temp) - udev_db = temp; - temp = getenv("UDEV_CONFIG_FILE"); - if (temp) - udev_config = temp; - temp = getenv("UDEV_PERMISSION_FILE"); - if (temp) - udev_permission = temp; - } - dbg("sysfs_path='%s'", sysfs_path); - - strncpy(udev_db_filename, udev_root, 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, udev_config, sizeof(udev_config_filename)); - - strncpy(udev_config_permission_filename, udev_config_dir, sizeof(udev_config_permission_filename)); - strncat(udev_config_permission_filename, udev_permission, sizeof(udev_config_permission_filename)); -} - int main(int argc, char **argv, char **envp) { char *action; char *devpath; char *subsystem; int retval = -EINVAL; - + main_argv = argv; main_envp = envp; @@ -162,14 +126,24 @@ int main(int argc, char **argv, char **envp) goto exit; } + /* initialize our configuration */ + udev_init_config(); + + /* connect to the system message bus */ + sysbus_connect(); + /* initialize udev database */ - get_dirs(); retval = udevdb_init(UDEVDB_DEFAULT); if (retval != 0) { dbg("unable to initialize database"); - goto exit; + goto exit_sysbus; } + /* set up a default signal handler for now */ + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); + signal(SIGKILL, sig_handler); + /* initialize the naming deamon */ namedev_init(); @@ -185,6 +159,10 @@ int main(int argc, char **argv, char **envp) } udevdb_exit(); -exit: +exit_sysbus: + /* disconnect from the system message bus */ + sysbus_disconnect(); + +exit: return retval; }