Commit Graph

1744 Commits

Author SHA1 Message Date
Jan Pokorný
7f0dc55b8f
doc: qbloop.h: document pros/cons of using built-in event loop impl
Make the qbipcs.h module interdependence clear (also shedding light to
some semantic dependencies) as well.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-07 17:37:23 +02:00
Jan Pokorný
83da9f2109
IPC: server: fix debug message wrt. what actually went wrong
It's misleading towards a random code observer, at least,
hiding the fact that what failed is actually the queing up
of some handling to perform asynchronously in the future,
rather than invoking it synchronously right away.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-05 10:38:32 +02:00
Jan Pokorný
97adfa6ba0
IPC: server: avoid temporary channel priority loss, up to deadlock-worth
It turns out that while 7f56f58 allowed for less blocking (thus
throughput increasing) initial handling of connections from clients
within the abstract (out-of-libqb managed) event loop, it unfortunately
subscribes itself back to such polling mechanism for UNIX-socket-check
with a default priority, which can be lower than desired (via explicit
qb_ipcs_request_rate_limit() configuration) for particular channel
(amongst attention-competing siblings in the pool, the term here
refers to associated communication, that is, both server and
on-server abstraction for particular clients).  And priority-based
discrepancies are not forgiven in true priority abiding systems
(that is, unlikele with libqb's native event loop harness as detailed
in the previous commit, for which this would be soft-torelated hence
the problem would not be spotted in the first place -- but that's
expliicitly excluded from further discussion).

On top of that, it violates the natural assumption that once (single
threaded, which is imposed by libqb, at least between initial accept()
and after-said-UNIX-socket-check) server accepts the connection, it
shall rather take care of serving it (at least within stated initial
scope of client connection life cycle) rather than be rushing to accept
new ones -- which is exactly what used to happen previously once the
library user set the effectively priority in the abstract poll
above the default one.

It's conceivable, just as with the former case of attention-competing
siblings with higher priority whereby they could _infinitely_ live on
at the expense of starving the client in the initial handling phase
(authentication) despite the library user's as-high-as-siblings
intention (for using the default priority for that unconditionally
instead, which we address here), the dead lock is imminent also in
this latter accept-to-client-authentication-handling case as well
if there's an _unlimited_ fast-paced arrival queue (well, limited
by with number of allowable open descriptors within the system,
but for the Linux built-in maximum of 1M, there may be no practical
difference, at least for time-sensitive applications).

The only hope then is that such dead-locks are rather theoretical,
since a "spontaneous" constant stream of either communication on
unrelated, higher-prio sibling channels, or of new connection arrivals
can as well testify the poor design of the libqb's IPC application.
That being said, unconditional default priority in the isolated
context of initial server-side client authentication is clearly
a bug, but such application shall apply appropriate rate-limiting
measures (exactly on priority basis) to handle unexpected flux
nonetheless.

The fix makes test_ipc_dispatch_*_glib_prio_deadlock_provoke tests pass.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-05 10:36:55 +02:00
Jan Pokorný
28e725938a
tests: ipc: check deadlock-like situation due to mixing priorities
Compared to the outer world, libqb brings rather unintuitive approach
to priorities within a native event loop (qbloop.h) -- it doesn't do
an exhaustive high-to-low priorities in a batched (clean-the-level)
manner, but rather linearly adds a possibility to pick the handling
task from the higher priority level as opposed to lower priority ones.

This has the advantage of limiting the chances of starvation and
deadlock opportunities in the incorrectly constructed SW, on the other
hand, it means that libqb is not fulfilling the architected intentions
regarding what deserves a priority truthfully, so these priorities are
worth just a hint rather than urgency-based separation.

