daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
da2bf9
From bbfebb42c9023e36fb66f0e3b0bad132ab2fba55 Mon Sep 17 00:00:00 2001
da2bf9
From: Yu Watanabe <watanabe.yu+github@gmail.com>
da2bf9
Date: Sun, 15 Dec 2019 21:47:21 +0900
da2bf9
Subject: [PATCH] sd-netlink: introduce sd_netlink_message_append_strv()
da2bf9
da2bf9
(cherry picked from commit 6d725977c4f98a8f5effc33f44aa646cc2b6a0b7)
da2bf9
da2bf9
Related: #2005008
da2bf9
---
da2bf9
 src/libsystemd/sd-netlink/netlink-message.c | 29 +++++++++++++++++++++
da2bf9
 src/systemd/sd-netlink.h                    |  1 +
da2bf9
 2 files changed, 30 insertions(+)
da2bf9
da2bf9
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c
da2bf9
index 5723e1d21c..55d6510b63 100644
da2bf9
--- a/src/libsystemd/sd-netlink/netlink-message.c
da2bf9
+++ b/src/libsystemd/sd-netlink/netlink-message.c
da2bf9
@@ -259,6 +259,35 @@ int sd_netlink_message_append_string(sd_netlink_message *m, unsigned short type,
da2bf9
         return 0;
da2bf9
 }
da2bf9
 
da2bf9
+int sd_netlink_message_append_strv(sd_netlink_message *m, unsigned short type, char * const *data) {
da2bf9
+        size_t length, size;
da2bf9
+        char * const *p;
da2bf9
+        int r;
da2bf9
+
da2bf9
+        assert_return(m, -EINVAL);
da2bf9
+        assert_return(!m->sealed, -EPERM);
da2bf9
+        assert_return(data, -EINVAL);
da2bf9
+
da2bf9
+        r = message_attribute_has_type(m, &size, type, NETLINK_TYPE_STRING);
da2bf9
+        if (r < 0)
da2bf9
+                return r;
da2bf9
+
da2bf9
+        STRV_FOREACH(p, data) {
da2bf9
+                if (size) {
da2bf9
+                        length = strnlen(*p, size+1);
da2bf9
+                        if (length > size)
da2bf9
+                                return -EINVAL;
da2bf9
+                } else
da2bf9
+                        length = strlen(*p);
da2bf9
+
da2bf9
+                r = add_rtattr(m, type, *p, length + 1);
da2bf9
+                if (r < 0)
da2bf9
+                        return r;
da2bf9
+        }
da2bf9
+
da2bf9
+        return 0;
da2bf9
+}
da2bf9
+
da2bf9
 int sd_netlink_message_append_flag(sd_netlink_message *m, unsigned short type) {
da2bf9
         size_t size;
da2bf9
         int r;
da2bf9
diff --git a/src/systemd/sd-netlink.h b/src/systemd/sd-netlink.h
da2bf9
index 1f5c093f11..5a05cd4485 100644
da2bf9
--- a/src/systemd/sd-netlink.h
da2bf9
+++ b/src/systemd/sd-netlink.h
da2bf9
@@ -67,6 +67,7 @@ int sd_netlink_attach_event(sd_netlink *nl, sd_event *e, int64_t priority);
da2bf9
 int sd_netlink_detach_event(sd_netlink *nl);
da2bf9
 
da2bf9
 int sd_netlink_message_append_string(sd_netlink_message *m, unsigned short type, const char *data);
da2bf9
+int sd_netlink_message_append_strv(sd_netlink_message *m, unsigned short type, char * const *data);
da2bf9
 int sd_netlink_message_append_flag(sd_netlink_message *m, unsigned short type);
da2bf9
 int sd_netlink_message_append_u8(sd_netlink_message *m, unsigned short type, uint8_t data);
da2bf9
 int sd_netlink_message_append_u16(sd_netlink_message *m, unsigned short type, uint16_t data);