oweals/ubus.git
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>
8 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>
8 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>
8 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>
9 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>
9 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>
9 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

10 years agoubus: increase message size limit and make it configurable at build-time
Alexandru Ardelean [Fri, 27 Jun 2014 16:11:40 +0000 (19:11 +0300)]
ubus: increase message size limit and make it configurable at build-time

10 years agolibubus: refactor ubus_context msgbuf data to be dynamically allocated
Alexandru Ardelean [Fri, 27 Jun 2014 16:11:39 +0000 (19:11 +0300)]
libubus: refactor ubus_context msgbuf data to be dynamically allocated

10 years agolibubus: fix deferring invoke processing for non-uloop usage
Felix Fietkau [Tue, 24 Jun 2014 20:42:14 +0000 (22:42 +0200)]
libubus: fix deferring invoke processing for non-uloop usage

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: always defer processing incoming invoke/unsubscribe/notify if there is a...
Felix Fietkau [Tue, 24 Jun 2014 20:34:50 +0000 (22:34 +0200)]
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>
10 years agocli: implement wait_for
Felix Fietkau [Tue, 6 May 2014 14:55:34 +0000 (16:55 +0200)]
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>
10 years agolua: forward return codes from lua to ubus
Steven Barth [Mon, 5 May 2014 17:47:32 +0000 (19:47 +0200)]
lua: forward return codes from lua to ubus

Signed-off-by: Steven Barth <cyrus@openwrt.org>
Tested-by: Luka Perkov <luka@openwrt.org>
10 years agolibubus: add support for defining a policy mask
Felix Fietkau [Sat, 26 Apr 2014 22:40:23 +0000 (00:40 +0200)]
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>
10 years agoubusd: fix processing object method signatures
Felix Fietkau [Tue, 1 Apr 2014 11:45:29 +0000 (13:45 +0200)]
ubusd: fix processing object method signatures

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: do not use uloop_run() inside ubus_complete_request
Felix Fietkau [Tue, 18 Mar 2014 21:36:36 +0000 (22:36 +0100)]
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>
10 years agolibubus-internal: use the __hidden definition from libubox
Felix Fietkau [Tue, 18 Mar 2014 21:12:21 +0000 (22:12 +0100)]
libubus-internal: use the __hidden definition from libubox

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agolibubus: close file descriptor after passing it in the status msg
Felix Fietkau [Thu, 27 Feb 2014 15:48:53 +0000 (16:48 +0100)]
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>
10 years agoubus: Fix imbalance in lua stack push/pop of values.
Karl Vogel [Tue, 11 Feb 2014 08:27:36 +0000 (09:27 +0100)]
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>
10 years agoexamples/client: receive data from the passed file descriptor
Felix Fietkau [Tue, 18 Feb 2014 14:03:44 +0000 (15:03 +0100)]
examples/client: receive data from the passed file descriptor

Signed-off-by: Felix Fietkau <nbd@openwrt.org>