summaryrefslogtreecommitdiff
path: root/src/shared/udev-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-02-10 22:15:01 +0100
committerLennart Poettering <lennart@poettering.net>2021-02-18 18:20:56 +0100
commita11300221482da7ffe7be2d75d508ddd411814f6 (patch)
tree009163435be6a2878d026e70439d731a1587a6e9 /src/shared/udev-util.c
parent96fb82aa06f2edef153c0ecb1642783aac1c1c84 (diff)
downloadsystemd-a11300221482da7ffe7be2d75d508ddd411814f6.tar.gz
sd-device: add sd_device_get_action() + sd_device_get_seqnum() + sd_device_new_from_stat_rdev()
To make sd-device properly usable for all programs we need to provide an API for the "action" field of an event, it's one of the most relevant ones, and it was so far missing. This also adds sd_device_get_seqnum(), which isn't that interesting, except for generating pretty debug output, which we use it ourselves for. This also makes device_new_from_stat_rdev() public, as it is truly useful, as we can see in our own uses of it, and I think is fairly generic to show up in the public APIs.
Diffstat (limited to 'src/shared/udev-util.c')
-rw-r--r--src/shared/udev-util.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c
index 61decb80fa..3a3f0198fd 100644
--- a/src/shared/udev-util.c
+++ b/src/shared/udev-util.c
@@ -7,6 +7,7 @@
#include "alloc-util.h"
#include "device-nodes.h"
+#include "device-private.h"
#include "device-util.h"
#include "env-file.h"
#include "escape.h"
@@ -175,7 +176,7 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device,
* (And yes, we only need to special case REMOVE. It's the only "negative" event type, where a device
* ceases to exist. All other event types are "positive": the device exists and is registered in the
* udev database, thus whenever we see the event, we can consider it initialized.) */
- if (device_for_action(device, DEVICE_ACTION_REMOVE))
+ if (device_for_action(device, SD_DEVICE_REMOVE))
return 0;
if (data->sysname && sd_device_get_sysname(device, &sysname) >= 0 && streq(sysname, data->sysname))
@@ -318,26 +319,29 @@ int device_is_renaming(sd_device *dev) {
return true;
}
-bool device_for_action(sd_device *dev, DeviceAction action) {
- DeviceAction a;
+bool device_for_action(sd_device *dev, sd_device_action_t a) {
+ sd_device_action_t b;
assert(dev);
- if (device_get_action(dev, &a) < 0)
+ if (a < 0)
return false;
- return a == action;
+ if (sd_device_get_action(dev, &b) < 0)
+ return false;
+
+ return a == b;
}
void log_device_uevent(sd_device *device, const char *str) {
- DeviceAction action = _DEVICE_ACTION_INVALID;
+ sd_device_action_t action = _SD_DEVICE_ACTION_INVALID;
uint64_t seqnum = 0;
if (!DEBUG_LOGGING)
return;
- (void) device_get_seqnum(device, &seqnum);
- (void) device_get_action(device, &action);
+ (void) sd_device_get_seqnum(device, &seqnum);
+ (void) sd_device_get_action(device, &action);
log_device_debug(device, "%s%s(SEQNUM=%"PRIu64", ACTION=%s)",
strempty(str), isempty(str) ? "" : " ",
seqnum, strna(device_action_to_string(action)));