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