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