diff --git a/udev_monitor.c b/udev_monitor.c index 5f7cb91..0b44766 100644 --- a/udev_monitor.c +++ b/udev_monitor.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -210,6 +211,7 @@ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char { struct udev_monitor *udev_monitor; struct epoll_event epoll; + struct stat st; if (!udev || !name) { return NULL; @@ -221,6 +223,22 @@ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char return NULL; } + if (lstat(UDEV_MONITOR_DIR, &st) != 0) { + if (mkdir(UDEV_MONITOR_DIR, 0) == -1) { + free(udev_monitor); + return NULL; + } + + if (chmod(UDEV_MONITOR_DIR, 0777) == -1) { + free(udev_monitor); + return NULL; + } + } + else if (!S_ISDIR(st.st_mode)) { + free(udev_monitor); + return NULL; + } + udev_monitor->ifd = inotify_init1(IN_CLOEXEC | IN_NONBLOCK); if (udev_monitor->ifd == -1) {