Commit Graph

20 Commits

Author SHA1 Message Date
Eric Wild 7f1fb3ea81 Revert "logging: add log level cache"
This reverts commit 7dc6d4a629.

Reason for revert: other tests are failing

Change-Id: Ife4c49d1bb933e983ac68c57970c9c49b40e08be
2024-01-09 16:37:05 +00:00
Eric Wild 7dc6d4a629 logging: add log level cache
This ensures multithreaded logging attempts, in particular ones that do
nothing, do not hold the lock just for checking the level, which
interferes with other logging attempts.

Closes: OS#5818

Change-Id: I35f8dd9127dd6e7feae392094fd6b3ce2d32558d
2024-01-09 15:28:29 +00:00
Harald Welte e61d459cef Support building with -Werror=strict-prototypes / -Werror=old-style-definition
Unfortunately "-std=c99" is not sufficient to make gcc ignore code that
uses constructs of earlier C standards, which were abandoned in C99.

See https://lwn.net/ml/fedora-devel/Y1kvF35WozzGBpc8@redhat.com/ for
some related discussion.

Change-Id: I84fd99442d0cc400fa562fa33623c142649230e2
2022-11-03 12:44:28 +01:00
Pau Espin f5b8ed14a9 ctrl: Pre-calculate required size before allocating msgb
This commit fixes crash when response is more than ~4096 chars.
Furthermore, we now allocate only the required memory, not 4096 for all
messages, which usually don't require it.
Test needs to be adapted since it assumed there was more available space
at the end of the msgb.

Related: OS#5169
Change-Id: I0b8f370f7b08736207f9efed13a0663b5e482824
2021-06-15 16:29:44 +00:00
Alexander Couzens 4e284b6379 utils.h: require a semi colon after OSMO_ASSERT
When using `OSMO_ASSERT(exp);` clang will warn about
an empty expression because the semi colon was superflous.
Use do {} while (0) to enfore the need of a semi colon.
This might break other test.

Change-Id: I2272d29a81496164bebd1696a694383a28a86434
2019-07-08 13:23:45 +00:00
Pau Espin b885ef88c1 tests: ctrl: Test received ERROR messages are handled correctly
Change-Id: I3c8e95aaa1ca222d4cd1395e548f8461bf9d4cd6
2018-07-16 17:56:25 +00:00
Neels Hofmeyr a8b6cc4cd9 fix ctrl_test sanitizer issues
Add logging to root ctx, add msgb ctx to root ctx, free wqueue to simulate the
msgb being sent, and assert final talloc size.

Change-Id: Ief3d5e7b6c4d781b3854e230e45a67d5281b94cd
2018-04-05 18:23:45 +02:00
Neels Hofmeyr cdbc9afe5d ctrl: fix deferred commands (and hence fix osmo-bts-sysmo 'clock-info' cmd)
The CTRL interface has a ctrl_cmd_def_* API that allows deferring a CTRL
command reply until later. However, the command handling currently fails to
acknowledge this and deallocates the struct ctrl_cmd anyway.

Fix: in struct ctrl_cmd, add a defer pointer to be populated by
ctrl_cmd_def_make(). A cmd thus marked as deferred is not deallocated at the
end of command handling. This fix needs no change in calling code.

(Another idea was to return a different code than CTRL_CMD_HANDLED when the
command is to be deferred, but that would require adjusting each user of
ctrl_cmd_def_make(). The implicit marking is safer and easier.)

Show that handling deferred commands is fixed by adjusting the expectations of
ctrl_test.c's test_deferred_cmd() and removing the now obsolete exit_early
label.

One symptom of the breakage is that osmo-bts-sysmo crashes when asked to report
a trx's clock-info, which is aggravated by the fact that the sysmobts-mgr does
ask osmo-bts-sysmo for a clock-info.

The crash appears since Id583b413f8b8bd16e5cf92a8a9e8663903646381 -- it looked
like just fixing an obvious memory leak, which it did as shown by the unit
test, but deferred ctrl commands actually relied on that leak. Both fixed now.

Related: OS#3120
Change-Id: I24232be7dcf7be79f4def91ddc8b8f8005b56318
2018-04-05 03:11:49 +02:00
Neels Hofmeyr 6882b80d96 ctrl: test deferred cmd, show current failure
Handling a deferred command currently deallocates the struct ctrl_cmd upon
exiting the initial command handling, while it should actually stay around for
the asynchronous/deferred handling of the ctrl command.

Show the current bug by means of a ctrl test. The test will be adjusted to
expect the correct result when the bug is fixed in a subsequent commit
(I24232be7dcf7be79f4def91ddc8b8f8005b56318).

Change-Id: Ibbc847fc583bdd8e5e53a008258805e634ea12b4
2018-04-05 03:10:34 +02:00
Neels Hofmeyr 3da9aa6b67 ctrl: tighten CTRL input parsing
Validate that incoming CTRL commands...
- have decimal IDs,
- return error on trailing characters,
- have invalid characters in variable identifiers,
- send detailed error messages as reply to the requestor.

Adjust ctrl_test.{c,ok}, which best show the change in behavior.

Message handling causes log messages on stderr; previously, stderr was empty.
Add '[ignore]' in testsuite.at so that the nonempty stderr doesn't cause test
failures.

