mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
udev-event: make udev_event_new() take sd_device instead of udev_device
This commit is contained in:
parent
cf697ec00e
commit
cf28ad4689
@ -12,6 +12,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fs-util.h"
|
||||
#include "libudev-device-internal.h"
|
||||
#include "log.h"
|
||||
#include "missing.h"
|
||||
#include "selinux-util.h"
|
||||
@ -82,7 +83,7 @@ int main(int argc, char *argv[]) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
assert_se(event = udev_event_new(dev, 0, NULL));
|
||||
assert_se(event = udev_event_new(dev->device, 0, NULL));
|
||||
|
||||
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, SIGHUP, SIGCHLD, -1) >= 0);
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "device-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "format-util.h"
|
||||
#include "libudev-device-internal.h"
|
||||
#include "libudev-private.h"
|
||||
#include "netlink-util.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
@ -42,7 +42,7 @@ typedef struct Spawn {
|
||||
size_t result_len;
|
||||
} Spawn;
|
||||
|
||||
struct udev_event *udev_event_new(struct udev_device *dev, int exec_delay, sd_netlink *rtnl) {
|
||||
struct udev_event *udev_event_new(sd_device *dev, int exec_delay, sd_netlink *rtnl) {
|
||||
struct udev_event *event;
|
||||
|
||||
assert(dev);
|
||||
@ -52,7 +52,7 @@ struct udev_event *udev_event_new(struct udev_device *dev, int exec_delay, sd_ne
|
||||
return NULL;
|
||||
|
||||
*event = (struct udev_event) {
|
||||
.dev = dev,
|
||||
.dev = sd_device_ref(dev),
|
||||
.birth_usec = now(CLOCK_MONOTONIC),
|
||||
.exec_delay = exec_delay,
|
||||
.rtnl = sd_netlink_ref(rtnl),
|
||||
@ -67,7 +67,7 @@ struct udev_event *udev_event_free(struct udev_event *event) {
|
||||
if (!event)
|
||||
return NULL;
|
||||
|
||||
udev_device_unref(event->dev);
|
||||
sd_device_unref(event->dev);
|
||||
sd_device_unref(event->dev_db_clone);
|
||||
sd_netlink_unref(event->rtnl);
|
||||
while ((p = hashmap_steal_first_key(event->run_list)))
|
||||
@ -129,7 +129,7 @@ static const struct subst_map_entry map[] = {
|
||||
static ssize_t subst_format_var(struct udev_event *event,
|
||||
const struct subst_map_entry *entry, char *attr,
|
||||
char *dest, size_t l) {
|
||||
sd_device *parent, *dev = event->dev->device;
|
||||
sd_device *parent, *dev = event->dev;
|
||||
const char *val = NULL;
|
||||
char *s = dest;
|
||||
dev_t devnum;
|
||||
@ -406,9 +406,9 @@ subst:
|
||||
subst_len = subst_format_var(event, entry, attr, s, l);
|
||||
if (subst_len < 0) {
|
||||
if (format_dollar)
|
||||
log_device_warning_errno(event->dev->device, subst_len, "Failed to substitute variable '$%s', ignoring: %m", entry->name);
|
||||
log_device_warning_errno(event->dev, subst_len, "Failed to substitute variable '$%s', ignoring: %m", entry->name);
|
||||
else
|
||||
log_device_warning_errno(event->dev->device, subst_len, "Failed to apply format '%%%c', ignoring: %m", entry->fmt);
|
||||
log_device_warning_errno(event->dev, subst_len, "Failed to apply format '%%%c', ignoring: %m", entry->fmt);
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -640,9 +640,9 @@ int udev_event_spawn(struct udev_event *event,
|
||||
free_and_replace(argv[0], program);
|
||||
}
|
||||
|
||||
r = device_get_properties_strv(event->dev->device, &envp);
|
||||
r = device_get_properties_strv(event->dev, &envp);
|
||||
if (r < 0)
|
||||
return log_device_error_errno(event->dev->device, r, "Failed to get device properties");
|
||||
return log_device_error_errno(event->dev, r, "Failed to get device properties");
|
||||
|
||||
log_debug("Starting '%s'", cmd);
|
||||
|
||||
@ -686,7 +686,7 @@ int udev_event_spawn(struct udev_event *event,
|
||||
}
|
||||
|
||||
static int rename_netif(struct udev_event *event) {
|
||||
sd_device *dev = event->dev->device;
|
||||
sd_device *dev = event->dev;
|
||||
const char *action, *oldname;
|
||||
char name[IFNAMSIZ];
|
||||
int ifindex, r;
|
||||
@ -729,7 +729,7 @@ static int rename_netif(struct udev_event *event) {
|
||||
}
|
||||
|
||||
static int update_devnode(struct udev_event *event) {
|
||||
sd_device *dev = event->dev->device;
|
||||
sd_device *dev = event->dev;
|
||||
const char *action;
|
||||
bool apply;
|
||||
int r;
|
||||
@ -784,7 +784,7 @@ static void event_execute_rules_on_remove(
|
||||
Hashmap *properties_list,
|
||||
struct udev_rules *rules) {
|
||||
|
||||
sd_device *dev = event->dev->device;
|
||||
sd_device *dev = event->dev;
|
||||
int r;
|
||||
|
||||
r = device_read_db_force(dev);
|
||||
@ -814,7 +814,7 @@ int udev_event_execute_rules(struct udev_event *event,
|
||||
usec_t timeout_usec, usec_t timeout_warn_usec,
|
||||
Hashmap *properties_list,
|
||||
struct udev_rules *rules) {
|
||||
sd_device *dev = event->dev->device;
|
||||
sd_device *dev = event->dev;
|
||||
const char *subsystem, *action;
|
||||
int r;
|
||||
|
||||
@ -894,7 +894,7 @@ void udev_event_execute_run(struct udev_event *event, usec_t timeout_usec, usec_
|
||||
udev_event_apply_format(event, cmd, command, sizeof(command), false);
|
||||
|
||||
if (builtin_cmd >= 0 && builtin_cmd < _UDEV_BUILTIN_MAX)
|
||||
udev_builtin_run(event->dev->device, builtin_cmd, command, false);
|
||||
udev_builtin_run(event->dev, builtin_cmd, command, false);
|
||||
else {
|
||||
if (event->exec_delay > 0) {
|
||||
log_debug("delay execution of '%s'", command);
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "glob-util.h"
|
||||
#include "libudev-device-internal.h"
|
||||
#include "libudev-private.h"
|
||||
#include "path-util.h"
|
||||
#include "proc-cmdline.h"
|
||||
#include "stat-util.h"
|
||||
@ -659,7 +659,7 @@ static int import_program_into_properties(struct udev_event *event,
|
||||
pos[0] = '\0';
|
||||
pos = &pos[1];
|
||||
}
|
||||
(void) import_property_from_string(event->dev->device, line);
|
||||
(void) import_property_from_string(event->dev, line);
|
||||
line = pos;
|
||||
}
|
||||
return 0;
|
||||
@ -1727,7 +1727,7 @@ int udev_rules_apply_to_event(
|
||||
usec_t timeout_usec,
|
||||
usec_t timeout_warn_usec,
|
||||
Hashmap *properties_list) {
|
||||
sd_device *dev = event->dev->device;
|
||||
sd_device *dev = event->dev;
|
||||
enum escape_type esc = ESCAPE_UNSET;
|
||||
struct token *cur, *rule;
|
||||
const char *action, *val;
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "libudev.h"
|
||||
#include "sd-device.h"
|
||||
#include "sd-netlink.h"
|
||||
|
||||
@ -21,7 +20,7 @@
|
||||
#include "util.h"
|
||||
|
||||
struct udev_event {
|
||||
struct udev_device *dev;
|
||||
sd_device *dev;
|
||||
sd_device *dev_parent;
|
||||
sd_device *dev_db_clone;
|
||||
char *name;
|
||||
@ -60,7 +59,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
|
||||
int udev_rules_apply_static_dev_perms(struct udev_rules *rules);
|
||||
|
||||
/* udev-event.c */
|
||||
struct udev_event *udev_event_new(struct udev_device *dev, int exec_delay, sd_netlink *rtnl);
|
||||
struct udev_event *udev_event_new(sd_device *dev, int exec_delay, sd_netlink *rtnl);
|
||||
struct udev_event *udev_event_free(struct udev_event *event);
|
||||
ssize_t udev_event_apply_format(struct udev_event *event,
|
||||
const char *src, char *dest, size_t size,
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <sys/signalfd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libudev-device-internal.h"
|
||||
#include "string-util.h"
|
||||
#include "udev-builtin.h"
|
||||
#include "udev.h"
|
||||
@ -128,7 +129,7 @@ int test_main(int argc, char *argv[], void *userdata) {
|
||||
/* don't read info from the db */
|
||||
udev_device_set_info_loaded(dev);
|
||||
|
||||
event = udev_event_new(dev, 0, NULL);
|
||||
event = udev_event_new(dev->device, 0, NULL);
|
||||
|
||||
sigfillset(&mask);
|
||||
sigprocmask(SIG_SETMASK, &mask, &sigmask_orig);
|
||||
|
@ -342,7 +342,7 @@ static void worker_spawn(Manager *manager, struct event *event) {
|
||||
pid = fork();
|
||||
switch (pid) {
|
||||
case 0: {
|
||||
struct udev_device *dev = NULL;
|
||||
_cleanup_(udev_device_unrefp) struct udev_device *dev = NULL;
|
||||
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
|
||||
int fd_monitor;
|
||||
_cleanup_close_ int fd_signal = -1, fd_ep = -1;
|
||||
@ -409,7 +409,7 @@ static void worker_spawn(Manager *manager, struct event *event) {
|
||||
assert(dev);
|
||||
|
||||
log_debug("seq %llu running", udev_device_get_seqnum(dev));
|
||||
udev_event = udev_event_new(dev, arg_exec_delay, rtnl);
|
||||
udev_event = udev_event_new(dev->device, arg_exec_delay, rtnl);
|
||||
if (!udev_event) {
|
||||
r = -ENOMEM;
|
||||
goto out;
|
||||
@ -473,8 +473,7 @@ skip:
|
||||
log_error_errno(r, "failed to send result of seq %llu to main daemon: %m",
|
||||
udev_device_get_seqnum(dev));
|
||||
|
||||
udev_device_unref(dev);
|
||||
dev = NULL;
|
||||
dev = udev_device_unref(dev);
|
||||
|
||||
/* wait for more device messages from main udevd, or term signal */
|
||||
while (dev == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user