[PATCH] genl: Add utility function no append nested attribute into a message
by Tomasz Bursztyka
It will fill-in a l_genl_attr structure with the necessary information
where the nested attribute starts. Thus at the end, it will update the
nested attribute with the final length.
---
ell/genl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
ell/genl.h | 3 +++
2 files changed, 51 insertions(+)
diff --git a/ell/genl.c b/ell/genl.c
index 2ef6a34..b74f3c0 100644
--- a/ell/genl.c
+++ b/ell/genl.c
@@ -707,6 +707,54 @@ bool l_genl_msg_append_attr(struct l_genl_msg *msg, uint16_t type,
return true;
}
+bool l_genl_msg_append_init_recurse(struct l_genl_msg *msg, uint16_t type,
+ struct l_genl_attr *nested)
+{
+ struct nlattr *nla;
+
+ if (!msg || !nested)
+ return false;
+
+ nla = msg->data + msg->len;
+ nla->nla_len = NLA_HDRLEN;
+ nla->nla_type = type;
+
+ if (!l_genl_msg_append_attr(msg, type, 0, NULL))
+ return false;
+
+ nested->msg = msg;
+ nested->data = nla;
+ nested->len = 0;
+ nested->next_data = NULL;
+ nested->next_len = 0;
+
+ return true;
+}
+
+bool l_genl_msg_append_end_recurse(struct l_genl_attr *nested)
+{
+ struct l_genl_msg *msg;
+ struct nlattr *nla;
+ uint32_t len;
+
+ if (!nested || !nested->msg)
+ return false;
+
+ msg = nested->msg;
+ len = nested->data - msg->data;
+ nla = msg->data + len;
+
+ len = msg->len - len;
+ if (len <= NLA_HDRLEN)
+ return false;
+
+ nla->nla_len = len;
+
+ msg->len = NLA_ALIGN(msg->len);
+
+ return true;
+}
+
#define NLA_OK(nla,len) ((len) >= (int) sizeof(struct nlattr) && \
(nla)->nla_len >= sizeof(struct nlattr) && \
(nla)->nla_len <= (len))
diff --git a/ell/genl.h b/ell/genl.h
index c628b8c..13fe149 100644
--- a/ell/genl.h
+++ b/ell/genl.h
@@ -71,6 +71,9 @@ int l_genl_msg_get_error(struct l_genl_msg *msg);
bool l_genl_msg_append_attr(struct l_genl_msg *msg, uint16_t type,
uint16_t len, const void *data);
+bool l_genl_msg_append_init_recurse(struct l_genl_msg *msg, uint16_t type,
+ struct l_genl_attr *nested);
+bool l_genl_msg_append_end_recurse(struct l_genl_attr *nested);
bool l_genl_attr_init(struct l_genl_attr *attr, struct l_genl_msg *msg);
bool l_genl_attr_next(struct l_genl_attr *attr, uint16_t *type,
--
2.0.5
7 years, 4 months
[PATCH_v2] genl: Introduce new api
by Ravi kumar Veeramally
Introducing l_genl_family_send_and_unref, l_genl_family_dump_and_unref
wrapper functions for l_genl_family_send and l_genl_family_dump
but it unref the message no matter of what the result is.
---
ell/genl.c | 28 ++++++++++++++++++++++++++++
ell/genl.h | 10 ++++++++++
2 files changed, 38 insertions(+)
diff --git a/ell/genl.c b/ell/genl.c
index 2ef6a34..e84d801 100644
--- a/ell/genl.c
+++ b/ell/genl.c
@@ -1091,6 +1091,20 @@ unsigned int l_genl_family_send(struct l_genl_family *family,
user_data, destroy);
}
+unsigned int l_genl_family_send_and_unref(struct l_genl_family *family,
+ struct l_genl_msg *msg,
+ l_genl_msg_func_t callback,
+ void *user_data,
+ l_genl_destroy_func_t destroy)
+{
+ unsigned int id;
+
+ id = l_genl_family_send(family, msg, callback, user_data, destroy);
+ l_genl_msg_unref(msg);
+
+ return id;
+}
+
unsigned int l_genl_family_dump(struct l_genl_family *family,
struct l_genl_msg *msg, l_genl_msg_func_t callback,
void *user_data, l_genl_destroy_func_t destroy)
@@ -1099,6 +1113,20 @@ unsigned int l_genl_family_dump(struct l_genl_family *family,
user_data, destroy);
}
+unsigned int l_genl_family_dump_and_unref(struct l_genl_family *family,
+ struct l_genl_msg *msg,
+ l_genl_msg_func_t callback,
+ void *user_data,
+ l_genl_destroy_func_t destroy)
+{
+ unsigned int id;
+
+ id = l_genl_family_dump(family, msg, callback, user_data, destroy);
+ l_genl_msg_unref(msg);
+
+ return id;
+}
+
static bool match_request_id(const void *a, const void *b)
{
const struct genl_request *request = a;
diff --git a/ell/genl.h b/ell/genl.h
index c628b8c..1f58a94 100644
--- a/ell/genl.h
+++ b/ell/genl.h
@@ -101,9 +101,19 @@ bool l_genl_family_can_dump(struct l_genl_family *family, uint8_t cmd);
unsigned int l_genl_family_send(struct l_genl_family *family,
struct l_genl_msg *msg, l_genl_msg_func_t callback,
void *user_data, l_genl_destroy_func_t destroy);
+unsigned int l_genl_family_send_and_unref(struct l_genl_family *family,
+ struct l_genl_msg *msg,
+ l_genl_msg_func_t callback,
+ void *user_data,
+ l_genl_destroy_func_t destroy);
unsigned int l_genl_family_dump(struct l_genl_family *family,
struct l_genl_msg *msg, l_genl_msg_func_t callback,
void *user_data, l_genl_destroy_func_t destroy);
+unsigned int l_genl_family_dump_and_unref(struct l_genl_family *family,
+ struct l_genl_msg *msg,
+ l_genl_msg_func_t callback,
+ void *user_data,
+ l_genl_destroy_func_t destroy);
bool l_genl_family_cancel(struct l_genl_family *family, unsigned int id);
bool l_genl_family_has_group(struct l_genl_family *family, const char *group);
--
2.1.0
7 years, 4 months
[PATCH] genl: Introduce new api
by Ravi kumar Veeramally
Introducing l_genl_family_send_and_unref, l_genl_family_dump_and_unref
wrapper functions for l_genl_family_send and l_genl_family_dump
but it unref the message no matter of what the result is.
---
ell/genl.c | 30 ++++++++++++++++++++++++++++++
ell/genl.h | 10 ++++++++++
2 files changed, 40 insertions(+)
diff --git a/ell/genl.c b/ell/genl.c
index 2ef6a34..97eac85 100644
--- a/ell/genl.c
+++ b/ell/genl.c
@@ -1091,6 +1091,21 @@ unsigned int l_genl_family_send(struct l_genl_family *family,
user_data, destroy);
}
+unsigned int l_genl_family_send_and_unref(struct l_genl_family *family,
+ struct l_genl_msg *msg,
+ l_genl_msg_func_t callback,
+ void *user_data,
+ l_genl_destroy_func_t destroy)
+{
+ unsigned int id;
+
+ id = l_genl_family_send(family, msg, callback, user_data, destroy);
+ l_genl_msg_unref(msg);
+ msg = NULL;
+
+ return id;
+}
+
unsigned int l_genl_family_dump(struct l_genl_family *family,
struct l_genl_msg *msg, l_genl_msg_func_t callback,
void *user_data, l_genl_destroy_func_t destroy)
@@ -1099,6 +1114,21 @@ unsigned int l_genl_family_dump(struct l_genl_family *family,
user_data, destroy);
}
+unsigned int l_genl_family_dump_and_unref(struct l_genl_family *family,
+ struct l_genl_msg *msg,
+ l_genl_msg_func_t callback,
+ void *user_data,
+ l_genl_destroy_func_t destroy)
+{
+ unsigned int id;
+
+ id = l_genl_family_dump(family, msg, callback, user_data, destroy);
+ l_genl_msg_unref(msg);
+ msg = NULL;
+
+ return id;
+}
+
static bool match_request_id(const void *a, const void *b)
{
const struct genl_request *request = a;
diff --git a/ell/genl.h b/ell/genl.h
index c628b8c..1f58a94 100644
--- a/ell/genl.h
+++ b/ell/genl.h
@@ -101,9 +101,19 @@ bool l_genl_family_can_dump(struct l_genl_family *family, uint8_t cmd);
unsigned int l_genl_family_send(struct l_genl_family *family,
struct l_genl_msg *msg, l_genl_msg_func_t callback,
void *user_data, l_genl_destroy_func_t destroy);
+unsigned int l_genl_family_send_and_unref(struct l_genl_family *family,
+ struct l_genl_msg *msg,
+ l_genl_msg_func_t callback,
+ void *user_data,
+ l_genl_destroy_func_t destroy);
unsigned int l_genl_family_dump(struct l_genl_family *family,
struct l_genl_msg *msg, l_genl_msg_func_t callback,
void *user_data, l_genl_destroy_func_t destroy);
+unsigned int l_genl_family_dump_and_unref(struct l_genl_family *family,
+ struct l_genl_msg *msg,
+ l_genl_msg_func_t callback,
+ void *user_data,
+ l_genl_destroy_func_t destroy);
bool l_genl_family_cancel(struct l_genl_family *family, unsigned int id);
bool l_genl_family_has_group(struct l_genl_family *family, const char *group);
--
2.1.0
7 years, 4 months
[RFC] genl: Add utility function no append nested attribute into a message
by Tomasz Bursztyka
It will fill-in a l_genl_attr structure with the necessary information
where the nested attribute starts. Thus at the end, it will update the
nested attribute with the final length.
---
ell/genl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
ell/genl.h | 3 +++
2 files changed, 51 insertions(+)
diff --git a/ell/genl.c b/ell/genl.c
index 2ef6a34..5484d33 100644
--- a/ell/genl.c
+++ b/ell/genl.c
@@ -707,6 +707,54 @@ bool l_genl_msg_append_attr(struct l_genl_msg *msg, uint16_t type,
return true;
}
+bool l_genl_msg_append_init_recurse(struct l_genl_msg *msg, uint16_t type,
+ struct l_genl_attr *nested)
+{
+ struct nlattr *nla;
+
+ if (!msg || !nested)
+ return false;
+
+ nla = msg->data + msg->len;
+ nla->nla_len = NLA_HDRLEN;
+ nla->nla_type = type;
+
+ if (!l_genl_msg_append_attr(msg, type, 0, NULL))
+ return false;
+
+ nested->msg = msg;
+ nested->data = nla;
+ nested->len = 0;
+ nested->next_data = NULL;
+ nested->next_len = 0;
+
+ return true;
+}
+
+bool l_genl_msg_append_end_recurse(struct l_genl_attr *nested)
+{
+ struct l_genl_msg *msg;
+ struct nlattr *nla;
+ uint32_t len;
+
+ if (!nested || !nested->msg)
+ return false;
+
+ msg = nested->msg;
+ len = nested->data - msg->data;
+ nla = msg->data + len;
+
+ len = msg->len - len;
+ if (len <= NLA_HDRLEN)
+ return false;
+
+ nla->nla_len = len;
+
+ // Should we check msg alignement again?
+
+ return true;
+}
+
#define NLA_OK(nla,len) ((len) >= (int) sizeof(struct nlattr) && \
(nla)->nla_len >= sizeof(struct nlattr) && \
(nla)->nla_len <= (len))
diff --git a/ell/genl.h b/ell/genl.h
index c628b8c..13fe149 100644
--- a/ell/genl.h
+++ b/ell/genl.h
@@ -71,6 +71,9 @@ int l_genl_msg_get_error(struct l_genl_msg *msg);
bool l_genl_msg_append_attr(struct l_genl_msg *msg, uint16_t type,
uint16_t len, const void *data);
+bool l_genl_msg_append_init_recurse(struct l_genl_msg *msg, uint16_t type,
+ struct l_genl_attr *nested);
+bool l_genl_msg_append_end_recurse(struct l_genl_attr *nested);
bool l_genl_attr_init(struct l_genl_attr *attr, struct l_genl_msg *msg);
bool l_genl_attr_next(struct l_genl_attr *attr, uint16_t *type,
--
2.0.5
7 years, 4 months
[PATCH v5 0/4] Add DBus disconnect watch support
by Jukka Rissanen
Hi,
v5:
- rebased the set
- fixed filter rule testing and added more tests there
v4:
- minor tweaking here and there
- filter rule and corresponding unit test in a separate patch
v3:
- reworked the unit test
v2:
- moved the code to dbus.c
- reworked the logic in the caller of the watcher so no need to
remove l_dbus_register() and l_dbus_unregister()
this set allows user to monitor the disconnect status
of a service.
Cheers,
Jukka
Jukka Rissanen (4):
unit: dbus: Add test for filter rule
dbus: Add AddMatch and RemoveMatch support
dbus: Add disconnect watch support
unit: dbus: Add test for disconnect watch API
Makefile.am | 3 +
ell/dbus-private.h | 3 +
ell/dbus.c | 134 +++++++++++++++++++++++++
ell/dbus.h | 7 ++
unit/test-dbus-watch.c | 268 +++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 415 insertions(+)
create mode 100644 unit/test-dbus-watch.c
--
2.1.0
7 years, 4 months
[PATCH v4 0/6] Add DBus disconnect watch support
by Jukka Rissanen
Hi,
v4:
- minor tweaking here and there
- filter rule and corresponding unit test in a separate patch
v3:
- reworked the unit test
v2:
- moved the code to dbus.c
- reworked the logic in the caller of the watcher so no need to
remove l_dbus_register() and l_dbus_unregister()
this set allows user to monitor the disconnect status
of a service.
Cheers,
Jukka
Jukka Rissanen (6):
dbus: Add AddMatch and RemoveMatch support
gvariant: dbus.h need to be included before private header
dbus: Add filter rule creator
unit: dbus: Add test for filter rule
dbus: Add disconnect watch support
unit: dbus: Add test for disconnect watch API
Makefile.am | 3 +
ell/dbus-private.h | 19 +++++
ell/dbus.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++++
ell/dbus.h | 9 ++
ell/gvariant-util.c | 2 +-
unit/test-dbus-watch.c | 166 +++++++++++++++++++++++++++++++++++++
6 files changed, 415 insertions(+), 1 deletion(-)
create mode 100644 unit/test-dbus-watch.c
--
2.1.0
7 years, 4 months
[PATCH] dbus: Message header was not initialized
by Jukka Rissanen
Saw this valgrind report about the issue
==30891== Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s)
==30891== at 0x3B8FF01850: __sendmsg_nocancel (syscall-template.S:81)
==30891== by 0x410602: classic_send_message (dbus.c:561)
==30891== by 0x40F4A1: message_write_handler (dbus.c:173)
==30891== by 0x419D56: io_callback (io.c:138)
==30891== by 0x40BBC2: l_main_run (main.c:346)
==30891== by 0x401ECF: main (main.c:160)
==30891== Address 0x4c59304 is 4 bytes inside a block of size 12 alloc'd
==30891== at 0x4A06BCF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==30891== by 0x4A08A9D: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==30891== by 0x409A7D: l_realloc (util.c:92)
==30891== by 0x413A3E: message_new_common (dbus-message.c:201)
==30891== by 0x414B73: _dbus_message_new_method_call (dbus-message.c:221)
==30891== by 0x408A8B: send_request (agent.c:102)
==30891== by 0x408D28: agent_finalize_pending (agent.c:157)
==30891== by 0x408F9D: request_timeout (agent.c:241)
==30891== by 0x40C349: timeout_callback (timeout.c:78)
==30891== by 0x40BBC2: l_main_run (main.c:346)
==30891== by 0x401ECF: main (main.c:160)
==30891==
---
ell/dbus-message.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/ell/dbus-message.c b/ell/dbus-message.c
index 159df82..8743d66 100644
--- a/ell/dbus-message.c
+++ b/ell/dbus-message.c
@@ -200,6 +200,7 @@ static struct l_dbus_message *message_new_common(uint8_t type, uint8_t flags,
*/
message->header = l_realloc(NULL, 12);
message->header_size = 12;
+ memset(message->header, 0, 12);
hdr = message->header;
hdr->endian = DBUS_NATIVE_ENDIAN;
--
2.1.0
7 years, 4 months
[PATCH v3 0/4] Add DBus disconnect watch support
by Jukka Rissanen
Hi,
v3:
- reworked the unit test
v2:
- moved the code to dbus.c
- reworked the logic in the caller of the watcher so no need to
remove l_dbus_register() and l_dbus_unregister()
this set allows user to monitor the disconnect status
of a service.
Cheers,
Jukka
Jukka Rissanen (4):
dbus: Add AddMatch and RemoveMatch support
gvariant: dbus.h need to be included before private header
dbus: Add disconnect watch support
unit: dbus: Add test for disconnect watch API
Makefile.am | 3 +
ell/dbus-private.h | 35 ++++++++
ell/dbus.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++
ell/dbus.h | 9 ++
ell/gvariant-util.c | 2 +-
unit/test-dbus-watch.c | 153 ++++++++++++++++++++++++++++++++++
6 files changed, 422 insertions(+), 1 deletion(-)
create mode 100644 unit/test-dbus-watch.c
--
2.1.0
7 years, 4 months
[PATCH 0/9] hashmap fixes
by Jukka Rissanen
Hi,
noticed some issues in hashmap while implementing
an applicantion on top of ell.
Cheers,
Jukka
Jukka Rissanen (9):
hashmap: Add value free function
hashmap: Call user supplied value free function in destroy
hashmap: Call user supplied value free function in insert
unit: hashmap: Add value free hash entry test
unit: hashmap: Add replace entry test
hashmap: Add re-entrancy support to foreach function
unit: hashmap: Re-entrancy tests added
hashmap: Add support to finding an element from hash
unit: hashmap: Add unit test for l_hashmap_find
ell/hashmap.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++-
ell/hashmap.h | 11 ++++
unit/test-hashmap.c | 142 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 326 insertions(+), 3 deletions(-)
--
1.8.3.1
7 years, 4 months
[PATCH v2 0/3] Add DBus disconnect watch support
by Jukka Rissanen
Hi,
v2:
- moved the code to dbus.c
- reworked the logic in the caller of the watcher so no need to
remove l_dbus_register() and l_dbus_unregister()
this set allows user to monitor the disconnect status
of a service.
Cheers,
Jukka
Jukka Rissanen (3):
dbus: Add AddMatch and RemoveMatch support
dbus: Add disconnect watch support
unit: dbus: Add test for disconnect watch API
Makefile.am | 3 +
ell/dbus.c | 253 ++++++++++++++++++++++++++++++++
ell/dbus.h | 19 +++
unit/test-dbus-watch.c | 388 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 663 insertions(+)
create mode 100644 unit/test-dbus-watch.c
--
2.1.0
7 years, 4 months