Commit Graph

843 Commits

Author SHA1 Message Date
Ken Gaillot
1070cbc17c
Make some logs less noisy (#495)
* log: lower IPC connection issues to info level

... in handle_new_connection(). The caller has better context for whether a
problem merits a warning or error, and the function's return code is
sufficiently descriptive to do so. Some problems may be expected or able to be
worked around.

For example, Pacemaker's crm_mon attempts to contact pacemakerd IPC. On a
Pacemaker Remote node, that IPC will be unavailable, and crm_mon can check the
libqb return code to detect and handle that situation gracefully.

* log: lower some ringbuffer debug messages to trace level

They're rather noisy, with every shm-based IPC connection generating multiple
obscure messages like:

  debug: shm size:1048589; real_size:1052672; rb->word_size:263168

and every disconnect generating the rather unhelpful:

  debug: qb_ipcc_disconnect()

along with multiple messages like:

  debug: Closing ringbuffer: /dev/shm/qb-10986-11014-34-26VRvs/qb-request-cmap-header

All of these seem appropriate to trace level.
2024-01-31 09:44:16 +00:00
Chrissie Caulfield
9297df4e48
Change assert in ringbuffer to a return code (#492)
Why just this one?

There are LOADS of asserts in libqb, some are OK and some may be
overkill. This one in particular is causing CI failures
and so annoys me more than the rest.
2023-11-15 09:03:52 +00:00
Christine Caulfield
002171bbcf Update library version for 2.0.8 2023-07-21 12:30:39 +01:00
Chrissie Caulfield
1bbaa929b7
log: fix potential overflow with long log messages (#490)
qb_vsnprintf_serialize was called with 'max_size' as the
limiting number for the length of the formatted log
message. But the buffer also needs to contain the
log header (given by 'actual_size'), so we now pass
't->max_line_length' as the maximum length of the
formatted log message to limit space to the actual 
bytes left

Also added error checks to the blackbox calls at
the end of the test, as these now provide a proper
test that the BB is functioning. Before they were
masking failures.
2023-07-20 07:19:01 +01:00
Christine Caulfield
06c8641de2 Update -version info for 2.0.7 2023-06-07 07:50:17 +01:00
Chrissie Caulfield
5862acbaef
blackbox: fix potential overlow/memory corruption (#486)
if the message was too long, then msg_len was added to the
buffer size twice, thus causing potential data corruption
(seen VERY rarely in the CI test - or, at least, I think it was
this).

Also fix a double close() spotted by gcc13's -fanalyzer
2023-06-05 09:51:38 +01:00
wferi
4dcdfe9856
strlcpy: avoid compiler warning from strncpy (#473)
Otherwise GCC complains about ‘__builtin_strncpy’ specified bound
depends on the length of the source argument.

Signed-off-by: Ferenc Wágner <wferi@debian.org>
2023-03-23 12:56:19 +00:00
Chrissie Caulfield
fde729e137
timer: Move state check to before time check (#479)
A timer in QB_POLL_ENTRY_JOBLIST doesn't necessarily
have a t->timerlist_handle so that deref can segv. Also
the comment assumes the timers are threaded - which as we have
decided is definitely not true. So it's safe to move the check
earlier.

In the tests, I've adjusted the timeouts so that they definitely
happen at different times. On some architectures they can fire
concurrently and in the wrong order.
2023-01-05 14:45:22 +00:00
Chrissie Caulfield
5594d377ac
ipc: Retry receiving credentials if the the message is short (#476)
ipc: Retry receiving credentials if the the message is short

rhbz#2111711 refers
2022-11-25 07:38:20 +00:00
Chrissie Caulfield
eaa95ecf03
lib: Fix some small bugs spotted by newest covscan (#471)
* lib: Fix some small bugs spotted by newest covscan
2022-08-17 13:17:33 +01:00
Christine Caulfield
ccdaadabe6 Bump version for 2.0.5 release 2022-03-21 09:14:52 +00:00
Chrissie Caulfield
06e318fdc0
blackbox: Sanitize items read from the blackbox header (#438)
covscan complained we don't check the blackbox header when
reading it in. (quite reasonably)

Note that we still get a covscan error for ->shared_data, but that's
really impossible to verify in the read routine, so I'll leave the
covscan waiver to handle that.
2022-03-18 10:04:58 +00:00
Chrissie Caulfield
2d03793eb0
unix: Don't fail on FreeBSD running ZFS (#461)
* unix: Don't fail on FreeBSD running ZFS

ZFS doesn't support posix_fallocate() so libqb IPC or RB would
always fail with EINVAL.

As there seems to be no prospect of a more useful return code,
trap it in a QB_BSD #ifdef. That way if we do have actual errors
in the posix_fallocate() call the Linux tests should still find them.

Also, stick a small sleep in the test_ipc_disconnect_after_created
test to allow the server to shutdown before killing it with SIGTERM
and causing a test failure. all the other uses of it seem to have this
sleep!
2022-03-17 07:47:39 +00:00
Christine Caulfield
f5106342d0 ipcc: Fix errno returned from qb_ipcc_connect
The errno value from qb_ipcc_connect was incorrectly negated
when I introduced qb_ipcc_async_connect()
2022-03-03 07:29:07 +00:00
Ken Gaillot
3fb2b59751 util: reimplement time functions as a series of fallbacks
Previously, when clock_gettime() was available, the time functions would use
that (regardless of success or failure), otherwise they would use
gettimeofday() if available.

Now, the functions first try clock_gettime() if available, but if that is
unavailable or fails, they then try gettimeofday() if available, but if that is
not available or fails, they try time().
2022-02-14 12:25:19 +00:00
Ken Gaillot
da12cc9695 util: use HAVE_GETTIMEOFDAY where appropriate
configure.ac already defined HAVE_GETTIMEOFDAY, but the uses of gettimeofday()
weren't guarded by it. It obviously doesn't matter on any currently supported
platforms, but it will be needed for planned changes.
2022-02-14 12:25:19 +00:00
Ken Gaillot
354c0c2531 util: drop HAVE_CLOCK_GETRES_MONOTONIC configure constant
It doesn't provide a significant benefit over just trying the call.
It was added by 6bd3f086 for Hurd support.
2022-02-14 12:25:19 +00:00
Ken Gaillot
1e67908580 util: add constant for which realtime clock to use
... to reduce code duplication and improve readability
2022-02-14 12:25:19 +00:00
Ken Gaillot
4f82b0b6c4 util: refactor so ifdef's are withing each time-related function
The time-related functions have two implementations, one if clock_gettime() is
available and the other if not.

Previously, there was one big ifdef-else with the clock_gettime()
implementation of each function followed by the other implementation of each
function.

With this commit, each function is defined once, with an ifdef-else inside it
with the two implementations of that function. For ease of review, no other
code changes are made, but the intent will become obvious with later changes.
2022-02-14 12:25:19 +00:00
Jakub Jankowski
176eae8f13
Retry if posix_fallocate is interrupted with EINTR (#453)
Every now and then Pacemaker reports errors:

  (pcmk__new_client)        debug: New IPC client 3efdbecf-c2d9-44bc-b4a6-9bcd48021ba1 for PID 27492 with uid 0 and gid 0
  (handle_new_connection)   debug: IPC credentials authenticated (/dev/shm/qb-7271-27492-12-hfPbKY/qb)
  (qb_ipcs_shm_connect)     debug: connecting to client [27492]
  (qb_rb_open_2)    debug: shm size:524301; real_size:528384; rb->word_size:132096
  (qb_rb_open_2)    debug: shm size:524301; real_size:528384; rb->word_size:132096
  (qb_sys_mmap_file_open)   error: couldn't allocate file /dev/shm/qb-7271-27492-12-hfPbKY/qb-event-cib_rw-data: Interrupted system call (4)
  (qb_rb_open_2)    error: couldn't create file for mmap
  (qb_ipcs_shm_rb_open)     error: qb_rb_open:/dev/shm/qb-7271-27492-12-hfPbKY/qb-event-cib_rw: Interrupted system call (4)
  (qb_rb_close_helper)      debug: Free'ing ringbuffer: /dev/shm/qb-7271-27492-12-hfPbKY/qb-response-cib_rw-header
  (qb_rb_close_helper)      debug: Free'ing ringbuffer: /dev/shm/qb-7271-27492-12-hfPbKY/qb-request-cib_rw-header
  (qb_ipcs_shm_connect)     error: shm connection FAILED: Interrupted system call (4)
  (handle_new_connection)   error: Error in connection setup (/dev/shm/qb-7271-27492-12-hfPbKY/qb): Interrupted system call (4)

While it probably might be addressed in Pacemaker code, a simple retry
loop in case posix_fallocate(3) returns EINTR seems to be a decent
workaround.

Fixes: #451

Signed-off-by: Jakub Jankowski <shasta@toxcorp.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
2022-01-14 07:57:25 +00:00
Chrissie Caulfield
de5ab3029c
ipcc: Add an async connect API (#450) 2022-01-05 10:53:09 +00:00
Christine Caulfield
a2691b9618 Bump library version for v2.0.4 2021-11-12 13:18:47 +00:00
Chrissie Caulfield
d4b49fb5e9
poll: Don't log in a signal handler (#447)
qb_log calls malloc() and probably many other non-signal-safe
functions, so don't call it in the signal handler.

Thanks to Honza for spotting this

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2021-11-10 12:35:07 +00:00
Chrissie Caulfield
a60ca50b67
Fix pthread returns (#444)
pthread calls do not set errno, they return the error directly
2021-08-11 07:55:42 +01:00
Jan Friesse
48fff5eb58
Implement heap based timer list (#439)
* tlist: Add heap based implementation of timer list

Previous timer was sorted list implementation of priority queue
and very slow when number of timers increased. This is mostly
not a problem because usually only few timers are used.
But for application where bigger number of timers are needed
it may become problem.

Solution is to use binary heap based priority queue which is much
faster.

API is unchanged, just timerlist_destroy is added which should be called
to free heap array. This function also destroys mutex (omitted when
mutex was added).

* tests: Fix check loop mt test

test_th was accesed both by main thread and loop_timer thread resulting in
failure. Fix is to access test_tht in loop_timer thread.

Speed test is adding only 10000 items so it is reasonable
fast even with sorted linked list implementation.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
2021-03-18 07:27:25 +00:00
Christine Caulfield
404adbcd99 release: bump library version for 2.0.3 release 2021-03-03 08:32:09 +00:00
Aleksei Burlakov
aae7a0aa5d
syslog: Add a message-id parameter for messages (#433)
The message-id parameter will enable systemd catalogs.
To enable message-id's the libqb should be configured with the
 --enable-systemd-journal option.

Co-authored-by: root <Aleksei Burlakov>
2021-03-01 15:58:50 +00:00
Chrissie Caulfield
d6e2bd1d6b
timers: Add some locking (#436)
Fix several locking issues reported by helgrind
2021-02-08 10:57:42 +00:00
Chrissie Caulfield
991872eded
ipcc: Have a few goes at tidying up after a dead server (#434)
This is an attempt to make sure that /dev/shm is cleaned up when a
server exits unexpectedly. Normally it's the server's responsibility
to tidy up sockets, but if it crashes or is killed with SIGKILL then
the client (us) makes a reasonable attempt to tidy up the server sockets
we have connected. The extra delay here just gives the server chance to
disappear fully. As a client we can get here pretty quickly but shutting
down a large server may take a little longer even when SIGKILLed.
The 1/100th of a second is an arbitrary delay (of course) but seems to
catch most servers in 2 tries or less.
2021-01-25 12:19:10 +00:00
Chrissie Caulfield
5097155bdf
strlcpy: Check for maxlen underflow (#432)
* strlcpy: Check for maxlen underflow

https://github.com/ClusterLabs/libqb/issues/429

* Always terminate the string if maxlen is > 0
2021-01-13 14:12:02 +00:00
Christine Caulfield
def947efcf lib: Update library version for 2.0.2 release
Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2020-12-03 13:05:43 +00:00
Hideo Yamauchi
51f181b3cd
ipcs : Decrease log level. (#426)
of ipcs event notification 'errors' that can occur in normal use.
2020-12-03 11:33:30 +00:00
Chrissie Caulfield
06ac2d43a9
cov: Quieten some covscan warnings (#427) 2020-12-03 09:39:28 +00:00
Chrissie Caulfield
51f64ed233
ipcs: ftruncate is not support on WIN32 (#424)
https://github.com/microsoft/WSL/issues/902
2020-10-05 08:08:48 +01:00
Chrissie Caulfield
a52d912675
ipcs: Add missing qb_list_del when freeing server (#423)
* ipcs: Remove list not used

Thanks to minhbq for pointing this out
2020-10-05 08:08:09 +01:00
Chrissie Caulfield
680db526f6
ipc: add qb_ipcc_auth_get() API call (#418)
* ipc: addd qb_ipcc_auth_get() API call

We can't use SO_PEERCRED on the client fd when using socket IPC
becayse it's a DGRAM socket (pacemaker tries this). So provide
an API to get the server credentials that libqb has already
squirreled away for its own purposes.

Also, fix some unused-variable compiler warnings in unix.c
when building on systems without posix_fallocate().
2020-09-28 09:53:21 +01:00
Christine Caulfield
416caf2b92 Bump version for 2.0.1 2020-07-29 08:28:23 +01:00
wladmis
1c6229c171
unix.c: use posix_fallocate() (#409)
Using of posix_fallocate() guarantees that, if it succeed, the
attempting to write to allocated space range does not fail because of
lack of storage space. This prevents SIGBUS when trying to write to
mmaped file and no space left.

Co-Authored-by: Ivan Zakharyaschev <imz@altlinux.org>
Reported-by: Mikhail Kulagin <m.kulagin at postgrespro dot ru>

Co-authored-by: Ivan Zakharyaschev <imz@altlinux.org>
2020-07-29 07:37:09 +01:00
Chrissie Caulfield
b2acdea2a8
array: More locking fixes (#400)
* array: More locking fixes

helgrind threw out a couple more locking errors in the logging/array
code and we also need to protect a->max_elements
2020-06-08 14:16:58 +01:00
Chrissie Caulfield
49641930d8
log: Fix threading races (#396)
It's possible that cs->filename or cs->format could be read
in the 'fast' path while the 'slow' path is still constructing
the object. So we need to lock arr_next_lock before copying them
out for the caller.

Also wthread_should_exit was unprotected.
2020-06-01 15:41:26 +01:00
Chrissie Caulfield
bdc716036a
Some bugs spotted by coverity (#399) 2020-05-28 07:30:26 +01:00
Jan Pokorný
803d9242ff log: journal: fix forgotten syslog reload when flipped from journal
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2020-05-04 08:32:47 +01:00
Ferenc Wágner
2baa2791ce Let remote_tempdir() assume a NUL-terminated name
This is the case already.  We also fix a buffer overflow opportunity in
the memcpy() call by this change.

Conflicts:
	lib/ipc_shm.c
2020-05-01 12:57:51 +01:00
Ferenc Wágner
e26ad0dae1 Make it impossible to truncate or overflow the connection description
It's hard to predict the length of formatted output, so we'd better
notice (and abort) if the description is truncated.  Incidentally,
mkdtemp() does this for us in the shared memory branch, but do an
explicit check there as well for consistency, and get rid of the wrongly
parametrized strncat() risking a buffer overflow (CONNECTION_DESCRIPTION
is not the length of the source "/qb").

Similar truncation checks should be added to qb_ipcs_{shm,us}_connect()
where they build the request/response names, and possibly to other
places using snprintf().
2020-05-01 12:54:30 +01:00
Chris Murphy
08806c5301
master: Issue 390: Clarify documentation of qb_loop_timer_expire_time_get and provide new function to return previously documented behavior (#391)
Includes unit test addition by chrissie-c
2020-04-29 13:20:52 +01:00
Chrissie Caulfield
1daca57c10
trie: Don't assume that chars are unsigned < 126 (#386)
* trie: Don't assume that chars are unsigned < 126

Trie fails on systems with unsigned chars when using characters over
126.
2020-03-09 08:14:39 +00:00
Jonas Witschel
99671f4d75 Set correct ownership if qb_ipcs_connection_auth_set() has been used
When qb_ipcs_connection_auth_set() has been used, the ownership of the
temp directory initially set by handle_new_connection() must be updated
as well.
2020-02-10 11:21:45 +01:00
Ferenc Wágner
700fb2b27e Allow group access to the IPC directory
And don't abort if we aren't permitted to chown() it.  The client might
still have the privileges to enter it.
2020-02-10 10:57:16 +01:00
Ferenc Wágner
a8301de262 Errors are represented as negative values 2020-02-10 10:57:01 +01:00
Jan Pokorný
7f891f0069 build: allow for possible v1 branch continuity by generous SONAME offset
The main and the most ABI-touching thing for the envisioned 2.0 branch
is the usage of the linker-build-time allocated callsite info, avoiding
the non-economic evaluations and, under some circumstances dangerous,
heap allocations in the run-time.

Considering that v1.9.0 release (libqb.so.20) was expressly marked as
tech-preview[1,2] (hence something that shall not make it to production
use), there should be no harm for master branch (that is headed towards
2.0 and beyond) to receive noticable SONAME bump (libqb.so.100) so as to

- leave enough of space for a possible v1-compatible branch evolution
  (for use cases where recompile-everything is a no-go).
  in particular, with resuming with libqb.so.30, there would
  be a room for 99-33 = 63 add-new-drop-nothing compatible
  changes for that branch (which is more than plentiful)

- indicate some big change is going on more clearly towards client space

This is supposed to be a reasonable trade-off solution that would still
leave enough wiggle space, and would represent responsible approach to the
development (like the original attempt to prevent ABI break in the first
place was), allowing for more than an enforced unanimity (rather
antagonistic in the free software realms).

[1] https://lists.clusterlabs.org/pipermail/users/2019-December/026690.html
[2] https://github.com/ClusterLabs/libqb/releases/tag/1.9.0

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2020-01-10 12:27:35 +00:00