1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

Merge pull request #30003 from poettering/vendor-model-unify

udev-util: add generic device_get_{vendor,model}_string() helpers
This commit is contained in:
Yu Watanabe 2023-11-14 02:36:08 +09:00 committed by GitHub
commit 175ff7bf0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 43 deletions

View File

@ -27,8 +27,8 @@ jobs:
env:
- { COMPILER: "gcc", COMPILER_VERSION: "11", LINKER: "bfd", CRYPTOLIB: "gcrypt" }
- { COMPILER: "gcc", COMPILER_VERSION: "13", LINKER: "mold", CRYPTOLIB: "openssl" }
- { COMPILER: "clang", COMPILER_VERSION: "14", LINKER: "bfd", CRYPTOLIB: "gcrypt" }
- { COMPILER: "clang", COMPILER_VERSION: "15", LINKER: "mold", CRYPTOLIB: "openssl" }
- { COMPILER: "clang", COMPILER_VERSION: "14", LINKER: "mold", CRYPTOLIB: "gcrypt" }
- { COMPILER: "clang", COMPILER_VERSION: "15", LINKER: "bfd", CRYPTOLIB: "openssl" }
- { COMPILER: "clang", COMPILER_VERSION: "17", LINKER: "lld", CRYPTOLIB: "auto" }
env: ${{ matrix.env }}
steps:

View File

@ -516,9 +516,7 @@ static int device_update_description(Unit *u, sd_device *dev, const char *path)
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 */

View File

@ -35,6 +35,7 @@
#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"
@ -1133,20 +1134,6 @@ static int acquire_mount_options(sd_device *d) {
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;
@ -1174,7 +1161,7 @@ static int acquire_mount_where(sd_device *d) {
name = get_label(d);
if (!name)
name = get_model(d);
(void) device_get_model_string(d, &name);
if (!name) {
const char *dn;
@ -1240,12 +1227,12 @@ static int acquire_mount_where_for_loop_dev(sd_device *dev) {
}
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)
@ -1466,7 +1453,7 @@ static int list_devices(void) {
break;
case COLUMN_MODEL:
x = get_model(d);
(void) device_get_model_string(d, &x);
break;
case COLUMN_WWN:

View File

@ -69,6 +69,7 @@
#include "strv.h"
#include "strxcpyx.h"
#include "terminal-util.h"
#include "udev-util.h"
#include "unit-def.h"
#include "verbs.h"
#include "virt.h"
@ -1722,12 +1723,8 @@ static int link_status_one(
(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);

View File

@ -14,12 +14,13 @@
#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"
@ -407,11 +408,8 @@ static int device_append_json(sd_device *device, JsonVariant **v) {
(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,

View File

@ -382,3 +382,31 @@ bool udev_available(void) {
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;
}

View File

@ -22,3 +22,6 @@ size_t udev_replace_chars(char *str, const char *allow);
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);

View File

@ -11,11 +11,12 @@
#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;
@ -248,14 +249,10 @@ static int query_solutions_for_path(const char *path) {
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);