project/ubus.git
6 years agoubusd: move global retmsg per client
Alexandru Ardelean [Wed, 7 Jun 2017 11:09:31 +0000 (14:09 +0300)]
ubusd: move global retmsg per client

Even with the tx_queue-ing issue resolved, what
seems to happen afterwards, is that all the messages
seems to get through, but the client still loops
in the `ubus_complete_request()` waiting for
`req->status_msg` or for a timeout.

Though, the timeout does not seem to happen, because
the data is processed in `ubus_poll_data()`, with
a infinite poll() timeout (ubus_complete_request() is
called with timeout 0).

It's likely that either the `seq` or `peer` sent from
ubusd are wrong, and the client cannot get the correct
ubus request in `ubus_process_req_msg()`.
I haven't digged too deep into this ; setting the
`retmsg` object on the client struct seems to have
resolved any hanging with the `ubus list` command.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name> [fix placement of retmsg in cl]
6 years agoubusd_monitor: alloc & free the buffer outside of the loop
Alexandru Ardelean [Wed, 5 Jul 2017 13:21:47 +0000 (16:21 +0300)]
ubusd_monitor: alloc & free the buffer outside of the loop

Should save a few cycles, since the data that's
being changed is only the seq number.
And the `ub` is always created as shared.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
6 years agoubusd: rename goto label from `error` to `out`
Alexandru Ardelean [Wed, 5 Jul 2017 13:21:22 +0000 (16:21 +0300)]
ubusd: rename goto label from `error` to `out`

Semantic has changed a bit.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
6 years agoubusd: don't free messages in ubus_send_msg() anymore
Alexandru Ardelean [Wed, 5 Jul 2017 13:20:51 +0000 (16:20 +0300)]
ubusd: don't free messages in ubus_send_msg() anymore

This makes it clear that `ubus_msg_send()` is only
about sending and queue-ing messages, and has nothing
to do with free-ing.

It can be a bit misleading/confusing when trying to go
through the code and make assumptions about whether a
buffer is free'd in ubus_send_msg(), or is free'd outside.

In `ubusd_proto_receive_message()` the `ubus_msg_free()`
is now called before the `if (ret == -1)` check.
That way, all callbacks will have their messages free'd,
which is what's desired, but confusing, because:
* ubusd_handle_invoke() called ubus_msg_free() before returning -1
* ubusd_handle_notify() called ubus_msg_free() before returning -1
* ubusd_handle_response() called ubus_msg_send(,,free=true) before returning -1
* ubus_msg_send() would call ubus_msg_send(,,free=false)
* all other callback callers would `ubus_msg_send(,,free=true)`
  (free the buffers in ubus_msg_send() )

In all other places, where `ubus_msg_send(,,free=true)`
an explicit `ubus_msg_free()` was added.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
6 years agolibubus: Fix deletion from context's object AVL tree when removing object
Bob Ham [Thu, 9 Nov 2017 15:53:24 +0000 (15:53 +0000)]
libubus: Fix deletion from context's object AVL tree when removing object

Objects are stored in the ubus context in an AVL tree.  An AVL tree
node contains a pointer to a key value.  For the ubus context, this
points to the id member of the object structure.  In
ubus_remove_object_cb, the id member is set to zero and then after,
avl_delete is called and fails.  To fix this, we call avl_delete
before setting the object id to zero.

Signed-off-by: Bob Ham <bob.ham@tomltd.co.uk>
6 years agoubus: Remove unnecessary memset calls.
Rosen Penev [Tue, 7 Nov 2017 20:34:20 +0000 (12:34 -0800)]
ubus: Remove unnecessary memset calls.

Replace malloc+memset with calloc.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 years agolibubus-req: add data_cb callback handling for ubus notifications
John Crispin [Wed, 1 Nov 2017 21:14:42 +0000 (22:14 +0100)]
libubus-req: add data_cb callback handling for ubus notifications

Signed-off-by: John Crispin <john@phrozen.org>
7 years agocli: fix listen_timeout compile issue
Hans Dedecker [Sat, 18 Feb 2017 12:41:53 +0000 (13:41 +0100)]
cli: fix listen_timeout compile issue

Variable listen_timeout is redefined as a function resulting into
a compile issue. Define the function as ubus_cli_listen_timeout
to fix the compile issue.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agolibubus: reset ctx->sock.error when doing ubus reconnect
Hans Dedecker [Sat, 18 Feb 2017 12:41:52 +0000 (13:41 +0100)]
libubus: reset ctx->sock.error when doing ubus reconnect

