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