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>
This enables us to use log levels for `LOG_ERRNO`. The default is the
"warning" level so that we do not need to adjust all calls. The levels
for connection establishment and receiving from sockets are adjusted to
"info" such that common cases like unreachable peers do not
unnecessarily clutter the logs.
Fixes: #172
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>
For two settings previously defined in `hal_config.h` it makes sense to
make them changeable via `config.mk`. The AAP setting is moved to the
appropriate header and the Linux-specific APU define gets a guard so it
can be changed at compile time.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This moves all definitions from config.h to individual header files and
makes them configurable (i.e., does not define when already defined).
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This removes the `DEBUG` log statements when compiling with `type=release`
for better performance.
Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
This adds log level to `ud3tn_cmdline_options` struct so that command line parser passes the value to `init.c` and has no side effects. Also adjusts log message format
for printing out current log level.
Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
This adds generic log function `LOGF_GENERIC` which accepts logging level as argument. Also adds different log messages for different logging levels.
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>
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>
`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>
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 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>
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>
The "Router Optimizer" was a task that re-ordered bundles according to
the stated priority. As this was only supported for BPv6 and can be
easily exploited by a sender by always stating the highest priority for
their bundles, it is considered unnecessary for future versions of
uD3TN.
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>
The re-name to "enum ud3tn_result" broke the indentation in some
function signatures, which is fixed by this commit.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This is the initial commit for uD3TN. uD3TN is a fork of uPCN v0.8.0,
which will be developed and maintained in a public Git repository.
For questions concerning the history of and code provided with uPCN,
please get in touch with us via: contact <at> d3tn <dot> com
Signed-off-by: Felix Walter <felix.walter@d3tn.com>