sh/jshn.sh: add json_for_each_item() Function usefull to iterate through the different elements of an array or object; the provided callback function is called for each element which is passed the value, key and user provided arguments. For field types different from array or object the callback is called with the retrieved value. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> Acked-by: Jo-Philipp Wich <jo@mein.io>
jshn: add functionality to read big JSON The existing read functionality feeds the complete JSON to jshn as a cmdline argument, leading to `-ash: jshn: Argument list too long` errors for JSONs bigger than ca. 100KB. This commit adds the ability to read the JSON directly from a file if wanted, removing this shell-imposed size limit. Tested on x86-64 and ar71xx. An mmap()-based solution was also evaluated, but found to make no performance difference on either platform. Signed-off-by: Christian Beier <dontmind@freeshell.org>
jshn: read and write 64-bit integers This allows for reading in and writing out bigger JSON Numbers. Following test script (that fails to print correct values _without_ this commit) verifies the functionality (tested on x86-64 as well as on ar71xx): ---snip--- # assumes you built jshn and sourced jshn.sh echo testing reading-in JSON SHELL_BIGNUM=12147483647 json_init json_load "{ \"bignum\": $SHELL_BIGNUM }" json_get_var BIGNUM bignum echo jshn bignum: $BIGNUM echo shll bignum: $SHELL_BIGNUM echo testing writing-out JSON json_init json_add_int bigint $SHELL_BIGNUM json_dump --snap--- Signed-off-by: Christian Beier <dontmind@freeshell.org>
utils: nuke bitfield functions and macros The bitfield functions and macros were committed without explaining their purpose in the commit message. As they are only used in uci, and conflict with similar functions added in hostapd, breaking our hostapd ubus patch, nuke them from libubox and add them in uci instead. If we need them anywhere else in the future we can add it to libubox again, but preferably prefixed with ubox_. Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
uloop: make SIGCHLD signal handling optional Some programs want to manage their own child life cycle without using SIGCHLD signal handler. In these cases, uloop is reaping children for them because they don't have SIGCHLD handler set. This patch makes it possible to disable reaping children through 'uloop_handle_sigchld' variable. Signed-off-by: Petar Paradzik <petar.paradzik@sartura.hr>
uloop: Fix race condition in SIGCHLD handling When uloop_process_add() is called outside of uloop_run(), i.e. not from a callback (which is the case of at least utrace and ujail), child events can be missed. The reason is that when SIGCHILD handler is installed in uloop_run(), after the uloop_process_add() is called, then an initial signal could be missed. Commit 4e3a47a ("uloop: use a waker for notifying sigchld and loop cancel events", 2016-06-09) solved a similar problem and introduced uloop_init() but forgot to move a call to uloop_setup_signals() there. This is what this commit does. Now, uloop_process_add() can be called any time after uloop_init() without missing any event. Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz> Acked-by: Yousong Zhou <yszhou4tech@gmail.com>
json_script: enable custom expr handler callback This wires in custom expression handler functionality, which was present in json script since the original version, but never used. Signed-off-by: Denis Osvald <denis.osvald@sartura.hr> Signed-off-by: Felix Fietkau <nbd@nbd.name> [error handling fix]
md5: add "const" qualifier to the "file" argument This is intended to fix the following compiler warning in opkg-lede: /home/yousong/git-repo/lede-project/opkg-lede/libopkg/file_util.c: In function ‘file_md5sum_alloc’: /home/yousong/git-repo/lede-project/opkg-lede/libopkg/file_util.c:144:2: warning: passing argument 1 of ‘md5sum’ discards ‘const’ qualifier from pointer target type [enabled by default] In file included from /home/yousong/git-repo/lede-project/opkg-lede/libopkg/file_util.c:28:0: /home/yousong/.usr/include/libubox/md5.h:56:5: note: expected ‘char *’ but argument is of type ‘const char *’ Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>