Merge pull request #11943 from yuwata/device-action-seqnum-cleanups
sd-device: store parsed SEQNUM and ACTION string
This commit is contained in:
commit
ec637f309f
|
@ -893,7 +893,8 @@ static void device_propagate_reload_by_sysfs(Manager *m, const char *sysfs) {
|
||||||
|
|
||||||
static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *userdata) {
|
static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *userdata) {
|
||||||
Manager *m = userdata;
|
Manager *m = userdata;
|
||||||
const char *action, *sysfs;
|
DeviceAction action;
|
||||||
|
const char *sysfs;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
|
@ -905,19 +906,19 @@ static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = sd_device_get_property_value(dev, "ACTION", &action);
|
r = device_get_action(dev, &action);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_device_error_errno(dev, r, "Failed to get udev action string: %m");
|
log_device_error_errno(dev, r, "Failed to get udev action: %m");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (streq(action, "change"))
|
if (action == DEVICE_ACTION_CHANGE)
|
||||||
device_propagate_reload_by_sysfs(m, sysfs);
|
device_propagate_reload_by_sysfs(m, sysfs);
|
||||||
|
|
||||||
/* A change event can signal that a device is becoming ready, in particular if
|
/* A change event can signal that a device is becoming ready, in particular if
|
||||||
* the device is using the SYSTEMD_READY logic in udev
|
* the device is using the SYSTEMD_READY logic in udev
|
||||||
* so we need to reach the else block of the follwing if, even for change events */
|
* so we need to reach the else block of the follwing if, even for change events */
|
||||||
if (streq(action, "remove")) {
|
if (action == DEVICE_ACTION_REMOVE) {
|
||||||
r = swap_process_device_remove(m, dev);
|
r = swap_process_device_remove(m, dev);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_device_warning_errno(dev, r, "Failed to process swap device remove event, ignoring: %m");
|
log_device_warning_errno(dev, r, "Failed to process swap device remove event, ignoring: %m");
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "sd-device.h"
|
#include "sd-device.h"
|
||||||
|
|
||||||
|
#include "device-private.h"
|
||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
#include "set.h"
|
#include "set.h"
|
||||||
#include "time-util.h"
|
#include "time-util.h"
|
||||||
|
@ -64,6 +65,10 @@ struct sd_device {
|
||||||
uid_t devuid;
|
uid_t devuid;
|
||||||
gid_t devgid;
|
gid_t devgid;
|
||||||
|
|
||||||
|
/* only set when device is passed through netlink */
|
||||||
|
DeviceAction action;
|
||||||
|
uint64_t seqnum;
|
||||||
|
|
||||||
bool parent_set:1; /* no need to try to reload parent */
|
bool parent_set:1; /* no need to try to reload parent */
|
||||||
bool sysattrs_read:1; /* don't try to re-read sysattrs once read */
|
bool sysattrs_read:1; /* don't try to re-read sysattrs once read */
|
||||||
bool property_tags_outdated:1; /* need to update TAGS= property */
|
bool property_tags_outdated:1; /* need to update TAGS= property */
|
||||||
|
|
|
@ -183,6 +183,72 @@ static int device_set_devgid(sd_device *device, const char *gid) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int device_get_action(sd_device *device, DeviceAction *action) {
|
||||||
|
assert(device);
|
||||||
|
|
||||||
|
if (device->action < 0)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
|
if (action)
|
||||||
|
*action = device->action;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int device_set_action(sd_device *device, const char *action) {
|
||||||
|
DeviceAction a;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(device);
|
||||||
|
assert(action);
|
||||||
|
|
||||||
|
a = device_action_from_string(action);
|
||||||
|
if (a < 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
r = device_add_property_internal(device, "ACTION", action);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
device->action = a;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int device_get_seqnum(sd_device *device, uint64_t *seqnum) {
|
||||||
|
assert(device);
|
||||||
|
|
||||||
|
if (device->seqnum == 0)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
|
if (seqnum)
|
||||||
|
*seqnum = device->seqnum;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int device_set_seqnum(sd_device *device, const char *str) {
|
||||||
|
uint64_t seqnum;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(device);
|
||||||
|
assert(str);
|
||||||
|
|
||||||
|
r = safe_atou64(str, &seqnum);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
if (seqnum == 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
r = device_add_property_internal(device, "SEQNUM", str);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
device->seqnum = seqnum;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int device_amend(sd_device *device, const char *key, const char *value) {
|
static int device_amend(sd_device *device, const char *key, const char *value) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -241,6 +307,14 @@ static int device_amend(sd_device *device, const char *key, const char *value) {
|
||||||
r = device_set_devgid(device, value);
|
r = device_set_devgid(device, value);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_device_debug_errno(device, r, "sd-device: Failed to set devgid to '%s': %m", value);
|
return log_device_debug_errno(device, r, "sd-device: Failed to set devgid to '%s': %m", value);
|
||||||
|
} else if (streq(key, "ACTION")) {
|
||||||
|
r = device_set_action(device, value);
|
||||||
|
if (r < 0)
|
||||||
|
return log_device_debug_errno(device, r, "sd-device: Failed to set action to '%s': %m", value);
|
||||||
|
} else if (streq(key, "SEQNUM")) {
|
||||||
|
r = device_set_seqnum(device, value);
|
||||||
|
if (r < 0)
|
||||||
|
return log_device_debug_errno(device, r, "sd-device: Failed to set SEQNUM to '%s': %m", value);
|
||||||
} else if (streq(key, "DEVLINKS")) {
|
} else if (streq(key, "DEVLINKS")) {
|
||||||
const char *word, *state;
|
const char *word, *state;
|
||||||
size_t l;
|
size_t l;
|
||||||
|
@ -278,23 +352,7 @@ static int device_amend(sd_device *device, const char *key, const char *value) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* const device_action_table[_DEVICE_ACTION_MAX] = {
|
static int device_append(sd_device *device, char *key, const char **_major, const char **_minor) {
|
||||||
[DEVICE_ACTION_ADD] = "add",
|
|
||||||
[DEVICE_ACTION_REMOVE] = "remove",
|
|
||||||
[DEVICE_ACTION_CHANGE] = "change",
|
|
||||||
[DEVICE_ACTION_MOVE] = "move",
|
|
||||||
[DEVICE_ACTION_ONLINE] = "online",
|
|
||||||
[DEVICE_ACTION_OFFLINE] = "offline",
|
|
||||||
[DEVICE_ACTION_BIND] = "bind",
|
|
||||||
[DEVICE_ACTION_UNBIND] = "unbind",
|
|
||||||
};
|
|
||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP(device_action, DeviceAction);
|
|
||||||
|
|
||||||
static int device_append(sd_device *device, char *key, const char **_major, const char **_minor, uint64_t *_seqnum,
|
|
||||||
DeviceAction *_action) {
|
|
||||||
DeviceAction action = _DEVICE_ACTION_INVALID;
|
|
||||||
uint64_t seqnum = 0;
|
|
||||||
const char *major = NULL, *minor = NULL;
|
const char *major = NULL, *minor = NULL;
|
||||||
char *value;
|
char *value;
|
||||||
int r;
|
int r;
|
||||||
|
@ -303,8 +361,6 @@ static int device_append(sd_device *device, char *key, const char **_major, cons
|
||||||
assert(key);
|
assert(key);
|
||||||
assert(_major);
|
assert(_major);
|
||||||
assert(_minor);
|
assert(_minor);
|
||||||
assert(_seqnum);
|
|
||||||
assert(_action);
|
|
||||||
|
|
||||||
value = strchr(key, '=');
|
value = strchr(key, '=');
|
||||||
if (!value) {
|
if (!value) {
|
||||||
|
@ -321,19 +377,6 @@ static int device_append(sd_device *device, char *key, const char **_major, cons
|
||||||
else if (streq(key, "MINOR"))
|
else if (streq(key, "MINOR"))
|
||||||
minor = value;
|
minor = value;
|
||||||
else {
|
else {
|
||||||
if (streq(key, "ACTION")) {
|
|
||||||
action = device_action_from_string(value);
|
|
||||||
if (action == _DEVICE_ACTION_INVALID)
|
|
||||||
return -EINVAL;
|
|
||||||
} else if (streq(key, "SEQNUM")) {
|
|
||||||
r = safe_atou64(value, &seqnum);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
else if (seqnum == 0)
|
|
||||||
/* kernel only sends seqnum > 0 */
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = device_amend(device, key, value);
|
r = device_amend(device, key, value);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -345,12 +388,6 @@ static int device_append(sd_device *device, char *key, const char **_major, cons
|
||||||
if (minor != 0)
|
if (minor != 0)
|
||||||
*_minor = minor;
|
*_minor = minor;
|
||||||
|
|
||||||
if (action != _DEVICE_ACTION_INVALID)
|
|
||||||
*_action = action;
|
|
||||||
|
|
||||||
if (seqnum > 0)
|
|
||||||
*_seqnum = seqnum;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,10 +397,10 @@ void device_seal(sd_device *device) {
|
||||||
device->sealed = true;
|
device->sealed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int device_verify(sd_device *device, DeviceAction action, uint64_t seqnum) {
|
static int device_verify(sd_device *device) {
|
||||||
assert(device);
|
assert(device);
|
||||||
|
|
||||||
if (!device->devpath || !device->subsystem || action == _DEVICE_ACTION_INVALID || seqnum == 0) {
|
if (!device->devpath || !device->subsystem || device->action < 0 || device->seqnum == 0) {
|
||||||
log_device_debug(device, "sd-device: Device created from strv or nulstr lacks devpath, subsystem, action or seqnum.");
|
log_device_debug(device, "sd-device: Device created from strv or nulstr lacks devpath, subsystem, action or seqnum.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -377,8 +414,6 @@ int device_new_from_strv(sd_device **ret, char **strv) {
|
||||||
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||||
char **key;
|
char **key;
|
||||||
const char *major = NULL, *minor = NULL;
|
const char *major = NULL, *minor = NULL;
|
||||||
DeviceAction action = _DEVICE_ACTION_INVALID;
|
|
||||||
uint64_t seqnum = 0;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
@ -389,7 +424,7 @@ int device_new_from_strv(sd_device **ret, char **strv) {
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
STRV_FOREACH(key, strv) {
|
STRV_FOREACH(key, strv) {
|
||||||
r = device_append(device, *key, &major, &minor, &seqnum, &action);
|
r = device_append(device, *key, &major, &minor);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -400,7 +435,7 @@ int device_new_from_strv(sd_device **ret, char **strv) {
|
||||||
return log_device_debug_errno(device, r, "sd-device: Failed to set devnum %s:%s: %m", major, minor);
|
return log_device_debug_errno(device, r, "sd-device: Failed to set devnum %s:%s: %m", major, minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = device_verify(device, action, seqnum);
|
r = device_verify(device);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -412,8 +447,6 @@ int device_new_from_strv(sd_device **ret, char **strv) {
|
||||||
int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
|
int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
|
||||||
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||||
const char *major = NULL, *minor = NULL;
|
const char *major = NULL, *minor = NULL;
|
||||||
DeviceAction action = _DEVICE_ACTION_INVALID;
|
|
||||||
uint64_t seqnum = 0;
|
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -437,7 +470,7 @@ int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
|
||||||
}
|
}
|
||||||
i += end - key + 1;
|
i += end - key + 1;
|
||||||
|
|
||||||
r = device_append(device, key, &major, &minor, &seqnum, &action);
|
r = device_append(device, key, &major, &minor);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -448,7 +481,7 @@ int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
|
||||||
return log_device_debug_errno(device, r, "sd-device: Failed to set devnum %s:%s: %m", major, minor);
|
return log_device_debug_errno(device, r, "sd-device: Failed to set devnum %s:%s: %m", major, minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = device_verify(device, action, seqnum);
|
r = device_verify(device);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -674,7 +707,7 @@ int device_new_from_synthetic_event(sd_device **new_device, const char *syspath,
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = device_add_property_internal(ret, "ACTION", action);
|
r = device_set_action(ret, action);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -953,3 +986,16 @@ int device_delete_db(sd_device *device) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* const device_action_table[_DEVICE_ACTION_MAX] = {
|
||||||
|
[DEVICE_ACTION_ADD] = "add",
|
||||||
|
[DEVICE_ACTION_REMOVE] = "remove",
|
||||||
|
[DEVICE_ACTION_CHANGE] = "change",
|
||||||
|
[DEVICE_ACTION_MOVE] = "move",
|
||||||
|
[DEVICE_ACTION_ONLINE] = "online",
|
||||||
|
[DEVICE_ACTION_OFFLINE] = "offline",
|
||||||
|
[DEVICE_ACTION_BIND] = "bind",
|
||||||
|
[DEVICE_ACTION_UNBIND] = "unbind",
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_STRING_TABLE_LOOKUP(device_action, DeviceAction);
|
||||||
|
|
|
@ -10,6 +10,19 @@
|
||||||
|
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
|
|
||||||
|
typedef enum DeviceAction {
|
||||||
|
DEVICE_ACTION_ADD,
|
||||||
|
DEVICE_ACTION_REMOVE,
|
||||||
|
DEVICE_ACTION_CHANGE,
|
||||||
|
DEVICE_ACTION_MOVE,
|
||||||
|
DEVICE_ACTION_ONLINE,
|
||||||
|
DEVICE_ACTION_OFFLINE,
|
||||||
|
DEVICE_ACTION_BIND,
|
||||||
|
DEVICE_ACTION_UNBIND,
|
||||||
|
_DEVICE_ACTION_MAX,
|
||||||
|
_DEVICE_ACTION_INVALID = -1,
|
||||||
|
} DeviceAction;
|
||||||
|
|
||||||
int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len);
|
int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len);
|
||||||
int device_new_from_strv(sd_device **ret, char **strv);
|
int device_new_from_strv(sd_device **ret, char **strv);
|
||||||
int device_new_from_stat_rdev(sd_device **ret, const struct stat *st);
|
int device_new_from_stat_rdev(sd_device **ret, const struct stat *st);
|
||||||
|
@ -21,6 +34,8 @@ int device_get_watch_handle(sd_device *device, int *handle);
|
||||||
int device_get_devnode_mode(sd_device *device, mode_t *mode);
|
int device_get_devnode_mode(sd_device *device, mode_t *mode);
|
||||||
int device_get_devnode_uid(sd_device *device, uid_t *uid);
|
int device_get_devnode_uid(sd_device *device, uid_t *uid);
|
||||||
int device_get_devnode_gid(sd_device *device, gid_t *gid);
|
int device_get_devnode_gid(sd_device *device, gid_t *gid);
|
||||||
|
int device_get_action(sd_device *device, DeviceAction *action);
|
||||||
|
int device_get_seqnum(sd_device *device, uint64_t *seqnum);
|
||||||
|
|
||||||
void device_seal(sd_device *device);
|
void device_seal(sd_device *device);
|
||||||
void device_set_is_initialized(sd_device *device);
|
void device_set_is_initialized(sd_device *device);
|
||||||
|
@ -58,18 +73,5 @@ static inline int device_read_db(sd_device *device) {
|
||||||
return device_read_db_internal(device, false);
|
return device_read_db_internal(device, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum DeviceAction {
|
|
||||||
DEVICE_ACTION_ADD,
|
|
||||||
DEVICE_ACTION_REMOVE,
|
|
||||||
DEVICE_ACTION_CHANGE,
|
|
||||||
DEVICE_ACTION_MOVE,
|
|
||||||
DEVICE_ACTION_ONLINE,
|
|
||||||
DEVICE_ACTION_OFFLINE,
|
|
||||||
DEVICE_ACTION_BIND,
|
|
||||||
DEVICE_ACTION_UNBIND,
|
|
||||||
_DEVICE_ACTION_MAX,
|
|
||||||
_DEVICE_ACTION_INVALID = -1,
|
|
||||||
} DeviceAction;
|
|
||||||
|
|
||||||
DeviceAction device_action_from_string(const char *s) _pure_;
|
DeviceAction device_action_from_string(const char *s) _pure_;
|
||||||
const char *device_action_to_string(DeviceAction a) _const_;
|
const char *device_action_to_string(DeviceAction a) _const_;
|
||||||
|
|
|
@ -43,6 +43,7 @@ int device_new_aux(sd_device **ret) {
|
||||||
.devmode = (mode_t) -1,
|
.devmode = (mode_t) -1,
|
||||||
.devuid = (uid_t) -1,
|
.devuid = (uid_t) -1,
|
||||||
.devgid = (gid_t) -1,
|
.devgid = (gid_t) -1,
|
||||||
|
.action = _DEVICE_ACTION_INVALID,
|
||||||
};
|
};
|
||||||
|
|
||||||
*ret = device;
|
*ret = device;
|
||||||
|
|
|
@ -45,24 +45,15 @@
|
||||||
*
|
*
|
||||||
* Returns: the kernel event sequence number, or 0 if there is no sequence number available.
|
* Returns: the kernel event sequence number, or 0 if there is no sequence number available.
|
||||||
**/
|
**/
|
||||||
_public_ unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device) {
|
_public_ unsigned long long udev_device_get_seqnum(struct udev_device *udev_device) {
|
||||||
const char *seqnum;
|
uint64_t seqnum;
|
||||||
unsigned long long ret;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert_return_errno(udev_device, 0, EINVAL);
|
assert_return_errno(udev_device, 0, EINVAL);
|
||||||
|
|
||||||
r = sd_device_get_property_value(udev_device->device, "SEQNUM", &seqnum);
|
if (device_get_seqnum(udev_device->device, &seqnum) < 0)
|
||||||
if (r == -ENOENT)
|
|
||||||
return 0;
|
return 0;
|
||||||
else if (r < 0)
|
|
||||||
return_with_errno(0, r);
|
|
||||||
|
|
||||||
r = safe_atollu(seqnum, &ret);
|
return seqnum;
|
||||||
if (r < 0)
|
|
||||||
return_with_errno(0, r);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -652,18 +643,14 @@ _public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct ud
|
||||||
* Returns: the kernel action value, or #NULL if there is no action value available.
|
* Returns: the kernel action value, or #NULL if there is no action value available.
|
||||||
**/
|
**/
|
||||||
_public_ const char *udev_device_get_action(struct udev_device *udev_device) {
|
_public_ const char *udev_device_get_action(struct udev_device *udev_device) {
|
||||||
const char *action;
|
DeviceAction action;
|
||||||
int r;
|
|
||||||
|
|
||||||
assert_return_errno(udev_device, NULL, EINVAL);
|
assert_return_errno(udev_device, NULL, EINVAL);
|
||||||
|
|
||||||
r = sd_device_get_property_value(udev_device->device, "ACTION", &action);
|
if (device_get_action(udev_device->device, &action) < 0)
|
||||||
if (r == -ENOENT)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
if (r < 0)
|
|
||||||
return_with_errno(NULL, r);
|
|
||||||
|
|
||||||
return action;
|
return device_action_to_string(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "process-util.h"
|
#include "process-util.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
#include "terminal-util.h"
|
#include "terminal-util.h"
|
||||||
|
#include "udev-util.h"
|
||||||
#include "user-util.h"
|
#include "user-util.h"
|
||||||
|
|
||||||
void manager_reset_config(Manager *m) {
|
void manager_reset_config(Manager *m) {
|
||||||
|
@ -238,14 +239,12 @@ int manager_add_button(Manager *m, const char *name, Button **_button) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_process_seat_device(Manager *m, sd_device *d) {
|
int manager_process_seat_device(Manager *m, sd_device *d) {
|
||||||
const char *action;
|
|
||||||
Device *device;
|
Device *device;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
|
|
||||||
if (sd_device_get_property_value(d, "ACTION", &action) >= 0 &&
|
if (device_for_action(d, DEVICE_ACTION_REMOVE)) {
|
||||||
streq(action, "remove")) {
|
|
||||||
const char *syspath;
|
const char *syspath;
|
||||||
|
|
||||||
r = sd_device_get_syspath(d, &syspath);
|
r = sd_device_get_syspath(d, &syspath);
|
||||||
|
@ -305,7 +304,7 @@ int manager_process_seat_device(Manager *m, sd_device *d) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_process_button_device(Manager *m, sd_device *d) {
|
int manager_process_button_device(Manager *m, sd_device *d) {
|
||||||
const char *action, *sysname;
|
const char *sysname;
|
||||||
Button *b;
|
Button *b;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -315,8 +314,7 @@ int manager_process_button_device(Manager *m, sd_device *d) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (sd_device_get_property_value(d, "ACTION", &action) >= 0 &&
|
if (device_for_action(d, DEVICE_ACTION_REMOVE)) {
|
||||||
streq(action, "remove")) {
|
|
||||||
|
|
||||||
b = hashmap_get(m->buttons, sysname);
|
b = hashmap_get(m->buttons, sysname);
|
||||||
if (!b)
|
if (!b)
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "signal-util.h"
|
#include "signal-util.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
#include "terminal-util.h"
|
#include "terminal-util.h"
|
||||||
|
#include "udev-util.h"
|
||||||
|
|
||||||
static Manager* manager_unref(Manager *m);
|
static Manager* manager_unref(Manager *m);
|
||||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref);
|
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref);
|
||||||
|
@ -559,7 +560,7 @@ static int manager_dispatch_device_udev(sd_device_monitor *monitor, sd_device *d
|
||||||
|
|
||||||
static int manager_dispatch_vcsa_udev(sd_device_monitor *monitor, sd_device *device, void *userdata) {
|
static int manager_dispatch_vcsa_udev(sd_device_monitor *monitor, sd_device *device, void *userdata) {
|
||||||
Manager *m = userdata;
|
Manager *m = userdata;
|
||||||
const char *name, *action;
|
const char *name;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(device);
|
assert(device);
|
||||||
|
@ -569,8 +570,7 @@ static int manager_dispatch_vcsa_udev(sd_device_monitor *monitor, sd_device *dev
|
||||||
|
|
||||||
if (sd_device_get_sysname(device, &name) >= 0 &&
|
if (sd_device_get_sysname(device, &name) >= 0 &&
|
||||||
startswith(name, "vcsa") &&
|
startswith(name, "vcsa") &&
|
||||||
sd_device_get_property_value(device, "ACTION", &action) >= 0 &&
|
device_for_action(device, DEVICE_ACTION_REMOVE))
|
||||||
streq(action, "remove"))
|
|
||||||
seat_preallocate_vts(m->seat0);
|
seat_preallocate_vts(m->seat0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "bus-util.h"
|
#include "bus-util.h"
|
||||||
#include "conf-parser.h"
|
#include "conf-parser.h"
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
|
#include "device-private.h"
|
||||||
#include "device-util.h"
|
#include "device-util.h"
|
||||||
#include "dns-domain.h"
|
#include "dns-domain.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
|
@ -182,21 +183,21 @@ int manager_connect_bus(Manager *m) {
|
||||||
|
|
||||||
static int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, void *userdata) {
|
static int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, void *userdata) {
|
||||||
Manager *m = userdata;
|
Manager *m = userdata;
|
||||||
const char *action;
|
DeviceAction action;
|
||||||
Link *link = NULL;
|
Link *link = NULL;
|
||||||
int r, ifindex;
|
int r, ifindex;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(device);
|
assert(device);
|
||||||
|
|
||||||
r = sd_device_get_property_value(device, "ACTION", &action);
|
r = device_get_action(device, &action);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_device_debug_errno(device, r, "Failed to get 'ACTION' property, ignoring device: %m");
|
log_device_debug_errno(device, r, "Failed to get udev action, ignoring device: %m");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!STR_IN_SET(action, "add", "change", "move")) {
|
if (!IN_SET(action, DEVICE_ACTION_ADD, DEVICE_ACTION_CHANGE, DEVICE_ACTION_MOVE)) {
|
||||||
log_device_debug(device, "Ignoring udev %s event for device.", action);
|
log_device_debug(device, "Ignoring udev %s event for device.", device_action_to_string(action));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +209,8 @@ static int manager_udev_process_link(sd_device_monitor *monitor, sd_device *devi
|
||||||
|
|
||||||
r = device_is_renaming(device);
|
r = device_is_renaming(device);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_device_error_errno(device, r, "Failed to determine the device is renamed or not, ignoring '%s' uevent: %m", action);
|
log_device_error_errno(device, r, "Failed to determine the device is renamed or not, ignoring '%s' uevent: %m",
|
||||||
|
device_action_to_string(action));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
|
|
|
@ -181,3 +181,14 @@ int device_is_renaming(sd_device *dev) {
|
||||||
|
|
||||||
return r >= 0;
|
return r >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool device_for_action(sd_device *dev, DeviceAction action) {
|
||||||
|
DeviceAction a;
|
||||||
|
|
||||||
|
assert(dev);
|
||||||
|
|
||||||
|
if (device_get_action(dev, &a) < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return a == action;
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "sd-device.h"
|
#include "sd-device.h"
|
||||||
|
|
||||||
|
#include "device-private.h"
|
||||||
#include "time-util.h"
|
#include "time-util.h"
|
||||||
|
|
||||||
typedef enum ResolveNameTiming {
|
typedef enum ResolveNameTiming {
|
||||||
|
@ -28,3 +29,4 @@ static inline int udev_parse_config(void) {
|
||||||
|
|
||||||
int device_wait_for_initialization(sd_device *device, const char *subsystem, sd_device **ret);
|
int device_wait_for_initialization(sd_device *device, const char *subsystem, sd_device **ret);
|
||||||
int device_is_renaming(sd_device *dev);
|
int device_is_renaming(sd_device *dev);
|
||||||
|
bool device_for_action(sd_device *dev, DeviceAction action);
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "strxcpyx.h"
|
#include "strxcpyx.h"
|
||||||
#include "udev-builtin.h"
|
#include "udev-builtin.h"
|
||||||
#include "udev-node.h"
|
#include "udev-node.h"
|
||||||
|
#include "udev-util.h"
|
||||||
#include "udev-watch.h"
|
#include "udev-watch.h"
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
|
|
||||||
|
@ -695,7 +696,7 @@ int udev_event_spawn(UdevEvent *event,
|
||||||
|
|
||||||
static int rename_netif(UdevEvent *event) {
|
static int rename_netif(UdevEvent *event) {
|
||||||
sd_device *dev = event->dev;
|
sd_device *dev = event->dev;
|
||||||
const char *action, *oldname;
|
const char *oldname;
|
||||||
int ifindex, r;
|
int ifindex, r;
|
||||||
|
|
||||||
if (!event->name)
|
if (!event->name)
|
||||||
|
@ -708,11 +709,7 @@ static int rename_netif(UdevEvent *event) {
|
||||||
if (streq(event->name, oldname))
|
if (streq(event->name, oldname))
|
||||||
return 0; /* The interface name is already requested name. */
|
return 0; /* The interface name is already requested name. */
|
||||||
|
|
||||||
r = sd_device_get_property_value(dev, "ACTION", &action);
|
if (!device_for_action(dev, DEVICE_ACTION_ADD))
|
||||||
if (r < 0)
|
|
||||||
return log_device_error_errno(dev, r, "Failed to get property 'ACTION': %m");
|
|
||||||
|
|
||||||
if (!streq(action, "add"))
|
|
||||||
return 0; /* Rename the interface only when it is added. */
|
return 0; /* Rename the interface only when it is added. */
|
||||||
|
|
||||||
r = sd_device_get_ifindex(dev, &ifindex);
|
r = sd_device_get_ifindex(dev, &ifindex);
|
||||||
|
@ -742,7 +739,6 @@ static int rename_netif(UdevEvent *event) {
|
||||||
|
|
||||||
static int update_devnode(UdevEvent *event) {
|
static int update_devnode(UdevEvent *event) {
|
||||||
sd_device *dev = event->dev;
|
sd_device *dev = event->dev;
|
||||||
const char *action;
|
|
||||||
bool apply;
|
bool apply;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -782,11 +778,7 @@ static int update_devnode(UdevEvent *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r = sd_device_get_property_value(dev, "ACTION", &action);
|
apply = device_for_action(dev, DEVICE_ACTION_ADD) || event->owner_set || event->group_set || event->mode_set;
|
||||||
if (r < 0)
|
|
||||||
return log_device_error_errno(dev, r, "Failed to get property 'ACTION': %m");
|
|
||||||
|
|
||||||
apply = streq(action, "add") || event->owner_set || event->group_set || event->mode_set;
|
|
||||||
return udev_node_add(dev, apply, event->mode, event->uid, event->gid, event->seclabel_list);
|
return udev_node_add(dev, apply, event->mode, event->uid, event->gid, event->seclabel_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -843,7 +835,8 @@ int udev_event_execute_rules(UdevEvent *event,
|
||||||
usec_t timeout_usec,
|
usec_t timeout_usec,
|
||||||
Hashmap *properties_list,
|
Hashmap *properties_list,
|
||||||
UdevRules *rules) {
|
UdevRules *rules) {
|
||||||
const char *subsystem, *action;
|
const char *subsystem;
|
||||||
|
DeviceAction action;
|
||||||
sd_device *dev;
|
sd_device *dev;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -856,11 +849,11 @@ int udev_event_execute_rules(UdevEvent *event,
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_device_error_errno(dev, r, "Failed to get subsystem: %m");
|
return log_device_error_errno(dev, r, "Failed to get subsystem: %m");
|
||||||
|
|
||||||
r = sd_device_get_property_value(dev, "ACTION", &action);
|
r = device_get_action(dev, &action);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_device_error_errno(dev, r, "Failed to get property 'ACTION': %m");
|
return log_device_error_errno(dev, r, "Failed to get ACTION: %m");
|
||||||
|
|
||||||
if (streq(action, "remove")) {
|
if (action == DEVICE_ACTION_REMOVE) {
|
||||||
event_execute_rules_on_remove(event, timeout_usec, properties_list, rules);
|
event_execute_rules_on_remove(event, timeout_usec, properties_list, rules);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -873,7 +866,7 @@ int udev_event_execute_rules(UdevEvent *event,
|
||||||
/* Disable watch during event processing. */
|
/* Disable watch during event processing. */
|
||||||
(void) udev_watch_end(event->dev_db_clone);
|
(void) udev_watch_end(event->dev_db_clone);
|
||||||
|
|
||||||
if (streq(action, "move"))
|
if (action == DEVICE_ACTION_MOVE)
|
||||||
(void) udev_event_on_move(event);
|
(void) udev_event_on_move(event);
|
||||||
|
|
||||||
(void) udev_rules_apply_to_event(rules, event, timeout_usec, properties_list);
|
(void) udev_rules_apply_to_event(rules, event, timeout_usec, properties_list);
|
||||||
|
|
|
@ -1156,6 +1156,7 @@ static void add_rule(UdevRules *rules, char *line,
|
||||||
else {
|
else {
|
||||||
if (STR_IN_SET(attr,
|
if (STR_IN_SET(attr,
|
||||||
"ACTION",
|
"ACTION",
|
||||||
|
"SEQNUM",
|
||||||
"SUBSYSTEM",
|
"SUBSYSTEM",
|
||||||
"DEVTYPE",
|
"DEVTYPE",
|
||||||
"MAJOR",
|
"MAJOR",
|
||||||
|
@ -1767,18 +1768,19 @@ int udev_rules_apply_to_event(
|
||||||
sd_device *dev = event->dev;
|
sd_device *dev = event->dev;
|
||||||
enum escape_type esc = ESCAPE_UNSET;
|
enum escape_type esc = ESCAPE_UNSET;
|
||||||
struct token *cur, *rule;
|
struct token *cur, *rule;
|
||||||
const char *action, *val;
|
DeviceAction action;
|
||||||
|
const char *val;
|
||||||
bool can_set_name;
|
bool can_set_name;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!rules->tokens)
|
if (!rules->tokens)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
r = sd_device_get_property_value(dev, "ACTION", &action);
|
r = device_get_action(dev, &action);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
can_set_name = (!streq(action, "remove") &&
|
can_set_name = (action != DEVICE_ACTION_REMOVE &&
|
||||||
(sd_device_get_devnum(dev, NULL) >= 0 ||
|
(sd_device_get_devnum(dev, NULL) >= 0 ||
|
||||||
sd_device_get_ifindex(dev, NULL) >= 0));
|
sd_device_get_ifindex(dev, NULL) >= 0));
|
||||||
|
|
||||||
|
@ -1797,7 +1799,7 @@ int udev_rules_apply_to_event(
|
||||||
esc = ESCAPE_UNSET;
|
esc = ESCAPE_UNSET;
|
||||||
break;
|
break;
|
||||||
case TK_M_ACTION:
|
case TK_M_ACTION:
|
||||||
if (!match_key(rules, cur, action))
|
if (!match_key(rules, cur, device_action_to_string(action)))
|
||||||
goto nomatch;
|
goto nomatch;
|
||||||
break;
|
break;
|
||||||
case TK_M_DEVPATH:
|
case TK_M_DEVPATH:
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "device-monitor-private.h"
|
#include "device-monitor-private.h"
|
||||||
|
#include "device-private.h"
|
||||||
#include "device-util.h"
|
#include "device-util.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
#include "format-util.h"
|
#include "format-util.h"
|
||||||
|
@ -26,14 +27,15 @@ static Set *arg_tag_filter = NULL;
|
||||||
static Hashmap *arg_subsystem_filter = NULL;
|
static Hashmap *arg_subsystem_filter = NULL;
|
||||||
|
|
||||||
static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, void *userdata) {
|
static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, void *userdata) {
|
||||||
const char *action = NULL, *devpath = NULL, *subsystem = NULL;
|
DeviceAction action = _DEVICE_ACTION_INVALID;
|
||||||
|
const char *devpath = NULL, *subsystem = NULL;
|
||||||
MonitorNetlinkGroup group = PTR_TO_INT(userdata);
|
MonitorNetlinkGroup group = PTR_TO_INT(userdata);
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|
||||||
assert(device);
|
assert(device);
|
||||||
assert(IN_SET(group, MONITOR_GROUP_UDEV, MONITOR_GROUP_KERNEL));
|
assert(IN_SET(group, MONITOR_GROUP_UDEV, MONITOR_GROUP_KERNEL));
|
||||||
|
|
||||||
(void) sd_device_get_property_value(device, "ACTION", &action);
|
(void) device_get_action(device, &action);
|
||||||
(void) sd_device_get_devpath(device, &devpath);
|
(void) sd_device_get_devpath(device, &devpath);
|
||||||
(void) sd_device_get_subsystem(device, &subsystem);
|
(void) sd_device_get_subsystem(device, &subsystem);
|
||||||
|
|
||||||
|
@ -42,7 +44,8 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device,
|
||||||
printf("%-6s[%"PRI_TIME".%06"PRI_NSEC"] %-8s %s (%s)\n",
|
printf("%-6s[%"PRI_TIME".%06"PRI_NSEC"] %-8s %s (%s)\n",
|
||||||
group == MONITOR_GROUP_UDEV ? "UDEV" : "KERNEL",
|
group == MONITOR_GROUP_UDEV ? "UDEV" : "KERNEL",
|
||||||
ts.tv_sec, (nsec_t)ts.tv_nsec/1000,
|
ts.tv_sec, (nsec_t)ts.tv_nsec/1000,
|
||||||
action, devpath, subsystem);
|
strna(device_action_to_string(action)),
|
||||||
|
devpath, subsystem);
|
||||||
|
|
||||||
if (arg_show_property) {
|
if (arg_show_property) {
|
||||||
const char *key, *value;
|
const char *key, *value;
|
||||||
|
|
|
@ -53,9 +53,17 @@ static int parse_argv(int argc, char *argv[]) {
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "a:N:Vh", options, NULL)) >= 0)
|
while ((c = getopt_long(argc, argv, "a:N:Vh", options, NULL)) >= 0)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a': {
|
||||||
|
DeviceAction a;
|
||||||
|
|
||||||
|
a = device_action_from_string(optarg);
|
||||||
|
if (a < 0)
|
||||||
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
|
"Invalid action '%s'", optarg);
|
||||||
|
|
||||||
arg_action = optarg;
|
arg_action = optarg;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'N':
|
case 'N':
|
||||||
arg_resolve_name_timing = resolve_name_timing_from_string(optarg);
|
arg_resolve_name_timing = resolve_name_timing_from_string(optarg);
|
||||||
if (arg_resolve_name_timing < 0)
|
if (arg_resolve_name_timing < 0)
|
||||||
|
|
|
@ -333,11 +333,7 @@ static int worker_lock_block_device(sd_device *dev, int *ret_fd) {
|
||||||
* udev has finished its event handling.
|
* udev has finished its event handling.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
r = sd_device_get_property_value(dev, "ACTION", &val);
|
if (device_for_action(dev, DEVICE_ACTION_REMOVE))
|
||||||
if (r < 0)
|
|
||||||
return log_device_debug_errno(dev, r, "Failed to get the value of property 'ACTION': %m");
|
|
||||||
|
|
||||||
if (streq(val, "remove"))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
r = sd_device_get_subsystem(dev, &val);
|
r = sd_device_get_subsystem(dev, &val);
|
||||||
|
@ -385,21 +381,23 @@ static int worker_lock_block_device(sd_device *dev, int *ret_fd) {
|
||||||
static int worker_process_device(Manager *manager, sd_device *dev) {
|
static int worker_process_device(Manager *manager, sd_device *dev) {
|
||||||
_cleanup_(udev_event_freep) UdevEvent *udev_event = NULL;
|
_cleanup_(udev_event_freep) UdevEvent *udev_event = NULL;
|
||||||
_cleanup_close_ int fd_lock = -1;
|
_cleanup_close_ int fd_lock = -1;
|
||||||
const char *seqnum, *action;
|
DeviceAction action;
|
||||||
|
uint64_t seqnum;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(manager);
|
assert(manager);
|
||||||
assert(dev);
|
assert(dev);
|
||||||
|
|
||||||
r = sd_device_get_property_value(dev, "SEQNUM", &seqnum);
|
r = device_get_seqnum(dev, &seqnum);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_device_debug_errno(dev, r, "Failed to get SEQNUM: %m");
|
return log_device_debug_errno(dev, r, "Failed to get SEQNUM: %m");
|
||||||
|
|
||||||
r = sd_device_get_property_value(dev, "ACTION", &action);
|
r = device_get_action(dev, &action);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_device_debug_errno(dev, r, "Failed to get ACTION: %m");
|
return log_device_debug_errno(dev, r, "Failed to get ACTION: %m");
|
||||||
|
|
||||||
log_device_debug(dev, "Processing device (SEQNUM=%s, ACTION=%s)", seqnum, action);
|
log_device_debug(dev, "Processing device (SEQNUM=%"PRIu64", ACTION=%s)",
|
||||||
|
seqnum, device_action_to_string(action));
|
||||||
|
|
||||||
udev_event = udev_event_new(dev, arg_exec_delay_usec, manager->rtnl);
|
udev_event = udev_event_new(dev, arg_exec_delay_usec, manager->rtnl);
|
||||||
if (!udev_event)
|
if (!udev_event)
|
||||||
|
@ -425,7 +423,8 @@ static int worker_process_device(Manager *manager, sd_device *dev) {
|
||||||
return log_device_debug_errno(dev, r, "Failed to update database under /run/udev/data/: %m");
|
return log_device_debug_errno(dev, r, "Failed to update database under /run/udev/data/: %m");
|
||||||
}
|
}
|
||||||
|
|
||||||
log_device_debug(dev, "Device (SEQNUM=%s, ACTION=%s) processed", seqnum, action);
|
log_device_debug(dev, "Device (SEQNUM=%"PRIu64", ACTION=%s) processed",
|
||||||
|
seqnum, device_action_to_string(action));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -581,8 +580,8 @@ static void event_run(Manager *manager, struct event *event) {
|
||||||
|
|
||||||
static int event_queue_insert(Manager *manager, sd_device *dev) {
|
static int event_queue_insert(Manager *manager, sd_device *dev) {
|
||||||
_cleanup_(sd_device_unrefp) sd_device *clone = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *clone = NULL;
|
||||||
const char *val, *action;
|
|
||||||
struct event *event;
|
struct event *event;
|
||||||
|
DeviceAction action;
|
||||||
uint64_t seqnum;
|
uint64_t seqnum;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -596,19 +595,12 @@ static int event_queue_insert(Manager *manager, sd_device *dev) {
|
||||||
assert(manager->pid == getpid_cached());
|
assert(manager->pid == getpid_cached());
|
||||||
|
|
||||||
/* We only accepts devices received by device monitor. */
|
/* We only accepts devices received by device monitor. */
|
||||||
r = sd_device_get_property_value(dev, "SEQNUM", &val);
|
r = device_get_seqnum(dev, &seqnum);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = safe_atou64(val, &seqnum);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
if (seqnum == 0)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/* Refuse devices do not have ACTION property. */
|
/* Refuse devices do not have ACTION property. */
|
||||||
r = sd_device_get_property_value(dev, "ACTION", &action);
|
r = device_get_action(dev, &action);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -641,7 +633,8 @@ static int event_queue_insert(Manager *manager, sd_device *dev) {
|
||||||
|
|
||||||
LIST_APPEND(event, manager->events, event);
|
LIST_APPEND(event, manager->events, event);
|
||||||
|
|
||||||
log_device_debug(dev, "Device (SEQNUM=%"PRIu64", ACTION=%s) is queued", seqnum, action);
|
log_device_debug(dev, "Device (SEQNUM=%"PRIu64", ACTION=%s) is queued",
|
||||||
|
seqnum, device_action_to_string(action));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,19 +21,19 @@ EOF
|
||||||
udevadm control --log-priority=debug --reload
|
udevadm control --log-priority=debug --reload
|
||||||
udevadm trigger --action=add --settle /sys/devices/virtual/net/lo
|
udevadm trigger --action=add --settle /sys/devices/virtual/net/lo
|
||||||
udevadm info /sys/devices/virtual/net/lo
|
udevadm info /sys/devices/virtual/net/lo
|
||||||
|
sleep 1
|
||||||
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
|
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
|
||||||
[[ $STATE == "active" ]] || exit 1
|
[[ $STATE == "active" ]] || exit 1
|
||||||
|
|
||||||
udevadm trigger --action=change --settle /sys/devices/virtual/net/lo
|
udevadm trigger --action=change --settle /sys/devices/virtual/net/lo
|
||||||
udevadm info /sys/devices/virtual/net/lo
|
udevadm info /sys/devices/virtual/net/lo
|
||||||
|
sleep 1
|
||||||
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
|
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
|
||||||
[[ $STATE == "inactive" ]] || exit 1
|
[[ $STATE == "inactive" ]] || exit 1
|
||||||
|
|
||||||
udevadm trigger --action=move --settle /sys/devices/virtual/net/lo
|
udevadm trigger --action=move --settle /sys/devices/virtual/net/lo
|
||||||
udevadm info /sys/devices/virtual/net/lo
|
udevadm info /sys/devices/virtual/net/lo
|
||||||
|
sleep 1
|
||||||
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
|
STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo.device)
|
||||||
[[ $STATE == "active" ]] || exit 1
|
[[ $STATE == "active" ]] || exit 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue