desc = path;
- if (dev &&
- (sd_device_get_property_value(dev, "ID_MODEL_FROM_DATABASE", &model) >= 0 ||
- sd_device_get_property_value(dev, "ID_MODEL", &model) >= 0)) {
+ if (dev && device_get_model_string(dev, &model) >= 0) {
desc = model;
/* Try to concatenate the device model string with a label, if there is one */
#include "stat-util.h"
#include "strv.h"
#include "terminal-util.h"
+#include "udev-util.h"
#include "umask-util.h"
#include "unit-def.h"
#include "unit-name.h"
return 1;
}
-static const char *get_model(sd_device *d) {
- const char *model;
-
- assert(d);
-
- if (sd_device_get_property_value(d, "ID_MODEL_FROM_DATABASE", &model) >= 0)
- return model;
-
- if (sd_device_get_property_value(d, "ID_MODEL", &model) >= 0)
- return model;
-
- return NULL;
-}
-
static const char* get_label(sd_device *d) {
const char *label;
name = get_label(d);
if (!name)
- name = get_model(d);
+ (void) device_get_model_string(d, &name);
if (!name) {
const char *dn;
}
static int acquire_description(sd_device *d) {
- const char *model, *label;
+ const char *model = NULL, *label;
if (arg_description)
return 0;
- model = get_model(d);
+ (void) device_get_model_string(d, &model);
label = get_label(d);
if (!label)
break;
case COLUMN_MODEL:
- x = get_model(d);
+ (void) device_get_model_string(d, &x);
break;
case COLUMN_WWN:
#include "strv.h"
#include "strxcpyx.h"
#include "terminal-util.h"
+#include "udev-util.h"
#include "unit-def.h"
#include "verbs.h"
#include "virt.h"
(void) sd_device_get_property_value(info->sd_device, "ID_NET_DRIVER", &driver);
(void) sd_device_get_property_value(info->sd_device, "ID_PATH", &path);
-
- if (sd_device_get_property_value(info->sd_device, "ID_VENDOR_FROM_DATABASE", &vendor) < 0)
- (void) sd_device_get_property_value(info->sd_device, "ID_VENDOR", &vendor);
-
- if (sd_device_get_property_value(info->sd_device, "ID_MODEL_FROM_DATABASE", &model) < 0)
- (void) sd_device_get_property_value(info->sd_device, "ID_MODEL", &model);
+ (void) device_get_vendor_string(info->sd_device, &vendor);
+ (void) device_get_model_string(info->sd_device, &model);
}
r = net_get_type_string(info->sd_device, info->iftype, &t);
#include "networkd-link.h"
#include "networkd-manager.h"
#include "networkd-neighbor.h"
-#include "networkd-nexthop.h"
#include "networkd-network.h"
+#include "networkd-nexthop.h"
#include "networkd-route-util.h"
#include "networkd-route.h"
#include "networkd-routing-policy-rule.h"
#include "sort-util.h"
+#include "udev-util.h"
#include "user-util.h"
#include "wifi-util.h"
(void) sd_device_get_property_value(device, "ID_PATH", &path);
- if (sd_device_get_property_value(device, "ID_VENDOR_FROM_DATABASE", &vendor) < 0)
- (void) sd_device_get_property_value(device, "ID_VENDOR", &vendor);
-
- if (sd_device_get_property_value(device, "ID_MODEL_FROM_DATABASE", &model) < 0)
- (void) sd_device_get_property_value(device, "ID_MODEL", &model);
+ (void) device_get_vendor_string(device, &vendor);
+ (void) device_get_model_string(device, &model);
return json_variant_merge_objectb(
v,
return (cache = (path_is_read_only_fs("/sys/") <= 0));
}
+
+int device_get_vendor_string(sd_device *device, const char **ret) {
+ int r;
+
+ assert(device);
+
+ FOREACH_STRING(field, "ID_VENDOR_FROM_DATABASE", "ID_VENDOR") {
+ r = sd_device_get_property_value(device, field, ret);
+ if (r != -ENOENT)
+ return r;
+ }
+
+ return -ENOENT;
+}
+
+int device_get_model_string(sd_device *device, const char **ret) {
+ int r;
+
+ assert(device);
+
+ FOREACH_STRING(field, "ID_MODEL_FROM_DATABASE", "ID_MODEL") {
+ r = sd_device_get_property_value(device, field, ret);
+ if (r != -ENOENT)
+ return r;
+ }
+
+ return -ENOENT;
+}
int udev_queue_is_empty(void);
bool udev_available(void);
+
+int device_get_vendor_string(sd_device *device, const char **ret);
+int device_get_model_string(sd_device *device, const char **ret);
#include "build.h"
#include "cgroup-util.h"
#include "conf-parser.h"
-#include "devnum-util.h"
#include "device-util.h"
+#include "devnum-util.h"
#include "main-func.h"
#include "path-util.h"
#include "pretty-print.h"
+#include "udev-util.h"
#include "verbs.h"
static char *arg_target_solution = NULL;
if (r < 0)
return log_error_errno(r, "Error looking up device: %m");
- r = sd_device_get_property_value(device, "ID_MODEL_FROM_DATABASE", &model_name);
+ r = device_get_model_string(device, &model_name);
if (r == -ENOENT) {
- log_device_debug(device, "Missing ID_MODEL_FROM_DATABASE property, trying ID_MODEL");
- r = sd_device_get_property_value(device, "ID_MODEL", &model_name);
- if (r == -ENOENT) {
- log_device_info(device, "Device model not found");
- return 0;
- }
+ log_device_info(device, "Device model not found");
+ return 0;
}
if (r < 0)
return log_device_error_errno(device, r, "Model name for device %s is unknown", path);