mirror of
https://github.com/systemd/systemd.git
synced 2025-03-08 08:58:27 +03:00
udev: move several definitions (#35613)
This commit is contained in:
commit
c5f95bc19b
@ -25,6 +25,7 @@
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "udev-event.h"
|
||||
#include "udev-rules.h"
|
||||
#include "udev-spawn.h"
|
||||
#include "version.h"
|
||||
|
||||
|
@ -7,31 +7,9 @@
|
||||
#include "sd-netlink.h"
|
||||
|
||||
#include "macro.h"
|
||||
#include "udev-def.h"
|
||||
#include "udev-event.h"
|
||||
|
||||
typedef enum UdevBuiltinCommand {
|
||||
#if HAVE_BLKID
|
||||
UDEV_BUILTIN_BLKID,
|
||||
#endif
|
||||
UDEV_BUILTIN_BTRFS,
|
||||
UDEV_BUILTIN_HWDB,
|
||||
UDEV_BUILTIN_INPUT_ID,
|
||||
UDEV_BUILTIN_KEYBOARD,
|
||||
#if HAVE_KMOD
|
||||
UDEV_BUILTIN_KMOD,
|
||||
#endif
|
||||
UDEV_BUILTIN_NET_DRIVER,
|
||||
UDEV_BUILTIN_NET_ID,
|
||||
UDEV_BUILTIN_NET_LINK,
|
||||
UDEV_BUILTIN_PATH_ID,
|
||||
UDEV_BUILTIN_USB_ID,
|
||||
#if HAVE_ACL
|
||||
UDEV_BUILTIN_UACCESS,
|
||||
#endif
|
||||
_UDEV_BUILTIN_MAX,
|
||||
_UDEV_BUILTIN_INVALID = -EINVAL,
|
||||
} UdevBuiltinCommand;
|
||||
|
||||
typedef struct UdevBuiltin {
|
||||
const char *name;
|
||||
int (*cmd)(UdevEvent *event, int argc, char *argv[]);
|
||||
|
57
src/udev/udev-def.h
Normal file
57
src/udev/udev-def.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#define UDEV_NAME_SIZE 512
|
||||
#define UDEV_PATH_SIZE 1024
|
||||
#define UDEV_LINE_SIZE 16384
|
||||
|
||||
typedef enum EventMode {
|
||||
EVENT_UDEV_WORKER,
|
||||
EVENT_UDEVADM_TEST,
|
||||
EVENT_UDEVADM_TEST_BUILTIN,
|
||||
EVENT_TEST_RULE_RUNNER,
|
||||
EVENT_TEST_SPAWN,
|
||||
_EVENT_MODE_MAX,
|
||||
_EVENT_MODE_INVALID = -EINVAL,
|
||||
} EventMode;
|
||||
|
||||
typedef enum UdevRuleEscapeType {
|
||||
ESCAPE_UNSET,
|
||||
ESCAPE_NONE, /* OPTIONS="string_escape=none" */
|
||||
ESCAPE_REPLACE, /* OPTIONS="string_escape=replace" */
|
||||
_ESCAPE_TYPE_MAX,
|
||||
_ESCAPE_TYPE_INVALID = -EINVAL,
|
||||
} UdevRuleEscapeType;
|
||||
|
||||
typedef enum ResolveNameTiming {
|
||||
RESOLVE_NAME_NEVER,
|
||||
RESOLVE_NAME_LATE,
|
||||
RESOLVE_NAME_EARLY,
|
||||
_RESOLVE_NAME_TIMING_MAX,
|
||||
_RESOLVE_NAME_TIMING_INVALID = -EINVAL,
|
||||
} ResolveNameTiming;
|
||||
|
||||
typedef enum UdevBuiltinCommand {
|
||||
#if HAVE_BLKID
|
||||
UDEV_BUILTIN_BLKID,
|
||||
#endif
|
||||
UDEV_BUILTIN_BTRFS,
|
||||
UDEV_BUILTIN_HWDB,
|
||||
UDEV_BUILTIN_INPUT_ID,
|
||||
UDEV_BUILTIN_KEYBOARD,
|
||||
#if HAVE_KMOD
|
||||
UDEV_BUILTIN_KMOD,
|
||||
#endif
|
||||
UDEV_BUILTIN_NET_DRIVER,
|
||||
UDEV_BUILTIN_NET_ID,
|
||||
UDEV_BUILTIN_NET_LINK,
|
||||
UDEV_BUILTIN_PATH_ID,
|
||||
UDEV_BUILTIN_USB_ID,
|
||||
#if HAVE_ACL
|
||||
UDEV_BUILTIN_UACCESS,
|
||||
#endif
|
||||
_UDEV_BUILTIN_MAX,
|
||||
_UDEV_BUILTIN_INVALID = -EINVAL,
|
||||
} UdevBuiltinCommand;
|
@ -12,8 +12,10 @@
|
||||
#include "strv.h"
|
||||
#include "udev-event.h"
|
||||
#include "udev-node.h"
|
||||
#include "udev-rules.h"
|
||||
#include "udev-trace.h"
|
||||
#include "udev-util.h"
|
||||
#include "udev-worker.h"
|
||||
#include "user-util.h"
|
||||
|
||||
UdevEvent* udev_event_new(sd_device *dev, UdevWorker *worker, EventMode mode) {
|
||||
|
@ -14,17 +14,11 @@
|
||||
#include "hashmap.h"
|
||||
#include "macro.h"
|
||||
#include "time-util.h"
|
||||
#include "udev-rules.h"
|
||||
#include "udev-worker.h"
|
||||
#include "udev-def.h"
|
||||
#include "user-util.h"
|
||||
|
||||
typedef enum EventMode {
|
||||
EVENT_UDEV_WORKER,
|
||||
EVENT_UDEVADM_TEST,
|
||||
EVENT_UDEVADM_TEST_BUILTIN,
|
||||
EVENT_TEST_RULE_RUNNER,
|
||||
EVENT_TEST_SPAWN,
|
||||
} EventMode;
|
||||
typedef struct UdevRules UdevRules;
|
||||
typedef struct UdevWorker UdevWorker;
|
||||
|
||||
typedef struct UdevEvent {
|
||||
UdevWorker *worker;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "udev-event.h"
|
||||
#include "udev-format.h"
|
||||
#include "udev-util.h"
|
||||
#include "udev-worker.h"
|
||||
|
||||
typedef enum {
|
||||
FORMAT_SUBST_DEVNODE,
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "udev-event.h"
|
||||
#include "udev-manager.h"
|
||||
#include "udev-node.h"
|
||||
#include "udev-rules.h"
|
||||
#include "udev-spawn.h"
|
||||
#include "udev-trace.h"
|
||||
#include "udev-util.h"
|
||||
@ -1227,15 +1228,69 @@ void manager_adjust_arguments(Manager *manager) {
|
||||
}
|
||||
}
|
||||
|
||||
int manager_init(Manager *manager, int fd_ctrl, int fd_uevent) {
|
||||
static int listen_fds(int *ret_ctrl, int *ret_netlink) {
|
||||
_cleanup_strv_free_ char **names = NULL;
|
||||
_cleanup_close_ int ctrl_fd = -EBADF, netlink_fd = -EBADF;
|
||||
|
||||
assert(ret_ctrl);
|
||||
assert(ret_netlink);
|
||||
|
||||
int n = sd_listen_fds_with_names(/* unset_environment = */ true, &names);
|
||||
if (n < 0)
|
||||
return n;
|
||||
|
||||
if (strv_length(names) != (size_t) n)
|
||||
return -EIO;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
int fd = SD_LISTEN_FDS_START + i;
|
||||
|
||||
if (sd_is_socket(fd, AF_UNIX, SOCK_SEQPACKET, -1) > 0) {
|
||||
if (ctrl_fd >= 0) {
|
||||
log_debug("Received multiple seqpacket socket (%s), ignoring.", names[i]);
|
||||
goto unused;
|
||||
}
|
||||
|
||||
ctrl_fd = fd;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sd_is_socket(fd, AF_NETLINK, SOCK_RAW, -1) > 0) {
|
||||
if (netlink_fd >= 0) {
|
||||
log_debug("Received multiple netlink socket (%s), ignoring.", names[i]);
|
||||
goto unused;
|
||||
}
|
||||
|
||||
netlink_fd = fd;
|
||||
continue;
|
||||
}
|
||||
|
||||
log_debug("Received unexpected fd (%s), ignoring.", names[i]);
|
||||
|
||||
unused:
|
||||
close_and_notify_warn(fd, names[i]);
|
||||
}
|
||||
|
||||
*ret_ctrl = TAKE_FD(ctrl_fd);
|
||||
*ret_netlink = TAKE_FD(netlink_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int manager_init(Manager *manager) {
|
||||
_cleanup_close_ int fd_ctrl = -EBADF, fd_uevent = -EBADF;
|
||||
_cleanup_free_ char *cgroup = NULL;
|
||||
int r;
|
||||
|
||||
assert(manager);
|
||||
|
||||
r = listen_fds(&fd_ctrl, &fd_uevent);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to listen on fds: %m");
|
||||
|
||||
r = udev_ctrl_new_from_fd(&manager->ctrl, fd_ctrl);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to initialize udev control socket: %m");
|
||||
TAKE_FD(fd_ctrl);
|
||||
|
||||
r = udev_ctrl_enable_receiving(manager->ctrl);
|
||||
if (r < 0)
|
||||
@ -1244,6 +1299,7 @@ int manager_init(Manager *manager, int fd_ctrl, int fd_uevent) {
|
||||
r = device_monitor_new_full(&manager->monitor, MONITOR_GROUP_KERNEL, fd_uevent);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to initialize device monitor: %m");
|
||||
TAKE_FD(fd_uevent);
|
||||
|
||||
(void) sd_device_monitor_set_description(manager->monitor, "manager");
|
||||
|
||||
|
@ -10,9 +10,10 @@
|
||||
#include "macro.h"
|
||||
#include "time-util.h"
|
||||
#include "udev-ctrl.h"
|
||||
#include "udev-rules.h"
|
||||
#include "udev-def.h"
|
||||
|
||||
typedef struct Event Event;
|
||||
typedef struct UdevRules UdevRules;
|
||||
typedef struct Worker Worker;
|
||||
|
||||
typedef struct Manager {
|
||||
@ -53,7 +54,7 @@ Manager* manager_free(Manager *manager);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
|
||||
|
||||
void manager_adjust_arguments(Manager *manager);
|
||||
int manager_init(Manager *manager, int fd_ctrl, int fd_uevent);
|
||||
int manager_init(Manager *manager);
|
||||
int manager_main(Manager *manager);
|
||||
|
||||
bool devpath_conflict(const char *a, const char *b);
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "udev-spawn.h"
|
||||
#include "udev-trace.h"
|
||||
#include "udev-util.h"
|
||||
#include "udev-worker.h"
|
||||
#include "user-util.h"
|
||||
#include "virt.h"
|
||||
|
||||
|
@ -4,31 +4,12 @@
|
||||
#include "alloc-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "time-util.h"
|
||||
|
||||
#define UDEV_NAME_SIZE 512
|
||||
#define UDEV_PATH_SIZE 1024
|
||||
#define UDEV_LINE_SIZE 16384
|
||||
#include "udev-def.h"
|
||||
|
||||
typedef struct UdevRuleFile UdevRuleFile;
|
||||
typedef struct UdevRules UdevRules;
|
||||
typedef struct UdevEvent UdevEvent;
|
||||
|
||||
typedef enum {
|
||||
ESCAPE_UNSET,
|
||||
ESCAPE_NONE, /* OPTIONS="string_escape=none" */
|
||||
ESCAPE_REPLACE, /* OPTIONS="string_escape=replace" */
|
||||
_ESCAPE_TYPE_MAX,
|
||||
_ESCAPE_TYPE_INVALID = -EINVAL,
|
||||
} UdevRuleEscapeType;
|
||||
|
||||
typedef enum ResolveNameTiming {
|
||||
RESOLVE_NAME_NEVER,
|
||||
RESOLVE_NAME_LATE,
|
||||
RESOLVE_NAME_EARLY,
|
||||
_RESOLVE_NAME_TIMING_MAX,
|
||||
_RESOLVE_NAME_TIMING_INVALID = -EINVAL,
|
||||
} ResolveNameTiming;
|
||||
|
||||
int udev_rule_parse_value(char *str, char **ret_value, char **ret_endpos, bool *ret_is_case_insensitive);
|
||||
int udev_rules_parse_file(UdevRules *rules, const char *filename, bool extra_checks, UdevRuleFile **ret);
|
||||
unsigned udev_rule_file_get_issues(UdevRuleFile *rule_file);
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "udev-event.h"
|
||||
#include "udev-spawn.h"
|
||||
#include "udev-trace.h"
|
||||
#include "udev-worker.h"
|
||||
|
||||
typedef struct Spawn {
|
||||
sd_device *device;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "signal-util.h"
|
||||
#include "string-util.h"
|
||||
#include "udev-event.h"
|
||||
#include "udev-rules.h"
|
||||
#include "udev-spawn.h"
|
||||
#include "udev-trace.h"
|
||||
#include "udev-util.h"
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "udev-builtin.h"
|
||||
#include "udev-event.h"
|
||||
#include "udev-format.h"
|
||||
#include "udev-rules.h"
|
||||
#include "udevadm-util.h"
|
||||
#include "udevadm.h"
|
||||
#include "user-util.h"
|
||||
|
@ -8,8 +8,6 @@
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "env-file.h"
|
||||
#include "errno-util.h"
|
||||
@ -24,6 +22,7 @@
|
||||
#include "signal-util.h"
|
||||
#include "syslog-util.h"
|
||||
#include "udev-manager.h"
|
||||
#include "udev-rules.h"
|
||||
#include "udev-util.h"
|
||||
#include "udevd.h"
|
||||
#include "version.h"
|
||||
@ -31,40 +30,6 @@
|
||||
static bool arg_debug = false;
|
||||
static int arg_daemonize = false;
|
||||
|
||||
static int listen_fds(int *ret_ctrl, int *ret_netlink) {
|
||||
int ctrl_fd = -EBADF, netlink_fd = -EBADF;
|
||||
|
||||
assert(ret_ctrl);
|
||||
assert(ret_netlink);
|
||||
|
||||
int n = sd_listen_fds(true);
|
||||
if (n < 0)
|
||||
return n;
|
||||
|
||||
for (int fd = SD_LISTEN_FDS_START; fd < n + SD_LISTEN_FDS_START; fd++) {
|
||||
if (sd_is_socket(fd, AF_UNIX, SOCK_SEQPACKET, -1) > 0) {
|
||||
if (ctrl_fd >= 0)
|
||||
return -EINVAL;
|
||||
ctrl_fd = fd;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sd_is_socket(fd, AF_NETLINK, SOCK_RAW, -1) > 0) {
|
||||
if (netlink_fd >= 0)
|
||||
return -EINVAL;
|
||||
netlink_fd = fd;
|
||||
continue;
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*ret_ctrl = ctrl_fd;
|
||||
*ret_netlink = netlink_fd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static DEFINE_CONFIG_PARSE_ENUM(config_parse_resolve_name_timing, resolve_name_timing, ResolveNameTiming);
|
||||
|
||||
static int manager_parse_udev_config(Manager *manager) {
|
||||
@ -286,7 +251,6 @@ static int parse_argv(int argc, char *argv[], Manager *manager) {
|
||||
|
||||
int run_udevd(int argc, char *argv[]) {
|
||||
_cleanup_(manager_freep) Manager *manager = NULL;
|
||||
int fd_ctrl = -EBADF, fd_uevent = -EBADF;
|
||||
int r;
|
||||
|
||||
log_setup();
|
||||
@ -330,13 +294,9 @@ int run_udevd(int argc, char *argv[]) {
|
||||
if (r < 0 && r != -EEXIST)
|
||||
return log_error_errno(r, "Failed to create /run/udev: %m");
|
||||
|
||||
r = listen_fds(&fd_ctrl, &fd_uevent);
|
||||
r = manager_init(manager);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to listen on fds: %m");
|
||||
|
||||
r = manager_init(manager, fd_ctrl, fd_uevent);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create manager: %m");
|
||||
return r;
|
||||
|
||||
if (arg_daemonize) {
|
||||
pid_t pid;
|
||||
|
Loading…
x
Reference in New Issue
Block a user