Change-Id: I96a9b6b6a3a5e0b80513aa9eaa727ae8c9c7d7a1
2017-12-20 15:50:24 +00:00
Neels Hofmeyr c0b0b62305 ctrl: on parse errors, return a detailed message to sender
The recently added ctrl_cmd_parse2() returns non-NULL cmd with error messages
upon parsing errors. In handle_control_read(), use ctrl_cmd_parse2() and send
those back to the CTRL command sender as reply.

Retain the previous "Command parser error" reply only in case ctrl_cmd_parse2()
should return NULL, which shouldn't actually happen at all.

Change-Id: Ie35a02555b76913bb12734a76fc40fde7ffb244d
2017-12-18 23:05:50 +00:00
Neels Hofmeyr 1b8b152e79 ctrl_test: add two more current parsing bugs to prep for fix
Change-Id: Id11bc326be2f0bc2746a928354e416495a18baf7
2017-12-18 23:05:50 +00:00
Neels Hofmeyr f2c10f1082 ctrl: fix mem leak when handling GET_REPLY and SET_REPLY
In ctrl_handle_msg() (code recently propagated from handle_control_read()),
talloc_free() the parsed ctrl_cmd in all code paths. In particular, a free was
missing in case ctrl_cmd_handle() returns CTRL_CMD_HANDLED.

CTRL_CMD_HANDLED is triggered by GET_REPLY / SET_REPLY parsing, as show by
ctrl_test.c. With the memleak fixed, adjust expected test output and make a
detected mem leak abort the test immediately.

Change-Id: Id583b413f8b8bd16e5cf92a8a9e8663903646381
2017-12-18 23:05:50 +00:00
Neels Hofmeyr 6769ad6e0a ctrl_test: show memleak when receiving GET_REPLY and SET_REPLY commands
The "memleak!" output shows messages that lack a talloc_free() of the parsed
ctrl command buffer. The leak shall be fixed in a subsequent patch.

Change-Id: I2c3e4d08b769b9cd77593362ea36a28d681cd042
2017-12-18 23:05:50 +00:00
Neels Hofmeyr 83aee83ec6 ctrl_test: expand to test message handling and detect mem leaks
Subsequent patches that tighten CTRL input validation will make the results
more interesting.

Change-Id: Idd4cc7d193db1a7d761f72ed33ed46eea450a78f
2017-12-18 23:05:50 +00:00
Neels Hofmeyr 0ab6eca80a ctrl_test.c: replace print_escaped() with new osmo_escape_str()
Change-Id: I12d3828dcc925f97fde11c360f1d60f3bd8cad8b
2017-12-18 23:05:49 +00:00
Neels Hofmeyr 505c965e36 CTRL: add unit tests for CTRL command parsing
This uncovers some interesting behavior of the CTRL interface which we may want
to guard against in subsequent patches: trailing whitespace, ignored tokens,
special characters as cmd->id.

Change-Id: If7af06d50ca71fd528b08cd70310774d5a53f0f7
2017-09-27 14:04:23 +00:00
Vadim Yanitskiy c2afe81d85 ctrl_test.c: fix build with GCC 7.1.1
According to GCC's online docs:

When an inline function is not static, then the compiler must
assume that there may be calls from other source files; since
a global symbol can be defined only once in any program, the
function must not be defined in the other source files, so the
calls therein cannot be integrated. Therefore, a non-static
inline function is always compiled on its own in the usual fashion.

There is no any (performance or size) benefit from 'inline' keyword
in this particular file, so let's replace one by 'static'.

Change-Id: I11e1f1cfea09c6f0cf8225239e782b551d3eb52f
2017-06-13 20:22:19 +07:00
Neels Hofmeyr 7c1ec8c8e7 ctrl_type_vals: explicitly terminate
Don't use CTRL_TYPE_UNKNOWN as value_string[] terminator, use an explicit, more
obvious { 0, NULL } termination. Set an explicit string for CTRL_TYPE_UNKNOWN.
No other value_string[]s to date have such a "hidden" terminator.

BTW, a { 0, "string" } item is not a terminator, only { 0, NULL } is, so we can
set a string for CTRL_TYPE_UNKNOWN == 0.

Also, having a string value for CTRL_TYPE_UNKNOWN is not harmful because all
code paths explicitly check for the CTRL_TYPE_*s that are valid.

Adjust the test expectation.

From the ctrl_type_vals enum, remove the = 0, because it is implicitly 0
anyway.

One motivation to press this fixup: I am trying to add a script that checks
whether all value_string[]s are terminated to our jenkins jobs, and to find
that this one is terminated, it would need to interpret the CTRL_TYPE_UNKNOWN
constant, which would make things far more complex. At this point, all of the
value_string[]s have an explicit termination, and I would like to enforce this
from now on -- for readable code and to not spend more time on the validator.

The patch adding ctrl_type_vals (Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28) was
accepted by another reviewer before I could reconfirm my -1, so this is a fixup
to enable the termination checking script patches.

Related: I2bc93ab4781487e7685cfb63091a489cd126b1a8 (adds script to libosmocore)
         I7fe3678b524d602fc6aa14bc0ed06308df809a3e (uses in jenkins.sh)
	 Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28 (adds ctrl_type_vals)

Change-Id: Ia99f37464c7b36b587da2cc78f52c82725f02cbc
2017-03-15 13:47:20 +00:00
Max 70c7d4160d Use value_string for ctrl_type
Use value_string for enum ctrl_type instead of custom code. Add
corresponding unit tests.

Related: OS#1615
Change-Id: Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28
2017-03-01 16:37:59 +00:00