X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev%2Ftest-udev.c;h=6c01bdbcd45249b49c9529da8c93661591eb592b;hp=591e93058a00a2ab5348de7663735e065a5bf8b6;hb=c4f5f942d7dd904e53374c10de319feb41968561;hpb=01618658fd82dbc5e6315b639f00e87c6fee3c54 diff --git a/udev/test-udev.c b/udev/test-udev.c index 591e93058..6c01bdbcd 100644 --- a/udev/test-udev.c +++ b/udev/test-udev.c @@ -29,25 +29,12 @@ #include #include #include +#include #include "udev.h" #include "udev_rules.h" #include "udev_selinux.h" -#ifdef USE_LOG -void log_message(int priority, const char *format, ...) -{ - va_list args; - - if (priority > udev_log_priority) - return; - - va_start(args, format); - vsyslog(priority, format, args); - va_end(args); -} -#endif - static void asmlinkage sig_handler(int signum) { switch (signum) { @@ -59,43 +46,24 @@ static void asmlinkage sig_handler(int signum) } } -int main(int argc, char *argv[], char *envp[]) +int main(int argc, char *argv[]) { + struct udev *udev; struct sysfs_device *dev; - struct udevice *udev; + struct udevice *udevice; const char *maj, *min; struct udev_rules rules; const char *action; const char *devpath; const char *subsystem; struct sigaction act; - int devnull; int retval = -EINVAL; - if (argc == 2 && strcmp(argv[1], "-V") == 0) { - printf("%s\n", VERSION); - exit(0); - } - - /* set std fd's to /dev/null, /sbin/hotplug forks us, we don't have them at all */ - devnull = open("/dev/null", O_RDWR); - if (devnull >= 0) { - if (devnull != STDIN_FILENO) - dup2(devnull, STDIN_FILENO); - if (devnull != STDOUT_FILENO) - dup2(devnull, STDOUT_FILENO); - if (devnull != STDERR_FILENO) - dup2(devnull, STDERR_FILENO); - if (devnull > STDERR_FILENO) - close(devnull); - } - - logging_init("udev"); - if (devnull < 0) - err("open /dev/null failed: %s\n", strerror(errno)); - udev_config_init(); - selinux_init(); - dbg("version %s\n", VERSION); + udev = udev_new(); + if (udev == NULL) + exit(1); + dbg(udev, "version %s\n", VERSION); + selinux_init(udev); /* set signal handlers */ memset(&act, 0x00, sizeof(act)); @@ -117,60 +85,59 @@ int main(int argc, char *argv[], char *envp[]) subsystem = argv[1]; if (action == NULL || subsystem == NULL || devpath == NULL) { - err("action, subsystem or devpath missing\n"); + err(udev, "action, subsystem or devpath missing\n"); goto exit; } /* export log_priority , as called programs may want to do the same as udev */ - if (udev_log_priority) { + if (udev_get_log_priority(udev) > 0) { char priority[32]; - sprintf(priority, "%i", udev_log_priority); + sprintf(priority, "%i", udev_get_log_priority(udev)); setenv("UDEV_LOG", priority, 1); } sysfs_init(); - udev_rules_init(&rules, 0); + udev_rules_init(udev, &rules, 0); - dev = sysfs_device_get(devpath); + dev = sysfs_device_get(udev, devpath); if (dev == NULL) { - info("unable to open '%s'\n", devpath); + info(udev, "unable to open '%s'\n", devpath); goto fail; } - udev = udev_device_init(NULL); - if (udev == NULL) + udevice = udev_device_init(udev); + if (udevice == NULL) goto fail; /* override built-in sysfs device */ - udev->dev = dev; - strlcpy(udev->action, action, sizeof(udev->action)); + udevice->dev = dev; + strlcpy(udevice->action, action, sizeof(udevice->action)); /* get dev_t from environment, which is needed for "remove" to work, "add" works also from sysfs */ maj = getenv("MAJOR"); min = getenv("MINOR"); if (maj != NULL && min != NULL) - udev->devt = makedev(atoi(maj), atoi(min)); + udevice->devt = makedev(atoi(maj), atoi(min)); else - udev->devt = udev_device_get_devt(udev); + udevice->devt = udev_device_get_devt(udevice); - retval = udev_device_event(&rules, udev); + retval = udev_device_event(&rules, udevice); /* rules may change/disable the timeout */ - if (udev->event_timeout >= 0) - alarm(udev->event_timeout); + if (udevice->event_timeout >= 0) + alarm(udevice->event_timeout); - if (retval == 0 && !udev->ignore_device && udev_run) - udev_rules_run(udev); + if (retval == 0 && !udevice->ignore_device && udev_get_run(udev)) + udev_rules_run(udevice); - udev_device_cleanup(udev); + udev_device_cleanup(udevice); fail: udev_rules_cleanup(&rules); sysfs_cleanup(); - selinux_exit(); - + selinux_exit(udev); exit: - logging_close(); + udev_unref(udev); if (retval != 0) return 1; return 0;