mirror of
https://github.com/systemd/systemd.git
synced 2025-03-08 08:58:27 +03:00
udev: make udev_builtin_run() take UdevEvent*
No functional change, preparation for later commits.
This commit is contained in:
parent
b3cfe59001
commit
5668f3a7cf
@ -315,7 +315,8 @@ notloop:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int builtin_blkid(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
static int builtin_blkid(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
const char *devnode, *root_partition = NULL, *data, *name;
|
||||
_cleanup_(blkid_free_probep) blkid_probe pr = NULL;
|
||||
_cleanup_free_ char *backing_fname = NULL;
|
||||
|
@ -12,7 +12,8 @@
|
||||
#include "strxcpyx.h"
|
||||
#include "udev-builtin.h"
|
||||
|
||||
static int builtin_btrfs(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
static int builtin_btrfs(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
struct btrfs_ioctl_vol_args args = {};
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
int r;
|
||||
|
@ -118,7 +118,7 @@ next:
|
||||
return r;
|
||||
}
|
||||
|
||||
static int builtin_hwdb(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
static int builtin_hwdb(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
static const struct option options[] = {
|
||||
{ "filter", required_argument, NULL, 'f' },
|
||||
{ "device", required_argument, NULL, 'd' },
|
||||
@ -131,6 +131,7 @@ static int builtin_hwdb(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[
|
||||
const char *subsystem = NULL;
|
||||
const char *prefix = NULL;
|
||||
_cleanup_(sd_device_unrefp) sd_device *srcdev = NULL;
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
int r;
|
||||
|
||||
if (!hwdb)
|
||||
|
@ -369,8 +369,8 @@ static bool test_key(sd_device *dev,
|
||||
return found;
|
||||
}
|
||||
|
||||
static int builtin_input_id(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
sd_device *pdev;
|
||||
static int builtin_input_id(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
sd_device *pdev, *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
unsigned long bitmask_ev[NBITS(EV_MAX)];
|
||||
unsigned long bitmask_abs[NBITS(ABS_MAX)];
|
||||
unsigned long bitmask_key[NBITS(KEY_MAX)];
|
||||
@ -380,8 +380,6 @@ static int builtin_input_id(sd_device *dev, sd_netlink **rtnl, int argc, char *a
|
||||
bool is_pointer;
|
||||
bool is_key;
|
||||
|
||||
assert(dev);
|
||||
|
||||
/* walk up the parental chain until we find the real input device; the
|
||||
* argument is very likely a subdevice of this, like eventN */
|
||||
for (pdev = dev; pdev; ) {
|
||||
|
@ -159,7 +159,8 @@ static int set_trackpoint_sensitivity(sd_device *dev, const char *value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int builtin_keyboard(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
static int builtin_keyboard(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
unsigned release[1024];
|
||||
unsigned release_count = 0;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
@ -22,11 +22,10 @@ _printf_(6,0) static void udev_kmod_log(void *data, int priority, const char *fi
|
||||
log_internalv(priority, 0, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
static int builtin_kmod(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
static int builtin_kmod(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
|
||||
if (!ctx)
|
||||
return 0;
|
||||
|
||||
|
@ -1096,7 +1096,8 @@ static int get_link_info(sd_device *dev, LinkInfo *info) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int builtin_net_id(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
const char *prefix;
|
||||
NetNames names = {};
|
||||
LinkInfo info = {};
|
||||
|
@ -12,7 +12,8 @@
|
||||
|
||||
static LinkConfigContext *ctx = NULL;
|
||||
|
||||
static int builtin_net_setup_link(sd_device *dev, sd_netlink **rtnl, int argc, char **argv, bool test) {
|
||||
static int builtin_net_setup_link(UdevEvent *event, int argc, char **argv, bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
_cleanup_(link_freep) Link *link = NULL;
|
||||
_cleanup_free_ char *joined = NULL;
|
||||
int r;
|
||||
@ -20,7 +21,7 @@ static int builtin_net_setup_link(sd_device *dev, sd_netlink **rtnl, int argc, c
|
||||
if (argc > 1)
|
||||
return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "This program takes no arguments.");
|
||||
|
||||
r = link_new(ctx, rtnl, dev, &link);
|
||||
r = link_new(ctx, &event->rtnl, dev, &link);
|
||||
if (r == -ENODEV) {
|
||||
log_device_debug_errno(dev, r, "Link vanished while getting information, ignoring.");
|
||||
return 0;
|
||||
@ -41,7 +42,7 @@ static int builtin_net_setup_link(sd_device *dev, sd_netlink **rtnl, int argc, c
|
||||
return log_device_error_errno(dev, r, "Failed to get link config: %m");
|
||||
}
|
||||
|
||||
r = link_apply_config(ctx, rtnl, link);
|
||||
r = link_apply_config(ctx, &event->rtnl, link);
|
||||
if (r == -ENODEV)
|
||||
log_device_debug_errno(dev, r, "Link vanished while applying configuration, ignoring.");
|
||||
else if (r < 0)
|
||||
|
@ -589,15 +589,14 @@ static int find_real_nvme_parent(sd_device *dev, sd_device **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int builtin_path_id(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
_cleanup_(sd_device_unrefp) sd_device *dev_other_branch = NULL;
|
||||
_cleanup_free_ char *path = NULL, *compat_path = NULL;
|
||||
bool supported_transport = false, supported_parent = false;
|
||||
const char *subsystem;
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
|
||||
/* walk up the chain of devices and compose path */
|
||||
for (sd_device *parent = dev; parent; ) {
|
||||
const char *subsys, *sysname;
|
||||
|
@ -16,7 +16,8 @@
|
||||
#include "log.h"
|
||||
#include "udev-builtin.h"
|
||||
|
||||
static int builtin_uaccess(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
static int builtin_uaccess(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
const char *path = NULL, *seat;
|
||||
bool changed_acl = false;
|
||||
uid_t uid;
|
||||
|
@ -224,7 +224,8 @@ static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
|
||||
* 6.) If the device supplies a serial number, this number
|
||||
* is concatenated with the identification with an underscore '_'.
|
||||
*/
|
||||
static int builtin_usb_id(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
|
||||
static int builtin_usb_id(UdevEvent *event, int argc, char *argv[], bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
char vendor_str[64] = "";
|
||||
char vendor_str_enc[256];
|
||||
const char *vendor_id;
|
||||
@ -250,8 +251,6 @@ static int builtin_usb_id(sd_device *dev, sd_netlink **rtnl, int argc, char *arg
|
||||
const char *syspath, *sysname, *devtype, *interface_syspath;
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
|
||||
r = sd_device_get_syspath(dev, &syspath);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -98,11 +98,12 @@ UdevBuiltinCommand udev_builtin_lookup(const char *command) {
|
||||
return _UDEV_BUILTIN_INVALID;
|
||||
}
|
||||
|
||||
int udev_builtin_run(sd_device *dev, sd_netlink **rtnl, UdevBuiltinCommand cmd, const char *command, bool test) {
|
||||
int udev_builtin_run(UdevEvent *event, UdevBuiltinCommand cmd, const char *command, bool test) {
|
||||
_cleanup_strv_free_ char **argv = NULL;
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
assert(event);
|
||||
assert(event->dev);
|
||||
assert(cmd >= 0 && cmd < _UDEV_BUILTIN_MAX);
|
||||
assert(command);
|
||||
|
||||
@ -115,7 +116,7 @@ int udev_builtin_run(sd_device *dev, sd_netlink **rtnl, UdevBuiltinCommand cmd,
|
||||
|
||||
/* we need '0' here to reset the internal state */
|
||||
optind = 0;
|
||||
return builtins[cmd]->cmd(dev, rtnl, strv_length(argv), argv, test);
|
||||
return builtins[cmd]->cmd(event, strv_length(argv), argv, test);
|
||||
}
|
||||
|
||||
int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "sd-netlink.h"
|
||||
|
||||
#include "macro.h"
|
||||
#include "udev-event.h"
|
||||
|
||||
typedef enum UdevBuiltinCommand {
|
||||
#if HAVE_BLKID
|
||||
@ -32,7 +33,7 @@ typedef enum UdevBuiltinCommand {
|
||||
|
||||
typedef struct UdevBuiltin {
|
||||
const char *name;
|
||||
int (*cmd)(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test);
|
||||
int (*cmd)(UdevEvent *event, int argc, char *argv[], bool test);
|
||||
const char *help;
|
||||
int (*init)(void);
|
||||
void (*exit)(void);
|
||||
@ -76,7 +77,7 @@ void udev_builtin_exit(void);
|
||||
UdevBuiltinCommand udev_builtin_lookup(const char *command);
|
||||
const char *udev_builtin_name(UdevBuiltinCommand cmd);
|
||||
bool udev_builtin_run_once(UdevBuiltinCommand cmd);
|
||||
int udev_builtin_run(sd_device *dev, sd_netlink **rtnl, UdevBuiltinCommand cmd, const char *command, bool test);
|
||||
int udev_builtin_run(UdevEvent *event, UdevBuiltinCommand cmd, const char *command, bool test);
|
||||
void udev_builtin_list(void);
|
||||
bool udev_builtin_should_reload(void);
|
||||
int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val);
|
||||
|
@ -1185,7 +1185,7 @@ void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec, int timeout_s
|
||||
|
||||
if (builtin_cmd != _UDEV_BUILTIN_INVALID) {
|
||||
log_device_debug(event->dev, "Running built-in command \"%s\"", command);
|
||||
r = udev_builtin_run(event->dev, &event->rtnl, builtin_cmd, command, false);
|
||||
r = udev_builtin_run(event, builtin_cmd, command, false);
|
||||
if (r < 0)
|
||||
log_device_debug_errno(event->dev, r, "Failed to run built-in command \"%s\", ignoring: %m", command);
|
||||
} else {
|
||||
|
@ -2193,7 +2193,7 @@ static int udev_rule_apply_token_to_event(
|
||||
|
||||
log_event_debug(dev, token, "Importing properties from results of builtin command '%s'", buf);
|
||||
|
||||
r = udev_builtin_run(dev, &event->rtnl, cmd, buf, false);
|
||||
r = udev_builtin_run(event, cmd, buf, false);
|
||||
if (r < 0) {
|
||||
/* remember failure */
|
||||
log_event_debug_errno(dev, token, r, "Failed to run builtin '%s': %m", buf);
|
||||
|
@ -72,7 +72,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
int builtin_main(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
|
||||
_cleanup_(udev_event_freep) UdevEvent *event = NULL;
|
||||
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
|
||||
UdevBuiltinCommand cmd;
|
||||
int r;
|
||||
@ -97,7 +97,13 @@ int builtin_main(int argc, char *argv[], void *userdata) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
r = udev_builtin_run(dev, &rtnl, cmd, arg_command, true);
|
||||
event = udev_event_new(dev, 0, NULL, LOG_DEBUG);
|
||||
if (!event) {
|
||||
r = log_oom();
|
||||
goto finish;
|
||||
}
|
||||
|
||||
r = udev_builtin_run(event, cmd, arg_command, true);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Builtin command '%s' fails: %m", arg_command);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user