free(udev_monitor);
return NULL;
}
+ util_set_fd_cloexec(udev_monitor->sock);
+
dbg(udev, "monitor %p created with '%s'\n", udev_monitor, socket_path);
return udev_monitor;
}
free(udev_monitor);
return NULL;
}
+ util_set_fd_cloexec(udev_monitor->sock);
udev_monitor->snl.nl_family = AF_NETLINK;
udev_monitor->snl.nl_groups = group;
extern int udev_util_replace_whitespace(const char *str, char *to, size_t len);
extern int udev_util_replace_chars(char *str, const char *white);
extern int udev_util_encode_string(const char *str, char *str_enc, size_t len);
+extern void util_set_fd_cloexec(int fd);
#endif
err:
return -1;
}
+
+void util_set_fd_cloexec(int fd)
+{
+ int flags;
+
+ flags = fcntl(fd, F_GETFD);
+ if (flags < 0)
+ flags = FD_CLOEXEC;
+ else
+ flags |= FD_CLOEXEC;
+ fcntl(fd, F_SETFD, flags);
+}
void udev_watch_init(struct udev *udev)
{
inotify_fd = inotify_init();
- if (inotify_fd >= 0) {
- int flags;
-
- flags = fcntl(inotify_fd, F_GETFD);
- if (flags < 0)
- flags = FD_CLOEXEC;
- else
- flags |= FD_CLOEXEC;
- fcntl(inotify_fd, F_SETFD, flags);
- } else if (errno == ENOSYS)
+ if (inotify_fd >= 0)
+ util_set_fd_cloexec(inotify_fd);
+ else if (errno == ENOSYS)
info(udev, "unable to use inotify, udevd will not monitor rule files changes\n");
else
err(udev, "inotify_init failed: %m\n");