#include "udev.h"
#include "sd-daemon.h"
#include "cgroup-util.h"
+#include "dev-setup.h"
static bool debug;
int ifindex;
};
-static struct event *node_to_event(struct udev_list_node *node)
+static inline struct event *node_to_event(struct udev_list_node *node)
{
- char *event;
-
- event = (char *)node;
- event -= offsetof(struct event, node);
- return (struct event *)event;
+ return container_of(node, struct event, node);
}
static void event_queue_cleanup(struct udev *udev, enum event_state type);
int exitcode;
};
-static struct worker *node_to_worker(struct udev_list_node *node)
+static inline struct worker *node_to_worker(struct udev_list_node *node)
{
- char *worker;
-
- worker = (char *)node;
- worker -= offsetof(struct worker, node);
- return (struct worker *)worker;
+ return container_of(node, struct worker, node);
}
static void event_queue_delete(struct event *event, bool export)
fclose(f);
}
-/* needed for standalone udev operations */
-static void static_dev_create_links(struct udev *udev)
-{
- struct stdlinks {
- const char *link;
- const char *target;
- };
- static const struct stdlinks stdlinks[] = {
- { "/dev/core", "/proc/kcore" },
- { "/dev/fd", "/proc/self/fd" },
- { "/dev/stdin", "/proc/self/fd/0" },
- { "/dev/stdout", "/proc/self/fd/1" },
- { "/dev/stderr", "/proc/self/fd/2" },
- };
- unsigned int i;
-
- for (i = 0; i < ELEMENTSOF(stdlinks); i++) {
- struct stat sb;
-
- if (stat(stdlinks[i].target, &sb) == 0) {
- label_context_set(stdlinks[i].link, S_IFLNK);
- if (symlink(stdlinks[i].target, stdlinks[i].link) < 0 && errno == EEXIST)
- utimensat(AT_FDCWD, stdlinks[i].link, NULL, AT_SYMLINK_NOFOLLOW);
- label_context_clear();
- }
- }
-}
-
static int mem_size_mb(void)
{
FILE *f;
mkdir("/run/udev", 0755);
- /* create standard links, copy static nodes, create nodes from modules */
- static_dev_create_links(udev);
+ dev_setup();
static_dev_create_from_modules(udev);
/* before opening new files, make sure std{in,out,err} fds are in a sane state */
setsid();
- fd = open("/proc/self/oom_score_adj", O_RDWR);
- if (fd < 0) {
- /* Fallback to old interface */
- fd = open("/proc/self/oom_adj", O_RDWR);
- if (fd < 0) {
- log_error("error disabling OOM: %m\n");
- } else {
- /* OOM_DISABLE == -17 */
- write(fd, "-17", 3);
- close(fd);
- }
- } else {
+ fd = open("/proc/self/oom_score_adj", O_RDWR|O_CLOEXEC);
+ if (fd >= 0) {
write(fd, "-1000", 5);
close(fd);
}