summaryrefslogtreecommitdiffstats
path: root/src/hostname
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2024-03-15 13:20:15 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2024-03-20 15:13:44 +0100
commitd3a3d2d328af63dce207146c58df72911f6fd8a4 (patch)
treea970dcd73e8356fc4795552babc41b40335ccd2e /src/hostname
parentsrc/basic: add yet another strdup helper (diff)
downloadsystemd-d3a3d2d328af63dce207146c58df72911f6fd8a4.tar.xz
systemd-d3a3d2d328af63dce207146c58df72911f6fd8a4.zip
hostnamed: use strdup_to_full()
Diffstat (limited to 'src/hostname')
-rw-r--r--src/hostname/hostnamed.c31
1 files changed, 2 insertions, 29 deletions
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 83a988154f..82d08803fa 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -211,7 +211,6 @@ static bool use_dmi_data(void) {
static int get_dmi_data(const char *database_key, const char *regular_key, char **ret) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
- _cleanup_free_ char *b = NULL;
const char *s = NULL;
int r;
@@ -227,17 +226,7 @@ static int get_dmi_data(const char *database_key, const char *regular_key, char
if (!s && regular_key)
(void) sd_device_get_property_value(device, regular_key, &s);
- if (!ret)
- return !!s;
-
- if (s) {
- b = strdup(s);
- if (!b)
- return -ENOMEM;
- }
-
- *ret = TAKE_PTR(b);
- return !!s;
+ return strdup_to_full(ret, s);
}
static int get_hardware_vendor(char **ret) {
@@ -264,23 +253,7 @@ static int get_hardware_firmware_data(const char *sysattr, char **ret) {
(void) sd_device_get_sysattr_value(device, sysattr, &s);
- bool empty = isempty(s);
-
- if (ret) {
- if (empty)
- *ret = NULL;
- else {
- _cleanup_free_ char *b = NULL;
-
- b = strdup(s);
- if (!b)
- return -ENOMEM;
-
- *ret = TAKE_PTR(b);
- }
- }
-
- return !empty;
+ return strdup_to_full(ret, empty_to_null(s));
}
static int get_hardware_serial(char **ret) {