Commit graph

207 commits

Author SHA1 Message Date
Hans Dedecker
7798d56301 ubus: Fix issues reported by static code analysis tool Klocwork
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
2015-04-20 15:43:19 +02:00
Felix Fietkau
2d660c519d libubus: fix processing queued messages after blocking requests
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2015-01-22 13:30:20 +01:00
Delio Brignoli
7b79b6226e libubus: expose ubus_connect_ctx() in public API
ubus_connect_ctx() is equivalent to ubus_connect() but accepts a
pointer to a previously allocated ubus_context struct.
ubus_shutdown() is made available as an alternative to ubus_free()
to clean up contexts initialised by ubus_connect_ctx().

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2014-10-14 09:57:11 +02:00
Felix Fietkau
4c4f35cf22 libubus: define _GNU_SOURCE, needed for O_CLOEXEC
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-17 13:32:43 +02:00
Zefir Kurtisi
9841dae95a libubus: fix build error in examples/server
This fixes build warning:
/ubus.git/examples/server.c: In function 'test_hello_reply':
/ubus.git/examples/server.c:69:6: error: ignoring return value of 'pipe', declared with attribute warn_unused_result [-Werror=unused-result]

Signed-off-by: Zefir Kurtisi <zefir.kurtisi@neratec.com>
2014-09-17 13:29:30 +02:00
Zefir Kurtisi
4d1cdc5527 libubus: replace __init with __constructor
__init has a naming collision with C++ and prevents ubus_common.h
from being included. Instead, use __constructor as defined from
libubox.

Signed-off-by: Zefir Kurtisi <zefir.kurtisi@neratec.com>
2014-09-17 13:29:24 +02:00
Alexandru Ardelean
e52db46c9c libubus: restore uloop_cancelled on timeout
Context: 1 loop with a single ubus_invoke() that times out calls
uloop_end() which ends the loop, and thus ends the application.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-15 15:48:54 +02:00
Felix Fietkau
9562291f68 libubus: preserve the received message buffer for incoming invoke calls
Set ctx->msgbuf.data to NULL during the call. If ctx->msgbuf is needed
during the call, a new buffer will be allocated. If not,
ctx->msgbuf.data is restored to the previous value afterwards

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-15 15:40:07 +02:00
Felix Fietkau
6a285141d9 libubus: rework buffer allocation code
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-15 15:36:03 +02:00
Felix Fietkau
3e45a782b2 libubus: remove ubus_msghdr_data() by passing in the right data structure pointer
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-15 15:33:27 +02:00
Felix Fietkau
7c25c119a5 libubus: use calloc_a for queued msgs to reduce the number of allocations
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-15 15:21:40 +02:00
Felix Fietkau
73cbb94b48 libubus: fix a small memleak in ubus_register_event_handler()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-04 20:01:13 +02:00
Alexandru Ardelean
6280cbaf09 libubus: fix msgbuf reduction logic during receive
Signed-off-by: Alexandru Ardelean <aa@ocedo.com>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-08-31 14:12:55 +02:00
Felix Fietkau
b79e808944 libubus: mark ubus socket with close-on-exec
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-08-31 14:10:26 +02:00
Felix Fietkau
f688c7ad0b libubus: use explicit type name in ubus_msghdr_data instead of typeof()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-07-03 20:58:37 +02:00
Felix Fietkau
382a05f54d libubus: move ubus_msghdr_data to libubus-internal.h
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-07-03 20:58:01 +02:00
Alexandru Ardelean
af63ab64af ubus: add count test to validate large message sizes
Client creates a string "1 2 3 ... 10000 ...", sends it to the server
along with the maximum number in the string.

Server creates another string like the client sent.

It validates it and, returns strcmp()'s result.

This is loop-ed every 2 seconds.
2014-07-03 12:47:11 +02:00
Alexandru Ardelean
f47005a44c libubus: fix ubus_invoke() to return err in case ubus_start_request() fails
Seems the UBUS_MAX_MSGLEN is ignored by ubus_invoke(),
and then segfault happens.

This issue is present before this set of patches.
2014-07-03 12:46:44 +02:00
Alexandru Ardelean
996e16b2cb ubusd: replace ubusd_msg_unshare() with ubus_msg_new() to prevent invalid free-ing
The realloc is problematic mostly with large packets, as the pointer changes
so what eventually gets free'd is invalid.
Note that ub ptr param in the  call will be passed on to a ubus_msg_free(),
right after ubus_msg_ref() finishes.

