]> err.no Git - systemd/commitdiff
test-udev: cleanup libudev context and overridden rules file string
authorKay Sievers <kay.sievers@vrfy.org>
Mon, 8 Sep 2008 22:08:42 +0000 (00:08 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Mon, 8 Sep 2008 22:08:42 +0000 (00:08 +0200)
udev/lib/libudev.c
udev/test-udev.c

index 5a00f44de91a11bb62e949257472dc53b659253a..09e1bec1bfb83e35fa8c4d24cfee796e206b5a81 100644 (file)
@@ -91,7 +91,6 @@ struct udev *udev_new(void)
        sysfs_init();
 
        /* defaults */
-       config_file = NULL;
        udev->refcount = 1;
        udev->log_fn = log_stderr;
        udev->log_priority = LOG_ERR;
@@ -100,7 +99,9 @@ struct udev *udev_new(void)
        udev->sys_path = strdup("/sys");
        config_file = strdup(SYSCONFDIR "/udev/udev.conf");
 
-       if (udev->dev_path == NULL || udev->sys_path == NULL)
+       if (udev->dev_path == NULL ||
+           udev->sys_path == NULL ||
+           config_file == NULL)
                goto err;
 
        /* settings by environment and config file */
@@ -205,7 +206,6 @@ struct udev *udev_new(void)
                }
                fclose(f);
        }
-       free(config_file);
 
        env = getenv("UDEV_ROOT");
        if (env != NULL) {
@@ -223,12 +223,16 @@ struct udev *udev_new(void)
 
        info(udev, "context %p created\n", udev);
        info(udev, "log_priority=%d\n", udev->log_priority);
+       info(udev, "config_file='%s'\n", config_file);
        info(udev, "dev_path='%s'\n", udev->dev_path);
+       info(udev, "sys_path='%s'\n", udev->sys_path);
        if (udev->rules_path != NULL)
                info(udev, "rules_path='%s'\n", udev->rules_path);
 
+       free(config_file);
        return udev;
 err:
+       free(config_file);
        err(udev, "context creation failed\n");
        udev_unref(udev);
        return NULL;
@@ -268,6 +272,7 @@ void udev_unref(struct udev *udev)
        sysfs_cleanup();
        free(udev->dev_path);
        free(udev->sys_path);
+       free(udev->rules_path);
        info(udev, "context %p released\n", udev);
        free(udev);
 }
index 4e782a0d613780fbe5f1aeb2a73572b94c1afe53..b05990ac073c94ef6fe2f9340c6413c7b9eff1a6 100644 (file)
@@ -66,21 +66,6 @@ int main(int argc, char *argv[])
        dbg(udev, "version %s\n", VERSION);
        selinux_init(udev);
 
-       /* 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);
-       } else {
-               err(udev, "open /dev/null failed: %s\n", strerror(errno));
-       }
-
        /* set signal handlers */
        memset(&act, 0x00, sizeof(act));
        act.sa_handler = (void (*)(int)) sig_handler;
@@ -152,8 +137,8 @@ fail:
        udev_rules_cleanup(&rules);
        sysfs_cleanup();
        selinux_exit(udev);
-
 exit:
+       udev_unref(udev);
        if (retval != 0)
                return 1;
        return 0;