When ubus connect fails ctx->sock.eof will be set but ctx->sock.error
can be set as well. Reset ctx->sock.error as well when doing ubus
reconnect

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agocli: do not use default timeout for listen
Felix Fietkau [Wed, 15 Feb 2017 10:35:35 +0000 (11:35 +0100)]
cli: do not use default timeout for listen

Default to listening for events forever unless -t is explicitly
specified on the command line

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agocli: add support for subscribing to objects
Felix Fietkau [Tue, 14 Feb 2017 14:58:49 +0000 (15:58 +0100)]
cli: add support for subscribing to objects

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agoubusd: fix incomplete copy of shared buf during queue-ing
Alexandru Ardelean [Thu, 2 Feb 2017 15:59:49 +0000 (17:59 +0200)]
ubusd: fix incomplete copy of shared buf during queue-ing

For a shared ubus_msg_buf, the ubus_msg_ref function will
create a copy for queue-ing.

Problem is, that during the dequeue (especially) in client_cb,
the header is 0-ed (because it's was a newly alloc-ed buffer).

And during ubus_msg_writev(), the header info will be ignored
by the client.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
7 years agolibubus: do not modify uloop_cancelled
Felix Fietkau [Fri, 3 Feb 2017 17:39:11 +0000 (18:39 +0100)]
libubus: do not modify uloop_cancelled

uloop_cancelled was used for two purposes within ubus_complete_request:
- interrupting recursive requests on SIGINT/SIGTERM
- breaking out of the poll loop in a recursive request that completed

Saving/restorung uloop_cancelled was buggy, leading to SIGTERM not being
processed properly. Simplify the logic by using a separate field for
internal use

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agolibubus: reset ctx->sock.eof to fix reconnect issues
Felix Fietkau [Fri, 3 Feb 2017 13:13:48 +0000 (14:13 +0100)]
libubus: reset ctx->sock.eof to fix reconnect issues

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agolibubus: do not register/unregister with uloop during sync requests
Felix Fietkau [Sun, 22 Jan 2017 13:33:37 +0000 (14:33 +0100)]
libubus: do not register/unregister with uloop during sync requests

This was leftover code from before this codepath was converted to
polling directly

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agolibubus: move uloop_init() call to ubus_connect_ctx
Felix Fietkau [Sun, 22 Jan 2017 13:28:47 +0000 (14:28 +0100)]
libubus: move uloop_init() call to ubus_connect_ctx

uloop should not be used before it is initialized

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agoubusd: fix issue caused by an implicit cast
Mihai Richard [Thu, 19 Jan 2017 12:51:04 +0000 (12:51 +0000)]
ubusd: fix issue caused by an implicit cast

An -1 returned by ubus_msg_writev() will be interpreted as
UINT_MAX during a check to see how much data had could be
written on the socket.

Because sizeof() will return size_t it will promote the
comparsion to unsigned

Signed-off-by: Mihai Richard <mihairichard@live.com>
7 years agoubus: ubus_free: clear pending timers before freeing context
Abhimanyu Vishwakarma [Tue, 3 Jan 2017 06:07:05 +0000 (11:37 +0530)]
ubus: ubus_free: clear pending timers before freeing context

If a synchronous operation is executed on a ubus context after
uloop_done() has been called, the context's pending_timer
may remain in uloop's list of timeouts.
This leads to undefined behaviour during next execution of uloop
code, as it may be referring to unavailable memory or memory
that has been allocated for different purposes.

Signed-off-by: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
Signed-off-by: Abhimanyu Vishwakarma <Abhimanyu.Vishwakarma@imgtec.com>
7 years agolibubus: reduce code duplication, fix indentation
Felix Fietkau [Sat, 24 Dec 2016 13:35:58 +0000 (14:35 +0100)]
libubus: reduce code duplication, fix indentation

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agoAllow sending a fd along a ubus_request
amine ahd [Mon, 19 Dec 2016 09:30:36 +0000 (10:30 +0100)]
Allow sending a fd along a ubus_request

Signed-off-by: amine.ahd <amine.ahd@gmail.com>
7 years agoubusd: fix id lookup of objects with path and no methods
Felix Fietkau [Sun, 20 Nov 2016 16:05:00 +0000 (17:05 +0100)]
ubusd: fix id lookup of objects with path and no methods

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agolua: add 'defer_request' and 'complete_deferred_request' functions
Vasily Goldobin [Wed, 16 Nov 2016 15:26:13 +0000 (20:26 +0500)]
lua: add 'defer_request' and 'complete_deferred_request' functions

Add Lua bindings for 'ubus_defer_request' and 'ubus_complete_deferred_request' functions with sample code.

Signed-off-by: Vasily Goldobin <vasily@lynxtech.ru>
7 years agoubusd_proto: fix crash when trying to subscribe to system objects
Felix Fietkau [Sun, 20 Nov 2016 15:40:06 +0000 (16:40 +0100)]
ubusd_proto: fix crash when trying to subscribe to system objects

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agobuild: remove /opt/local prefix
Felix Fietkau [Sun, 20 Nov 2016 15:26:19 +0000 (16:26 +0100)]
build: remove /opt/local prefix

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agocli: register event handler first, then do lookup
Alexandru Ardelean [Thu, 5 May 2016 11:03:30 +0000 (14:03 +0300)]
cli: register event handler first, then do lookup

We seem to be getting timeout for ubus wait_for calls
every now and then.

And it's not reliably reproducible.
Looking at the code the only thing that would look like
a potetntial reason, is that between the ubus_lookup() and
ubus_register_event_handler() calls, there's a very narrow
window where the event would get sent out and we would not
get it, thus having to timeout.

It doesn't look like registering the event handler first
is a big problem for the whole wait_check_object() logic.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
8 years agoubusd: fix inverted check in ubusd_reply_add
Denis Osvald [Thu, 25 Aug 2016 11:54:54 +0000 (13:54 +0200)]
ubusd: fix inverted check in ubusd_reply_add

Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
8 years agoubusd: don't check ACL when object is NULL
Denis Osvald [Thu, 25 Aug 2016 11:54:52 +0000 (13:54 +0200)]
ubusd: don't check ACL when object is NULL

If there are any ACLs present other than global wildcard "*", the AVL
tree comparator will compare ACL key to object name. However, object
name can be NULL in cases where ACL check is done on call to internal
ubus objects (e.g. ubus monitor).

With this change we skip checking ACLs on such NULL objects.

Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
8 years agoubusd: fix sending remove-object notification
Felix Fietkau [Tue, 23 Aug 2016 10:55:08 +0000 (12:55 +0200)]
ubusd: fix sending remove-object notification

Patch by Delio Brignoli <brignoli.delio@gmail.com>

Both ubusd_free_object (eventually via ubusd_create_object_event_msg)
and ubus_proto_send_msg_from_blob() use the same message buffer.
So ubusd_handle_remove_object builds the payload which gets (indirectly)
overwritten by the call to ubusd_free_object and then sent again by
ubus_proto_send_msg_from_blob.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agoubusd: add missing NULL pointer checks for obj->type
Felix Fietkau [Tue, 23 Aug 2016 09:36:41 +0000 (11:36 +0200)]
ubusd: add missing NULL pointer checks for obj->type

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agocmake: Fix find_library for ubusd and examples/server
Florian Fainelli [Fri, 1 Jul 2016 21:57:44 +0000 (14:57 -0700)]
cmake: Fix find_library for ubusd and examples/server

Both ubusd and cli TARGET_LINK_LIBRARIES reference ${json} which is
obtained via find_library(), but since the find_library() is searched
after the TARGET_LINK_LIBRARIES for ubusd, ubusd always gets an empty
${json} variable.

examples/server also links against libjson-c, but we were not setting
TARGET_LINK_LIBRARIES accordingly, so do that too with ${json} appended.

This was causing linking errors for ubusd and then examples/server using
an external toolchain (stbgcc-4.8-1.x).

Fixes: 9f52d1769b762 ("cli: use the new json-c library name")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
8 years agoFix the length of msg buffer after realloc
Rujun Wang [Thu, 23 Jun 2016 03:06:06 +0000 (11:06 +0800)]
Fix the length of msg buffer after realloc

Signed-off-by: Rujun Wang <chinawrj@gmail.com>
8 years agoImplemented publish/subscribe lua bindings to libubus-lua with example lua files.
Iain Fraser [Thu, 19 May 2016 13:40:42 +0000 (14:40 +0100)]
Implemented publish/subscribe lua bindings to libubus-lua with example lua files.

8 years agoubusd: remove systemd socket activation support
John Crispin [Wed, 1 Jun 2016 09:37:30 +0000 (11:37 +0200)]
ubusd: remove systemd socket activation support

Signed-off-by: John Crispin <john@phrozen.org>
8 years agoubusd: fix systemd socket activation support
Matthias Schiffer [Tue, 24 May 2016 00:01:48 +0000 (02:01 +0200)]
ubusd: fix systemd socket activation support

62cdfc3 added systemd units including a ubus.socket unit, but didn't
actually add socket activation support to ubusd. This would cause the first
connection that activated ubusd to hang (as ubusd ignored it), and stopping
ubusd would break it completely (as ubusd removed the socket file).

The ENABLE_SYSTEMD default is changed to OFF as the socket activation uses
libsystemd, so setting ENABLE_SYSTEMD to ON will now require libsystemd.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
8 years agolibubus: nullify stale msgbuf pointer in case of ubus_connect_ctx() failure
Eyal Birger [Sun, 15 May 2016 05:13:27 +0000 (08:13 +0300)]
libubus: nullify stale msgbuf pointer in case of ubus_connect_ctx() failure

If the ubus_reconnect() call fails in ubus_connect_ctx(), the msgbuf.data
newly allocated buffer is freed, but its pointer in the ubus_context is not
removed.

This leads to a double free error if ubus_auto_shutdown() is called for cleanup
after ubus_auto_connect() failed to connect to ubusd.

Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
8 years agocmake: Add ubox, blobmsg_json libraries and include dirs lookup
Petr Štetiar [Sat, 5 Mar 2016 13:59:33 +0000 (14:59 +0100)]
cmake: Add ubox, blobmsg_json libraries and include dirs lookup

Otherwise cmake uses files from system which sometimes isn't wanted, ie.
for testing.

Signed-off-by: Petr Å tetiar <ynezz@true.cz>
8 years agocli: add timeout support for listen command
Zhao, Gang [Fri, 26 Feb 2016 09:18:39 +0000 (17:18 +0800)]
cli: add timeout support for listen command

Currently 'ubus listen' command does not respect the timeout parameter,
i.e., whether timeout parameter is provided, 'ubus listen' will always
run infinitely. This patch let 'ubus listen' command support the timeout
parameter. For example, 'ubus listen -t 60' will cause the command to
exit after 60 seconds.

Signed-off-by: Zhao, Gang <gang.zhao.42@gmail.com>
8 years agocli: static keyword tweak
Zhao, Gang [Fri, 26 Feb 2016 09:18:38 +0000 (17:18 +0800)]
cli: static keyword tweak

Function ubus_cli_listen() is called only once, and function uloop_run()
and uloop_done() which need struct ubus_event_handler listener are
called within this function, so it's not needed to mark struct
ubus_event_handler listener as static. The same as pointer struct
ubus_context *ctx in main function.

Global struct commands is only used in this file, so it should be marked
static.

Signed-off-by: Zhao, Gang <gang.zhao.42@gmail.com>
8 years agoubus: use network order in ubus message header fields
Eyal Birger [Mon, 15 Feb 2016 04:09:38 +0000 (06:09 +0200)]
ubus: use network order in ubus message header fields

Changing the ubus message header fields from 'host' order to 'network' order
allows passing ubus messages between hosts with different endianity.

Example use (creating a ubus proxy):

on host A (e.g. big endian router already running ubusd), run:
$ socat TCP-LISTEN:5699,fork UNIX:/var/run/ubus.sock &

On host B (e.g. little endian development PC) run:
$ socat UNIX-LISTEN:/var/run/ubus.sock,fork TCP:<host A IP>:5699 &

Now ubus applications can be run on host B and seamlessly interact with ubus
applications on host A.

Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
8 years agolibubus.h: marking unused variables
Emanuel Taube [Fri, 12 Feb 2016 12:28:12 +0000 (13:28 +0100)]
libubus.h: marking unused variables

Inform the compiler that the variables are not gona be used to avoid
compiler warnings.

Signed-off-by: Emanuel Taube <emanuel.taube@gmail.com>
8 years agolibubus.h: add ubus_auto_shutdown()
Ben Kelly [Tue, 2 Feb 2016 13:02:59 +0000 (15:02 +0200)]
libubus.h: add ubus_auto_shutdown()

Add ubus_auto_shutdown function, which ensures any pending uloop_timer is cancelled before calling ubus_shutdown on the context.

This avoids a condition where ubus_shutdown() is called during ubus_auto_connect attempting a reconnection.

Signed-off-by: Ben Kelly <ben@benjii.net>
8 years agoubusd: fix a memory leak on user/group client info
Felix Fietkau [Tue, 26 Jan 2016 09:10:39 +0000 (10:10 +0100)]
ubusd: fix a memory leak on user/group client info

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agolua: fix stack leak in ubus method handling
Felix Fietkau [Wed, 20 Jan 2016 13:59:04 +0000 (14:59 +0100)]
lua: fix stack leak in ubus method handling

Signed-off-by: Chen Bin <ewolfok@126.com>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agoubusd: add missing NULL pointer checks for ACL processing
Felix Fietkau [Wed, 13 Jan 2016 11:28:37 +0000 (12:28 +0100)]
ubusd: add missing NULL pointer checks for ACL processing

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agolibubus: add null for ubus_context object in ubus_shutdown()
Alexandru Ardelean [Thu, 17 Dec 2015 08:45:22 +0000 (10:45 +0200)]
libubus: add null for ubus_context object in ubus_shutdown()

At the moment, we do our own null checks before calling ubus_free().
The likely-hood of 'ctx' being null (in ubus_free()) is low,
but since free() handles null, might make sense for ubus_free() to do so as well.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
8 years agoubusd: allow all object access if uid=0 (ignore gid)
Felix Fietkau [Wed, 9 Dec 2015 19:16:31 +0000 (20:16 +0100)]
ubusd: allow all object access if uid=0 (ignore gid)

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agoubusd: fix the return code for acl check mismatch
Felix Fietkau [Wed, 9 Dec 2015 18:48:08 +0000 (19:48 +0100)]
ubusd: fix the return code for acl check mismatch

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agoubusd: simplify/fix avl loop in ubusd_reply_add()
Felix Fietkau [Wed, 9 Dec 2015 18:39:24 +0000 (19:39 +0100)]
ubusd: simplify/fix avl loop in ubusd_reply_add()

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agoubusd: simplify/fix avl loop in ubusd_acl_check()
Felix Fietkau [Wed, 9 Dec 2015 18:36:49 +0000 (19:36 +0100)]
ubusd: simplify/fix avl loop in ubusd_acl_check()

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agolibubus: add socket EOF handling to ubus_complete_request()
Felix Fietkau [Wed, 9 Dec 2015 17:35:07 +0000 (18:35 +0100)]
libubus: add socket EOF handling to ubus_complete_request()

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agolibubus: fix error handling during close after partially receiving a message
Felix Fietkau [Wed, 9 Dec 2015 17:26:43 +0000 (18:26 +0100)]
libubus: fix error handling during close after partially receiving a message

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agoubusd: make ACL path configurable on the command line
Felix Fietkau [Wed, 9 Dec 2015 16:44:00 +0000 (17:44 +0100)]
ubusd: make ACL path configurable on the command line

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agoubusd: remove a faulty and redundant check
Felix Fietkau [Wed, 9 Dec 2015 16:36:08 +0000 (17:36 +0100)]
ubusd: remove a faulty and redundant check

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agoubus: Correct usage of timeout on poll function
Karl Vogel [Mon, 7 Dec 2015 07:35:52 +0000 (08:35 +0100)]
ubus: Correct usage of timeout on poll function

As the man page explains:

"Specifying a timeout of zero causes poll() to return immediately,
even if no file descriptors are ready."

The use of 0 as timeout could cause libubus to busy loop if the
socket was non-blocking. For blocking sockets, this was less
apparent as the subsequent read() would then block.

Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
8 years agocli: add monitor support
Felix Fietkau [Thu, 19 Nov 2015 21:32:29 +0000 (22:32 +0100)]
cli: add monitor support

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agolibubus: add monitor support
Felix Fietkau [Thu, 19 Nov 2015 21:32:25 +0000 (22:32 +0100)]
libubus: add monitor support

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agoubusd: add monitor support
Felix Fietkau [Thu, 19 Nov 2015 21:32:11 +0000 (22:32 +0100)]
ubusd: add monitor support

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agolibubus: Fix reverse order processing of pending ubus notifications messages
Hans Dedecker [Mon, 2 Nov 2015 10:16:11 +0000 (11:16 +0100)]
libubus: Fix reverse order processing of pending ubus notifications messages

Append ubus notification messages to the tail of the pending list
so they're processed in the order as they're put onto the pending list

Signed-off-by: Xinxing Hu <xinxing.huchn@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
9 years agolua: Fix stack imbalance in ubus_event_handler
Hans Dedecker [Mon, 2 Nov 2015 10:16:10 +0000 (11:16 +0100)]
lua: Fix stack imbalance in ubus_event_handler

The value from getglobal wasn't being removed from the stack,
resulting in an ever growing stack in the ubus event handler.

Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
9 years agofix off-by-one in acl match iteration
John Crispin [Tue, 22 Sep 2015 04:20:55 +0000 (06:20 +0200)]
fix off-by-one in acl match iteration

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agounbreak acl allocation
John Crispin [Tue, 22 Sep 2015 04:12:08 +0000 (06:12 +0200)]
unbreak acl allocation

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agofix a copy & paste bug
John Crispin [Wed, 1 Jul 2015 00:22:36 +0000 (02:22 +0200)]
fix a copy & paste bug

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agoubusd: fix offset calculation (based on patch by Yang Chao)
Felix Fietkau [Mon, 6 Jul 2015 16:42:36 +0000 (18:42 +0200)]
ubusd: fix offset calculation (based on patch by Yang Chao)

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agoubusd: fix build on non-linux systems without peercred support
Felix Fietkau [Wed, 24 Jun 2015 16:28:37 +0000 (18:28 +0200)]
ubusd: fix build on non-linux systems without peercred support

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agochange socket permission to allow !root users to connect
John Crispin [Mon, 13 Apr 2015 16:31:28 +0000 (18:31 +0200)]
change socket permission to allow !root users to connect

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agohook acl into ubusd
John Crispin [Sat, 25 Apr 2015 08:10:34 +0000 (10:10 +0200)]
hook acl into ubusd

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agohook acl into libubus
John Crispin [Sat, 25 Apr 2015 08:10:26 +0000 (10:10 +0200)]
hook acl into libubus

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agoadd acl code
John Crispin [Sat, 25 Apr 2015 08:50:39 +0000 (10:50 +0200)]
add acl code

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agomake ubusd load the acl on start and HUP
John Crispin [Wed, 15 Apr 2015 23:54:15 +0000 (01:54 +0200)]
make ubusd load the acl on start and HUP

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agoadd optional tags to the ubus methos struct and the wrapper macros
John Crispin [Mon, 13 Apr 2015 15:21:21 +0000 (17:21 +0200)]
add optional tags to the ubus methos struct and the wrapper macros

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agocall openlog on startup
John Crispin [Wed, 15 Apr 2015 23:54:54 +0000 (01:54 +0200)]
call openlog on startup

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agomake ubus_proto_send_msg_from_blob() none static
John Crispin [Sat, 25 Apr 2015 07:48:09 +0000 (09:48 +0200)]
make ubus_proto_send_msg_from_blob() none static

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agomake ubus_parse_msg() none static
John Crispin [Mon, 20 Apr 2015 23:01:26 +0000 (01:01 +0200)]
make ubus_parse_msg() none static

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agomake ubusd_send_event() none static
John Crispin [Mon, 20 Apr 2015 22:45:52 +0000 (00:45 +0200)]
make ubusd_send_event() none static

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agopass ubus_msg_buf to callback of internal object
John Crispin [Mon, 20 Apr 2015 09:08:26 +0000 (11:08 +0200)]
pass ubus_msg_buf to callback of internal object

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agoremove obseleted validation of key
John Crispin [Tue, 14 Apr 2015 03:12:34 +0000 (05:12 +0200)]
remove obseleted validation of key

Signed-off-by: John Crispin <blogic@openwrt.org>
9 years agolua: fix memory leak problem
陈斌 [Wed, 13 May 2015 05:52:22 +0000 (13:52 +0800)]
lua: fix memory leak problem

Signed-off-by: Chen Bin <ewolfok@126.com>
9 years agocli: flush stdout after printing an event
Felix Fietkau [Tue, 12 May 2015 14:56:09 +0000 (16:56 +0200)]
cli: flush stdout after printing an event

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agoubus: Fix memleak in examples/client in case of failure
Hans Dedecker [Tue, 28 Apr 2015 14:07:28 +0000 (16:07 +0200)]
ubus: Fix memleak in examples/client in case of failure

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
9 years agoubus: Fix issues reported by static code analysis tool Klocwork
Hans Dedecker [Mon, 13 Apr 2015 16:18:36 +0000 (18:18 +0200)]
ubus: Fix issues reported by static code analysis tool Klocwork

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
9 years agolibubus: fix processing queued messages after blocking requests
Felix Fietkau [Thu, 22 Jan 2015 12:30:20 +0000 (13:30 +0100)]
libubus: fix processing queued messages after blocking requests

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: expose ubus_connect_ctx() in public API
Delio Brignoli [Wed, 1 Oct 2014 17:57:56 +0000 (19:57 +0200)]
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>
10 years agolibubus: define _GNU_SOURCE, needed for O_CLOEXEC
Felix Fietkau [Wed, 17 Sep 2014 11:32:43 +0000 (13:32 +0200)]
libubus: define _GNU_SOURCE, needed for O_CLOEXEC

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: fix build error in examples/server
Zefir Kurtisi [Wed, 17 Sep 2014 10:33:32 +0000 (12:33 +0200)]
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>
10 years agolibubus: replace __init with __constructor
Zefir Kurtisi [Wed, 17 Sep 2014 10:30:49 +0000 (12:30 +0200)]
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>
10 years agolibubus: restore uloop_cancelled on timeout
Alexandru Ardelean [Mon, 15 Sep 2014 12:42:09 +0000 (15:42 +0300)]
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>
10 years agolibubus: preserve the received message buffer for incoming invoke calls
Felix Fietkau [Mon, 15 Sep 2014 13:40:05 +0000 (15:40 +0200)]
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>
10 years agolibubus: rework buffer allocation code
Felix Fietkau [Mon, 15 Sep 2014 13:36:03 +0000 (15:36 +0200)]
libubus: rework buffer allocation code

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: remove ubus_msghdr_data() by passing in the right data structure pointer
Felix Fietkau [Mon, 15 Sep 2014 13:29:29 +0000 (15:29 +0200)]
libubus: remove ubus_msghdr_data() by passing in the right data structure pointer

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: use calloc_a for queued msgs to reduce the number of allocations
Felix Fietkau [Mon, 15 Sep 2014 13:21:40 +0000 (15:21 +0200)]
libubus: use calloc_a for queued msgs to reduce the number of allocations

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: fix a small memleak in ubus_register_event_handler()
Felix Fietkau [Thu, 4 Sep 2014 18:01:13 +0000 (20:01 +0200)]
libubus: fix a small memleak in ubus_register_event_handler()

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: fix msgbuf reduction logic during receive
Alexandru Ardelean [Thu, 7 Aug 2014 04:32:53 +0000 (04:32 +0000)]
libubus: fix msgbuf reduction logic during receive

Signed-off-by: Alexandru Ardelean <aa@ocedo.com>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: mark ubus socket with close-on-exec
Felix Fietkau [Sun, 31 Aug 2014 12:10:26 +0000 (14:10 +0200)]
libubus: mark ubus socket with close-on-exec

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: use explicit type name in ubus_msghdr_data instead of typeof()
Felix Fietkau [Thu, 3 Jul 2014 18:58:37 +0000 (20:58 +0200)]
libubus: use explicit type name in ubus_msghdr_data instead of typeof()

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: move ubus_msghdr_data to libubus-internal.h
Felix Fietkau [Thu, 3 Jul 2014 18:58:01 +0000 (20:58 +0200)]
libubus: move ubus_msghdr_data to libubus-internal.h

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agoubus: add count test to validate large message sizes
Alexandru Ardelean [Fri, 27 Jun 2014 16:11:45 +0000 (19:11 +0300)]
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.

10 years agolibubus: fix ubus_invoke() to return err in case ubus_start_request() fails
Alexandru Ardelean [Fri, 27 Jun 2014 16:11:44 +0000 (19:11 +0300)]
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.

10 years agoubusd: replace ubusd_msg_unshare() with ubus_msg_new() to prevent invalid free-ing
Alexandru Ardelean [Fri, 27 Jun 2014 16:11:43 +0000 (19:11 +0300)]
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.

10 years agolibubus: fix writev_retry() function when writing large packets
Alexandru Ardelean [Fri, 27 Jun 2014 16:11:42 +0000 (19:11 +0300)]
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.

10 years agolibubus: add logic to reduce msgbuf data size after 16 small messages
Alexandru Ardelean [Fri, 27 Jun 2014 16:11:41 +0000 (19:11 +0300)]
libubus: add logic to reduce msgbuf data size after 16 small messages