This improves const correctness, at least for pointers (making the
pointed-to data const where possible).
Some suppressions are added for false positive warnings, such as in
`simple_queue.c` where an arithmethic operation is used on the pointer
to calculate a non-const pointer that is returned (thus, the passed
pointer should also not point to const).
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
In order to properly clean up all resources allocated by threads, we
need to join the non-detached threads. This is not possible within the
`sigaction` exit handler function. For this reason, the termination
logic is changed to use `sigwait`.
In addition, SIGALRM is added to the list of handled signals and
SIGUSR1, SIGUSR2 are ignored.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
Adds a parameter to the `hal_task_create()` function to allow
non-detached threads and a second parameter to pass the thread
identifier.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
They are unnecessary now. We should do platform-specific definitions
centrally via config.mk as well.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We only used it for thread naming - the hal_platform malloc analysis
support was removed a long time ago. As we do not really need thread
naming and removed it when cleaning up hal_task, we do not need this
define anymore.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This removes the parameters for task name, priority, and stack size,
which were mostly relevant for FreeRTOS on STM32.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We implemented this to mirror the behavior on STM32 with FreeRTOS. We do
not need it anymore on POSIX systems, so better go with the defaults of
the OS.
Closes: #162
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This simplifies the logging of system error messages by passing
everything to a single `fprintf` call. The error message is obtained
from `strerror` - as we guard everything via a semaphore this should not
lead to any issue(s) we had in the past with it.
Fixes: #171
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This checks for `POLLNVAL` errors for which we would otherwise return
`0` (as if the timeout was triggered). It also makes the formatting of
checks consistent.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Previously we were using ASSERT(0|false), which only works in debug
builds. In some cases, this is intended, but we cannot reliably continue
operation in others. We now use abort() where we have to terminate the
program abnormally. In cases where only debug builds should terminate, a
comment is added.
This is done along with the logging updates as the code is typically
related and would cause conflicts otherwise.
Closes: #163
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Rules that have been applied:
- ERROR: Anything that is or may be problematic for the program to
continue running.
- WARN: Anything abnormal but definitely not critical for program
continuation, especially issues encountered when interacting with
clients (e.g. AAP).
- INFO: All state changes not corresponding to the "normal" processing of
individual data or messages/bundles, as well as further informative and
helpful messages. Includea errors that occur during normal data
processing.
- DEBUG: Messages to trace what happens with individual bundles and
other fine-grained information about internal processes.
At the moment, `LOG_ERRNO` always emits messages with the "ERROR" level.
We might want to change this in the future to better differentiate WARN
and ERROR in this regard also.
Closes: #140
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This resolves the race condition documented in #139.
The log macros now each call only a single function which locks
a binary semaphore during execution.
Fixes: #139
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This fixes the implementation of `hal_task_delay` function by replacing `usleep` which has been removed from POSIX with `nanosleep`. Also handles `EINTR` error.
Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
Previously the maximum waiting time was just over 24 days. In a DTN
setup we may want to wait longer, e.g., for contacts to occur. This
allows for waiting about 292 years. If the provided delay exceeds this
threshold, an infinite delay is assumed.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The nanoseconds field in struct timespec must not exceed 1000 million,
i.e., one second. As we add to an absolute time we might exceed this in
some cases. Thus, we need to check for it and reflect the additional
second in the seconds field of struct timespec.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We cannot easily support this on MacOS, but we do not use it except in
tests. Thus, remove it and make the tests only run on Linux and use
`sem_getvalue` directly.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Unnamed semaphores are unsupported there, which is why we were seeing
segfaults.
See also: https://stackoverflow.com/a/27847103
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This removes all external functions currently unused in uD3TN.
We may re-introduce esp. JSON at a later point in time, but should
include updated libraries anyway.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
`hal_task_create` returned a reference to the new task allocated on the
heap via `malloc`. We commonly used the pattern to `free` this reference
from the new thread which, however, could result in race conditions and
other synchronization issues. We added a fix using a semaphore in the
application agent, but this would have been needed in other places (CLA,
...) as well. As we do not make use of the task reference anywhere
besides in the CLA for error handling, we can remove the heap-allocated
value altogether and replace it with an `enum ud3tn_result` to simplify
things and circumvent the named synchronization issues.
In the case of the CLA function `cla_link_init`, logic is introduced to
request the RX task to exit immediately in case the TX task cannot be
launched.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The delete function should just deallocate the heap memory, termination
of the thread should be controlled by itself, to make it safe to call
`hal_task_delete()` from within the thread.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
`strerror()` is not thread-safe, thus, we have to use an alternative. If
we want to prevent allocating a temporary buffer (e.g., for
`strerror_r`), we need to use `perror()`. To allow writing stored
`errno` values, the function sets `errno` from an argument passed to it,
which should be safe according to the manual.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
As on the targeted platforms the scheduler is always running when the
program is launched, the function should simply pause indefinitely. It
did not do this, though, as a signal can interrupt `pause()`.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This removes some functions solely useful for the STM32, debugging and
error handling with these boards. When doing a future uC port, we should
move such functions to the platform-specific part.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The static variables might be accessed at the same time. The name is not
really needed if we have a debugger available, which we probably always
do...
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This can lead to hard-to-debug errors as it would just increment the
semaphore further and then a double "locking" is needed to actually lock it.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The previous polling method was not clean in that it left the semaphore
locked and did not return whether the operation was successful or not.
This adds a more descriptive and correct method to chieve the goal of
checking the semaphore's status.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This switches all log messages to `stderr`, which is intended for
diagnostic purposes (i.e., matches the intent of our log messages). This
makes it easy to distinguish the log output from actual output (which
the uD3TN daemon does not have, but a program based on libud3tn might).
This also flushes stderr after every log message (i.e., makes it
line-buffered) to prevent delays when outputting the logs.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
LOG() is not safe to be called inside signal handlers as it requires
malloc() and free() to work.
Detected by Clang's thread sanitizer.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Do not return a reference to a non-thread-safe global variable:
ctime() is not thread safe. As we only use the function in logging, we
can directly print the return value, protected by a mutex.
This also adapts the tests and makes the initialization routine always
run. To use the system time again, UINT64_MAX can be passed.
Found by Clang's thread (data race) sanitizer.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Former releases of uD3TN have included support for STM32/FreeRTOS.
Having this support from the first moment on was a good thing in
order to optimize for platforms with limited resources. As this
platform is not used in current uD3TN setups and as it results in quite
some maintenance work, it is removed with this commit. The removed parts
cover the implementation itself, tests, tools, documentation, parts of
the build/make scripts as well as licensing information.
Signed-off-by: Marius Feldmann <marius.feldmann@d3tn.com>
ud3tn is available under multiple licenses and we want to reflect this in
our source code. But which license information should appear first and how
can we manage this efficiently in the future? The Linux Kernel uses SPDX
expressions instead of boilerplate sections. This seems to be a great
approach, so we do the same here.
Signed-off-by: Georg Alexander Murzik <georg.murzik@d3tn.com>
As we are moving to `BSD-3-Clause OR Apache-2.0`, this needs to be
adapted as well. (We got the permission of Robert to publish his code
under the new licensing scheme.)
Signed-off-by: Felix Walter <felix.walter@d3tn.com>