#include "fileio.h"
#include "fs-util.h"
#include "hashmap.h"
+#include "id128-util.h"
#include "macro.h"
#include "parse-util.h"
#include "path-util.h"
return 0;
}
+_public_ int sd_device_get_trigger_uuid(sd_device *device, sd_id128_t *ret) {
+ const char *s;
+ sd_id128_t id;
+ int r;
+
+ assert_return(device, -EINVAL);
+
+ /* Retrieves the UUID attached to a uevent when triggering it from userspace via
+ * sd_device_trigger_with_uuid() or an equivalent interface. Returns -ENOENT if the record is not
+ * caused by a synthetic event and -ENODATA if it was but no UUID was specified */
+
+ r = sd_device_get_property_value(device, "SYNTH_UUID", &s);
+ if (r < 0)
+ return r;
+
+ if (streq(s, "0")) /* SYNTH_UUID=0 is set whenever a device is triggered by userspace without specifying a UUID */
+ return -ENODATA;
+
+ r = sd_id128_from_string(s, &id);
+ if (r < 0)
+ return r;
+
+ if (ret)
+ *ret = id;
+
+ return 0;
+}
+
static int device_cache_sysattr_value(sd_device *device, const char *key, char *value) {
_cleanup_free_ char *new_key = NULL, *old_value = NULL;
int r;
if (!s)
return -EINVAL;
+ /* This uses the simple no-UUID interface of kernel < 4.13 */
return sd_device_set_sysattr_value(device, "uevent", s);
}
+
+_public_ int sd_device_trigger_with_uuid(
+ sd_device *device,
+ sd_device_action_t action,
+ sd_id128_t *ret_uuid) {
+
+ char buf[ID128_UUID_STRING_MAX];
+ const char *s, *j;
+ sd_id128_t u;
+ int r;
+
+ assert_return(device, -EINVAL);
+
+ /* If noone wants to know the UUID, use the simple interface from pre-4.13 times */
+ if (!ret_uuid)
+ return sd_device_trigger(device, action);
+
+ s = device_action_to_string(action);
+ if (!s)
+ return -EINVAL;
+
+ r = sd_id128_randomize(&u);
+ if (r < 0)
+ return r;
+
+ id128_to_uuid_string(u, buf);
+ j = strjoina(s, " ", buf);
+
+ r = sd_device_set_sysattr_value(device, "uevent", j);
+ if (r < 0)
+ return r;
+
+ *ret_uuid = u;
+ return 0;
+}
#include <sys/types.h>
#include "sd-event.h"
+#include "sd-id128.h"
#include "_sd-common.h"
int sd_device_has_tag(sd_device *device, const char *tag);
int sd_device_has_current_tag(sd_device *device, const char *tag);
int sd_device_get_property_value(sd_device *device, const char *key, const char **value);
+int sd_device_get_trigger_uuid(sd_device *device, sd_id128_t *ret);
int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value);
int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, const char *value);
int sd_device_set_sysattr_valuef(sd_device *device, const char *sysattr, const char *format, ...) _sd_printf_(3, 4);
int sd_device_trigger(sd_device *device, sd_device_action_t action);
+int sd_device_trigger_with_uuid(sd_device *device, sd_device_action_t action, sd_id128_t *ret_uuid);
/* device enumerator */