This creates a mapping with twice the size of the allocated memory. The
second half of that mapping points at the same memory as the first half.
This is useful for ring buffers, because any read starting in the first
half can overflow into the second half as long as the read size is
smaller than the size of the memory area.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
ev.data is a union, so setting ev.data.fd is lost after setting
ev.data.ptr
Reported-by: Song Yaofei <songyaofei@joyware.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
The current blobmsg_format_json* functions will return invalid JSON when
the "list" argument is given as false (blobmsg_format_element() will
output the name of the blob_attr as if the value is printed as part of a
JSON object).
To avoid breaking software relying on this behaviour, introduce new
functions which will never print the blob_attr name and thus always
produce valid JSON.
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Acked-by: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Felix Fietkau <nbd@nbd.name> [cosmetic style fix]
Recent glibc warns if result of read() or write() is unused.
Added a retry in case of EINTR, all other faults are silently discarded.
Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
-----
- I was not able to reproduce the EINTR case, but it seems to be the right
thing to do
- Retrying on EAGAIN in this case would be weird as there is no one to read
from the other end of the pipe. We could call waker_consume() directly but
since the size of the message is just one byte, I think this would be dead
code
When a process quits in response to a signal it handles, it should to so
be re-sending the signal to itself. This especially important for SIGINT,
as is explained in [1].
uloop currently hides the reason for quitting uloop_run(). Fix this by
returning the signal that caused the loop to quit (or 0 when uloop_end()
was used), so a program using loop an comply with [1].
[1] https://www.cons.org/cracauer/sigint.html
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Consistently handle allocation failures. Some functions are changed to
return bool or int instead of void to allow returning an error.
Also fix a buffer size miscalculation in lua/uloop and use _exit() instead
of exit() on errors after forking.
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Fix a race condition when do_sigchld, uloop_cancelled were set just
before epoll_wait(timeout=-1), resulting the loop stuck in the syscall
without noticing the events just happened
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
We already serialize BLOBMSG_TYPE_UNSPEC as "null" so represent JSON null
values as blob attribute type unspec with payload size zero.
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Different distributions have different names for the lua 5.1 package.
Use cmake's built in pkg-config support to search for the first one,
rather than running it explicitly and searching for a single version.
Signed-off-by: Karl Palsson <karlp@remake.is>
Race is possible in ulog_kmsg(): if no /dev/kmsg exists
(e.g. while /dev gets re-mounted) regular file created instead.
>From this point system goes without kernel logger:
special character file can't be created anymore, all clients keep
overwriting single message in regular file.
To avoid this we open file in "r+" mode which doesn't create
file if it's not found.
Signed-off-by: Sergiy Kibrik <sakib@meta.ua>
Cc: John Crispin <blogic@openwrt.org>
The default uloop error handling is to delete the fd. Continue to do
that, but also set the write_error flag and notify the user.
Signed-off-by: Philip Craig <philipjcraig@gmail.com>
Add ability to skip building the examples. The default value is ON to follow
the original cmake behavior.
Signed-off-by: Nikolay Dimitrov <picmaster@mail.bg>
User's s->notify_read is called in ustream_fill_read(). If
s->read_blocked is set there, then stop reading more.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
No functional change.
- Reuse existing NULL check on buf.
- Add some comments for ease of reading the code.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Use PKG_SEARCH_MODULE() to detect json-c library,
otherwise the search fails, if both json-c and json
are not present in pkg-config database.
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>