This bug stayed hidden the same way as the bug in libubus writev_retry().
Since the write/sendmsg function can send about ~200k the ubus_msg_enqueue()
call does not get triggered.
2014-07-03 12:45:49 +02:00
Alexandru Ardelean
5db90dbc94 libubus: fix writev_retry() function when writing large packets
Seems this bug stayed hidden for a while, because the write/sendmsg function
can send up to ~200k in one send, so it looked at first why there was
some data mismatch.
2014-07-03 12:45:30 +02:00
Alexandru Ardelean
82da9db3a9 libubus: add logic to reduce msgbuf data size after 16 small messages 2014-07-03 12:45:13 +02:00
Alexandru Ardelean
6d24ad71f6 ubus: increase message size limit and make it configurable at build-time 2014-07-03 12:44:19 +02:00
Alexandru Ardelean
7e746e5a85 libubus: refactor ubus_context msgbuf data to be dynamically allocated 2014-07-03 12:42:42 +02:00
Felix Fietkau
3869e0ca07 libubus: fix deferring invoke processing for non-uloop usage
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-06-25 10:24:27 +02:00
Felix Fietkau
bbd3fbc9cc libubus: always defer processing incoming invoke/unsubscribe/notify if there is a request pending
This fixes recursion problems on config reload in netifd and simplifies
application handling of requests

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-06-24 22:34:53 +02:00
Felix Fietkau
9fda19140e cli: implement wait_for
Allows waiting for one or more objects to appear
Returns instantly if objects are already present

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-05-06 16:58:11 +02:00
Steven Barth
6dffecb36b lua: forward return codes from lua to ubus
Signed-off-by: Steven Barth <cyrus@openwrt.org>
Tested-by: Luka Perkov <luka@openwrt.org>
2014-05-05 19:56:31 +02:00
Felix Fietkau
2c71017cfb libubus: add support for defining a policy mask
This allows sharing a policy array across methods, but masking out
unused entries for individual methods.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-04-27 00:40:25 +02:00
Felix Fietkau
7c9e76ed08 ubusd: fix processing object method signatures
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-04-01 13:45:29 +02:00
Felix Fietkau
1d5ac421a5 libubus: do not use uloop_run() inside ubus_complete_request
Avoid unrelated uloop callbacks by using poll() on the ubus fd instead.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-03-18 22:36:38 +01:00
Felix Fietkau
4d7b2ab639 libubus-internal: use the __hidden definition from libubox
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-03-18 22:12:21 +01:00
Felix Fietkau
8f3c5a7b50 libubus: close file descriptor after passing it in the status msg
Simplifies handling of non-deferred requests

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-27 16:48:55 +01:00
Karl Vogel
334c389180 ubus: Fix imbalance in lua stack push/pop of values.
The lua getglobal and rawgeti both push a value onto the lua stack,
but they weren't being removed by the ubus_method_handler function,
thus corrupting the lua stack.

In case the specified method wasn't a function, the stack was also
corrupted as the method name remained on the stack.

Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
2014-02-23 18:20:29 +01:00
Felix Fietkau
54926994e2 examples/client: receive data from the passed file descriptor
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-18 15:03:53 +01:00
Felix Fietkau
85dff762f9 examples/server: send a file descriptor as part of the request to the "hello" method
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-18 15:03:53 +01:00
Felix Fietkau
47a9ab0c64 libubus: implement file descriptor passing support
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-18 15:03:53 +01:00
Felix Fietkau
37cc5d2f25 ubusd: implement protocol support for passing file descriptors as part of request completion msgs from objects to clients
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-18 15:03:53 +01:00
Luka Perkov
4e82a1fabb lua: allow methods with no arguments
In C it is possible to have methods without arguments (UBUS_METHOD_NOARG).
Enable support for the same calls in Lua too.

This commit also fixes segfault which can be caused by passing non-table type
where table is expected. The lua_gettablelen() function is called after we have
made sure we are dealing with a table in the first place.

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-28 22:20:30 +00:00
Luka Perkov
b356773921 lua: fix whitespaces and typo
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-28 22:20:26 +00:00
John Crispin
29d7092252 add auto (re)connect logic to libubus
Signed-off-by: John Crispin <blogic@openwrt.org>
2014-01-22 13:53:11 +00:00
John Crispin
8ea9667036 add Lua bindings for ubus events
It mostly mimick the style of the existing code.

With it and the ubox Lua bindings, you can now send ubus events
through Lua or listen for events (you can register for multiple events
at the same time).

Signed-off-by: Jeff Remy <jeff.remy@gmail.com>
2013-11-07 16:23:30 +01:00
Felix Fietkau
a9ee3ef0cf libubus: pull the variable length data array out of struct ubus_msghdr to fix builds with clang
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-29 17:28:37 +01:00
Jo-Philipp Wich
6ae17d0298 ubusd: use umask of 0177 for now to prevent a world- and group-writable unix socket 2013-09-28 17:23:29 +02:00
Lukasz Baj
d486006ab9 libubus: Check if remove callback exists before call it
When process unsubscribes then remove callback is called. But it
can be NULL if not defined, so we should check it before we call it.

Signed-off-by: Lukasz Baj <l.baj@radytek.com>
2013-08-29 20:35:38 +02:00
Felix Fietkau
b20a8a01c7 libubus: detect read/write errors and set the eof flag, even if uloop is not used as main event loop
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-08-08 22:42:50 +02:00
Felix Fietkau
62bfc16a09 libubus: fix publishing objects after reconnect
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-08-08 22:20:39 +02:00
Yousong Zhou
2b4fc4c916 Add a return value to make compiler silent.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2013-08-04 10:53:36 +02:00
Yousong Zhou
cca7fb2ab1 Fix the condition for stopping the writev_retry.
All iov's were sent only after the last were sent (iov_len == 0). We
could have 'cur_len == 0' if the sent iov's were sent wholly but not all
iov's were sent (how about all but the last).

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2013-08-04 10:53:24 +02:00
Felix Fietkau
f72dca720b libubus: fix logic inversion for cancelling requests
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-05-30 12:39:51 +02:00
Felix Fietkau
9f52d1769b cli: use the new json-c library name
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-05-29 12:53:22 +02:00