And consequently, a discovery of these deadlocks etc. is deferred to
the (as Murphy's laws have it) least convenient moment, e.g., when
said native event loop is exchanged for other (this time priority
trully abiding, like GLib) implementation, while retaining the same
basic notion and high-level handling of priorities on libqb
side, in IPC server (service handling) context.

Hence, demonstration of such a degenerate blocking is not trivial,
and we must defer such other event loop implementation.  After this
hassle, we are rewarded with a practical proof said "high-level
handling [...] in IPC server (service handling) context" contains
a bug (which we are going to subsequently fix) -- this is contrasted
with libqb's native loop implementation that works just fine even
prior that fix.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:07:27 +02:00
Jan Pokorný
2ced1b4341
tests: ipc: refactor/split test_ipc_dispatch part into client_dispatch
This way, this core part can be easily reused where needed.
Note that "ready_signaller" similarity with run_ipc_server is not
accidental, following commit will justify it.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:54 +02:00
Jan Pokorný
c54e2712a6
tests: ipc: allow for easier tests debugging by discerning PIDs/roles
Roles specifications are currently not applied and are rather
a preparation for the actual meaningful use to come.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:52 +02:00
Jan Pokorný
c3175eabd3
tests: ipc: speed the suite up with avoiding expendable sleep(3)s
Using i7-6820HQ CPU yields these results:

Before: ~2:54
After: ~2:26
Speedup: ~16%

The main optimization lies in how run_function_in_new_process helper is
constructed, since now, there's an actual synchronization between the
parent and its child (that needs to be prioritized here, which is
furthermore help with making the parent immediately give up it's
processor possession) after the fork, so that a subsequent sleep is
completely omitted -- at worst (unlikely), additional sleep round(s)
will need to be undertaken as already arranged for (and now, just
400 ms is waited rather than excessive 1 second).

Another slight optimization is likewise in omission of sleep where
the control gets returned to once the waited for process has been
suceesfully examined post-mortem, without worries it's previous
life is still resounding.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:48 +02:00
Jan Pokorný
571e162990
tests: ipc: avoid problems when UNIX_PATH_MAX (108) limits is hit
There's some slight reserve for when bigger PID ranges are in use.
The method to yield the limit on prefix string was derived from
practical experience (rather than based on exact calculations).

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:44 +02:00
Ferenc Wágner
d90d45f576 doc: qbarray: reword comment about index partitioning 2019-05-07 14:46:02 +01:00
Ferenc Wágner
5f1b3f57d7 doc: qbarray.h: remove stray asterisk and parentheses 2019-05-07 14:46:02 +01:00
Ferenc Wágner
94c8192b6e Update changelog for 1.0.5-1 release 2019-04-26 15:52:31 +02:00
Ferenc Wágner
e36150cc77 New patch: doc: qbarray.h: remove stray asterisk 2019-04-26 15:46:29 +02:00
Ferenc Wágner
ff391813b8 Remove upstreamed patches, refresh the Hurd support patch 2019-04-26 14:22:06 +02:00
Ferenc Wágner
711e390446 Merge tag 'upstream/1.0.5' into debian/master
Upstream version 1.0.5
2019-04-26 14:17:40 +02:00
Ferenc Wágner
b862a98839 New upstream version 1.0.5 2019-04-26 14:17:30 +02:00
Christine Caulfield
d08dbcf08b version: bump soname for 1.0.5 release 2019-04-25 09:13:19 +01:00
Ferenc Wágner
1699bf4e29 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.
2019-04-23 14:02:56 +01:00
Ferenc Wágner
4aa460891e 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().
2019-04-23 14:02:56 +01:00
Ferenc Wágner
65d6fb37a2 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.
2019-04-23 14:02:56 +01:00
Ferenc Wágner
802f5f98ed Errors are represented as negative values 2019-04-23 14:02:56 +01:00
Ferenc Wágner
bd7b502762 Fix garbled Doxygen markup
Part of d0ec0a6 on the master branch: fix the unreadable docstring.
2019-04-23 14:02:56 +01:00
Ferenc Wágner
499874c004 Fix spelling: plaform -> platform 2019-04-23 14:02:56 +01:00
Ferenc Wágner
0a190da51b Update changelog for 1.0.4-2 release 2019-04-18 18:42:32 +02:00
Ferenc Wágner
706317618a New patch: Let remote_tempdir() assume a NUL-terminated name 2019-04-18 18:37:22 +02:00
Ferenc Wágner
3365b9d9bf New patch: Make it impossible to truncate or overflow the connection description 2019-04-18 18:37:22 +02:00
Ferenc Wágner
58781005db New patch: Allow group access to the IPC directory 2019-04-18 18:37:22 +02:00
Ferenc Wágner
0e7a72dea6 New patch: Errors are represented as negative values 2019-04-17 15:10:02 +02:00
Ferenc Wágner
55468ba203 tests: let ipcserver clean up /dev/shm after ipcclient finishes 2019-04-16 15:26:43 +02:00
Ferenc Wágner
95f608a4fa Update changelog for 1.0.4-1 release 2019-04-16 11:32:42 +02:00
Ferenc Wágner
174d21057f New patch: Fix garbled Doxygen markup 2019-04-16 11:31:02 +02:00
Ferenc Wágner
88aafa5c9c Update Standards-Version to 4.3.0 (no changes required) 2019-04-16 11:31:01 +02:00
Ferenc Wágner
0823bf1c54 Acknowledge new internal symbol 2019-04-16 11:31:01 +02:00
Ferenc Wágner
e36e34a67a Refresh our patches 2019-04-16 11:31:01 +02:00
Ferenc Wágner
405db85f3e Kick off changelog for 1.0.4-1 release 2019-04-16 11:30:37 +02:00
Ferenc Wágner
dc825fb9c3 Merge tag 'upstream/1.0.4' into debian/master
Upstream version 1.0.4
2019-04-15 18:51:09 +02:00
Ferenc Wágner
50b5444d02 New upstream version 1.0.4 2019-04-15 18:51:00 +02:00
Christine Caulfield
dc78f42226 version: update version-info for 1.0.4 release 2019-04-12 09:29:06 +01:00
Christine Caulfield
f950a5d3f8 ipc: Use mkdtemp for more secure IPC files
Use mkdtemp makes sure that IPC files are only visible to the
owning (client) process and do not use predictable names outside
of that.

This is not meant to be the last word on the subject, it's mainly a
simple way of making the current libqb more secure. Importantly, it's
backwards compatible with an old server.

It calls rmdir on the directory created by mkdtemp way too often, but
it seems to be the only way to be sure that things get cleaned up on
the various types of server/client exit. I'm sure we can come up with
something tidier for master but I hope this, or something similar, will
be OK for 1.0.x.
2019-04-09 10:56:51 +01:00
Christine Caulfield
6a4067c1d1 ipc: Use mkdtemp for more secure IPC files
Use mkdtemp makes sure that IPC files are only visible to the
owning (client) process and do not use predictable names outside
of that.

This is not meant to be the last word on the subject, it's mainly a
simple way of making the current libqb more secure. Importantly, it's
backwards compatible with an old server.

It calls rmdir on the directory created by mkdtemp way too often, but
it seems to be the only way to be sure that things get cleaned up on
the various types of server/client exit. I'm sure we can come up with
something tidier for master but I hope this, or something similar, will
be OK for 1.0.x.
2019-04-08 16:24:19 +01:00
Christine Caulfield
269a0ca007 ipc: use O_EXCL when opening IPC files 2019-04-08 13:31:38 +01:00
Christine Caulfield
7cd7b06d52 ipc: fixes
Use O_EXCL on IPC files
2019-04-08 13:18:34 +01:00
Christine Caulfield
e322e98dc2 ipc: use O_EXCL on SHM files, and randomize the names
Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2019-04-08 13:18:34 +01:00
Christine Caulfield
a5216040d3 tests: allow blackbox-segfault.sh to run out-of-tree 2019-03-26 11:31:05 +00:00
Fabio M. Di Nitto
e6c7798fae [tests] first pass at fixing test execution
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2019-03-26 11:31:05 +00:00
Fabio M. Di Nitto
44386edf7d [tests] enable building / shipping of libqb-tests.rpm
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2019-03-26 11:31:05 +00:00
Fabio M. Di Nitto
6255a1466c [tests] allow installation of test suite
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2019-03-26 11:31:05 +00:00
Fabio M. Di Nitto
d3d32bc281 [tests] export SOCKETDIR from tests/Makefile.am
allows make check to be executed correctly from tests/ dir.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2019-03-26 11:31:05 +00:00
Fabio M. Di Nitto
5ddc2eb954 [test-rpm] build test binaries by default
build test binaries at "make" or "make all" instead of "make check".

this is necessary if it´s not possible to run make check during make rpm.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2019-03-26 11:31:05 +00:00
Jan Pokorný
c880fcfd8d
build: configure: fix "snapshot consumption" feature on FreeBSD
There were a few missed leftovers in d6875f2 regarding compatibility
with sed on FreeBSD (some commands do require a newline and/or
backslash separation).

Merges: #335
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-01-15 00:24:37 +01:00
wferi
f67b428111 Add Pthreads (and possibly other) flags to the pkg-config file (#332)
Proper Libs.private enables linking applications statically against
libqb: static archives (.a) don't carry their own dependency
information, unlike shared libraries (.so).  Modern libc versions
include socket and RT functions, so socket_LIBS and rt_LIBS will be
empty there, but we include them for strict correctness on older
platforms; basically, we're matching libqb_la_LIBADD here.
Consequently, nsl_LIBS and GLIB_LIBS don't enter this field, since they
are only used in the examples and tests, not in the library proper.

Cflags, on the other hand, is emitted all the time and (under GCC)
propagates the -pthread option (which also affects the preprocessing
stage) to all users of libqb even when compiling modules or linking
everything dynamically.

Signed-off-by: Ferenc Wágner <wferi@debian.org>
2018-12-13 08:25:57 +00:00