Merge pull request #18546 from poettering/sd-device-action
export sd_device_get_action() API + more
This commit is contained in:
@@ -745,4 +745,8 @@ global:
|
||||
sd_event_source_set_ratelimit;
|
||||
sd_event_source_get_ratelimit;
|
||||
sd_event_source_is_ratelimited;
|
||||
|
||||
sd_device_get_action;
|
||||
sd_device_get_seqnum;
|
||||
sd_device_new_from_stat_rdev;
|
||||
} LIBSYSTEMD_247;
|
||||
|
||||
@@ -76,7 +76,7 @@ struct sd_device {
|
||||
gid_t devgid;
|
||||
|
||||
/* only set when device is passed through netlink */
|
||||
DeviceAction action;
|
||||
sd_device_action_t action;
|
||||
uint64_t seqnum;
|
||||
|
||||
bool parent_set:1; /* no need to try to reload parent */
|
||||
|
||||
@@ -183,20 +183,8 @@ static int device_set_devgid(sd_device *device, const char *gid) {
|
||||
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;
|
||||
sd_device_action_t a;
|
||||
int r;
|
||||
|
||||
assert(device);
|
||||
@@ -206,7 +194,7 @@ static int device_set_action(sd_device *device, const char *action) {
|
||||
if (a < 0)
|
||||
return a;
|
||||
|
||||
r = device_add_property_internal(device, "ACTION", action);
|
||||
r = device_add_property_internal(device, "ACTION", device_action_to_string(a));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -215,18 +203,6 @@ static int device_set_action(sd_device *device, const char *action) {
|
||||
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;
|
||||
@@ -355,7 +331,12 @@ static int device_amend(sd_device *device, const char *key, const char *value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int device_append(sd_device *device, char *key, const char **_major, const char **_minor) {
|
||||
static int device_append(
|
||||
sd_device *device,
|
||||
char *key,
|
||||
const char **_major,
|
||||
const char **_minor) {
|
||||
|
||||
const char *major = NULL, *minor = NULL;
|
||||
char *value;
|
||||
int r;
|
||||
@@ -384,10 +365,10 @@ static int device_append(sd_device *device, char *key, const char **_major, cons
|
||||
return r;
|
||||
}
|
||||
|
||||
if (major != 0)
|
||||
if (major)
|
||||
*_major = major;
|
||||
|
||||
if (minor != 0)
|
||||
if (minor)
|
||||
*_minor = minor;
|
||||
|
||||
return 0;
|
||||
@@ -719,22 +700,6 @@ int device_new_from_synthetic_event(sd_device **new_device, const char *syspath,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device_new_from_stat_rdev(sd_device **ret, const struct stat *st) {
|
||||
char type;
|
||||
|
||||
assert(ret);
|
||||
assert(st);
|
||||
|
||||
if (S_ISBLK(st->st_mode))
|
||||
type = 'b';
|
||||
else if (S_ISCHR(st->st_mode))
|
||||
type = 'c';
|
||||
else
|
||||
return -ENOTTY;
|
||||
|
||||
return sd_device_new_from_devnum(ret, type, st->st_rdev);
|
||||
}
|
||||
|
||||
int device_copy_properties(sd_device *device_dst, sd_device *device_src) {
|
||||
const char *property, *value;
|
||||
int r;
|
||||
@@ -998,19 +963,19 @@ int device_delete_db(sd_device *device) {
|
||||
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",
|
||||
static const char* const device_action_table[_SD_DEVICE_ACTION_MAX] = {
|
||||
[SD_DEVICE_ADD] = "add",
|
||||
[SD_DEVICE_REMOVE] = "remove",
|
||||
[SD_DEVICE_CHANGE] = "change",
|
||||
[SD_DEVICE_MOVE] = "move",
|
||||
[SD_DEVICE_ONLINE] = "online",
|
||||
[SD_DEVICE_OFFLINE] = "offline",
|
||||
[SD_DEVICE_BIND] = "bind",
|
||||
[SD_DEVICE_UNBIND] = "unbind",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(device_action, DeviceAction);
|
||||
DEFINE_STRING_TABLE_LOOKUP(device_action, sd_device_action_t);
|
||||
|
||||
void dump_device_action_table(void) {
|
||||
DUMP_STRING_TABLE(device_action, DeviceAction, _DEVICE_ACTION_MAX);
|
||||
DUMP_STRING_TABLE(device_action, sd_device_action_t, _SD_DEVICE_ACTION_MAX);
|
||||
}
|
||||
|
||||
@@ -10,22 +10,8 @@
|
||||
|
||||
#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 = -EINVAL,
|
||||
} DeviceAction;
|
||||
|
||||
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_stat_rdev(sd_device **ret, const struct stat *st);
|
||||
|
||||
int device_get_id_filename(sd_device *device, const char **ret);
|
||||
|
||||
@@ -34,8 +20,6 @@ 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_uid(sd_device *device, uid_t *uid);
|
||||
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_set_is_initialized(sd_device *device);
|
||||
@@ -73,6 +57,6 @@ static inline int device_read_db(sd_device *device) {
|
||||
return device_read_db_internal(device, false);
|
||||
}
|
||||
|
||||
DeviceAction device_action_from_string(const char *s) _pure_;
|
||||
const char *device_action_to_string(DeviceAction a) _const_;
|
||||
sd_device_action_t device_action_from_string(const char *s) _pure_;
|
||||
const char *device_action_to_string(sd_device_action_t a) _const_;
|
||||
void dump_device_action_table(void);
|
||||
|
||||
@@ -43,7 +43,7 @@ int device_new_aux(sd_device **ret) {
|
||||
.devmode = (mode_t) -1,
|
||||
.devuid = (uid_t) -1,
|
||||
.devgid = (gid_t) -1,
|
||||
.action = _DEVICE_ACTION_INVALID,
|
||||
.action = _SD_DEVICE_ACTION_INVALID,
|
||||
};
|
||||
|
||||
*ret = device;
|
||||
@@ -316,6 +316,22 @@ _public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *s
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
_public_ int sd_device_new_from_stat_rdev(sd_device **ret, const struct stat *st) {
|
||||
char type;
|
||||
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return(st, -EINVAL);
|
||||
|
||||
if (S_ISBLK(st->st_mode))
|
||||
type = 'b';
|
||||
else if (S_ISCHR(st->st_mode))
|
||||
type = 'c';
|
||||
else
|
||||
return -ENOTTY;
|
||||
|
||||
return sd_device_new_from_devnum(ret, type, st->st_rdev);
|
||||
}
|
||||
|
||||
int device_set_devtype(sd_device *device, const char *devtype) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
int r;
|
||||
@@ -1052,6 +1068,30 @@ _public_ int sd_device_get_sysnum(sd_device *device, const char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_device_get_action(sd_device *device, sd_device_action_t *ret) {
|
||||
assert_return(device, -EINVAL);
|
||||
|
||||
if (device->action < 0)
|
||||
return -ENOENT;
|
||||
|
||||
if (ret)
|
||||
*ret = device->action;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_device_get_seqnum(sd_device *device, uint64_t *ret) {
|
||||
assert_return(device, -EINVAL);
|
||||
|
||||
if (device->seqnum == 0)
|
||||
return -ENOENT;
|
||||
|
||||
if (ret)
|
||||
*ret = device->seqnum;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool is_valid_tag(const char *tag) {
|
||||
assert(tag);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user