#include "build-path.h"
#include "bus-common-errors.h"
#include "bus-locator.h"
+#include "device-util.h"
#include "env-util.h"
#include "errno-list.h"
#include "errno-util.h"
if (r < 0)
return r;
- r = sd_device_get_property_value(d, "ID_SEAT", &seat);
- if (r == -ENOENT) /* no property means seat0 */
- seat = "seat0";
- else if (r < 0)
+ r = device_get_seat(d, &seat);
+ if (r < 0)
return r;
return strdup_to(ret, seat);
return !!suffix;
}
+int device_get_seat(sd_device *device, const char **ret) {
+ const char *seat = NULL;
+ int r;
+
+ assert(device);
+ assert(ret);
+
+ r = sd_device_get_property_value(device, "ID_SEAT", &seat);
+ if (r < 0 && r != -ENOENT)
+ return r;
+
+ *ret = isempty(seat) ? "seat0" : seat;
+ return 0;
+}
+
bool device_property_can_set(const char *property) {
return property &&
!STR_IN_SET(property,
int device_is_subsystem_devtype(sd_device *device, const char *subsystem, const char *devtype);
+int device_get_seat(sd_device *device, const char **ret);
+
int device_sysname_startswith_strv(sd_device *device, char * const *prefixes, const char **ret_suffix);
#define device_sysname_startswith(device, ...) \
device_sysname_startswith_strv(device, STRV_MAKE(__VA_ARGS__), NULL)
bool master;
Seat *seat;
- if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn))
- sn = "seat0";
+ r = device_get_seat(d, &sn);
+ if (r < 0)
+ return r;
if (!seat_name_is_valid(sn)) {
log_device_warning(d, "Device with invalid seat name %s found, ignoring.", sn);
if (r < 0)
return r;
- if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn))
- sn = "seat0";
+ r = device_get_seat(d, &sn);
+ if (r < 0)
+ return r;
button_set_seat(b, sn);
#include "bus-label.h"
#include "bus-polkit.h"
#include "bus-util.h"
+#include "device-util.h"
#include "devnum-util.h"
#include "fd-util.h"
#include "format-util.h"
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to open device %s:%s: %m", subsystem, name);
- if (sd_device_get_property_value(d, "ID_SEAT", &seat) >= 0 && !streq_ptr(seat, s->seat->id))
+ r = device_get_seat(d, &seat);
+ if (r < 0)
+ return sd_bus_error_set_errnof(error, r, "Failed to get seat of %s:%s: %m", subsystem, name);
+ if (!streq(seat, s->seat->id))
return sd_bus_error_setf(error, BUS_ERROR_NOT_YOUR_DEVICE, "Device %s:%s does not belong to your seat %s, refusing.", subsystem, name, s->seat->id);
r = manager_write_brightness(s->manager, d, brightness, message);
#include "alloc-util.h"
#include "device-enumerator-private.h"
+#include "device-util.h"
#include "glyph-util.h"
#include "path-util.h"
#include "string-util.h"
!path_startswith(sysfs, sub))
return 0;
- if (sd_device_get_property_value(dev_list[*i_dev], "ID_SEAT", &sn) < 0 || isempty(sn))
- sn = "seat0";
+ r = device_get_seat(dev_list[*i_dev], &sn);
+ if (r < 0)
+ return r;
/* Explicitly also check for tag 'seat' here */
if (!streq(seat, sn) ||
!path_startswith(lookahead_sysfs, sysfs)) {
const char *lookahead_sn;
- if (sd_device_get_property_value(dev_list[lookahead], "ID_SEAT", &lookahead_sn) < 0 ||
- isempty(lookahead_sn))
- lookahead_sn = "seat0";
+ r = device_get_seat(dev_list[lookahead], &lookahead_sn);
+ if (r < 0)
+ return r;
if (streq(seat, lookahead_sn) && sd_device_has_current_tag(dev_list[lookahead], "seat") > 0)
break;
if (sd_device_has_current_tag(d, "uaccess") <= 0)
continue;
- if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn))
- sn = "seat0";
+ r = device_get_seat(d, &sn);
+ if (r < 0)
+ return r;
if (!streq(seat, sn))
continue;
return log_device_error_errno(dev, r, "Failed to get device node: %m");
const char *seat;
- if (sd_device_get_property_value(dev, "ID_SEAT", &seat) < 0)
- seat = "seat0";
+ r = device_get_seat(dev, &seat);
+ if (r < 0)
+ return log_device_error_errno(dev, r, "Failed to get seat: %m");
uid_t uid;
r = sd_seat_get_active(seat, /* ret_session = */ NULL, &uid);