summaryrefslogtreecommitdiff
path: root/src/nm-dispatcher
Commit message (Collapse)AuthorAgeFilesLines
* doc: replace all (allow-none) annotations by (optional) and/or (nullable)Corentin Noël2023-03-271-1/+1
| | | | | | | | The (allow-none) annotation is deprecated since a long time now, it is better to use (nullable) and/or (optional) which clarifies what it means with the (out) annotation. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1551
* clang-format: reformat code with clang-format 15.0.4-1.fc37Thomas Haller2022-11-231-15/+15
| | | | | | | | | | | | | | This is the version shipped in Fedora 37. As Fedora 37 is now out, the core developers switch to it. Our gitlab-ci will also use that as base image for the check-{patch.tree} tests and to generate the pages. There is a need that everybody agrees on which clang-format version to use, and that version should be the one of the currently used Fedora release. Also update the used Fedora image in "contrib/scripts/nm-code-format-container.sh" script. The gitlab-ci still needs update in the following commit. The change in isolation will break the "check-tree" test.
* dispatcher: make global data in "nm-dispatcher.c" staticThomas Haller2022-10-251-1/+1
| | | | | | | | It's not needed outside the source file, and lgtm.com complains that global variables should have a long name. Poor global variable name 'gl'. Prefer longer, descriptive names for globals (eg. kMyGlobalConstant, not foo).
* all: reformat with clang-format (clang-tools-extra-14.0.0-1.fc36) and update ↵Thomas Haller2022-07-061-17/+17
| | | | gitlab-ci to f36
* all: suppress wrong gcc-12 warning "-Wdangling-pointer"Thomas Haller2022-02-211-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | gcc-12.0.1-0.8.fc36 is annoying with false positives. It's related to g_error() and its `for(;;) ;`. For example: ../src/libnm-glib-aux/nm-shared-utils.c: In function 'nm_utils_parse_inaddr_bin_full': ../src/libnm-glib-aux/nm-shared-utils.c:1145:26: error: dangling pointer to 'error' may be used [-Werror=dangling-pointer=] 1145 | error->message); | ^~ /usr/include/glib-2.0/glib/gmessages.h:343:32: note: in definition of macro 'g_error' 343 | __VA_ARGS__); \ | ^~~~~~~~~~~ ../src/libnm-glib-aux/nm-shared-utils.c:1133:31: note: 'error' declared here 1133 | gs_free_error GError *error = NULL; | ^~~~~ /usr/include/glib-2.0/glib/gmessages.h:341:25: error: dangling pointer to 'addrbin' may be used [-Werror=dangling-pointer=] 341 | g_log (G_LOG_DOMAIN, \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 342 | G_LOG_LEVEL_ERROR, \ | ~~~~~~~~~~~~~~~~~~~~~~~ 343 | __VA_ARGS__); \ | ~~~~~~~~~~~~ ../src/libnm-glib-aux/nm-shared-utils.c:1141:13: note: in expansion of macro 'g_error' 1141 | g_error("unexpected assertion failure: could parse \"%s\" as %s, but not accepted by " | ^~~~~~~ ../src/libnm-glib-aux/nm-shared-utils.c:1112:14: note: 'addrbin' declared here 1112 | NMIPAddr addrbin; | ^~~~~~~ I think the warning could potentially be useful and prevent real bugs. So don't disable it altogether, but go through the effort to suppress it at the places where it currently happens. Note that NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER macro only expands to suppressing the warning with __GNUC__ equal to 12. The purpose is to only suppress the warning where we know we want to. Hopefully other gcc versions don't have this problem. I guess, we could also write a NM_COMPILER_WARNING() check in "m4/compiler_options.m4", to disable the warning if we detect it. But that seems too cumbersome.
* format: reformat source tree with clang-format 13.0Thomas Haller2021-11-294-163/+163
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We use clang-format for automatic formatting of our source files. Since clang-format is actively maintained software, the actual formatting depends on the used version of clang-format. That is unfortunate and painful, but really unavoidable unless clang-format would be strictly bug-compatible. So the version that we must use is from the current Fedora release, which is also tested by our gitlab-ci. Previously, we were using Fedora 34 with clang-tools-extra-12.0.1-1.fc34.x86_64. As Fedora 35 comes along, we need to update our formatting as Fedora 35 comes with version "13.0.0~rc1-1.fc35". An alternative would be to freeze on version 12, but that has different problems (like, it's cumbersome to rebuild clang 12 on Fedora 35 and it would be cumbersome for our developers which are on Fedora 35 to use a clang that they cannot easily install). The (differently painful) solution is to reformat from time to time, as we switch to a new Fedora (and thus clang) version. Usually we would expect that such a reformatting brings minor changes. But this time, the changes are huge. That is mentioned in the release notes [1] as Makes PointerAligment: Right working with AlignConsecutiveDeclarations. (Fixes https://llvm.org/PR27353) [1] https://releases.llvm.org/13.0.0/tools/clang/docs/ReleaseNotes.html#clang-format
* glib-aux: rename nm_g_timeout_add_source_seconds() to ↵Thomas Haller2021-10-081-1/+1
| | | | | | | | | | | | nm_g_timeout_add_seconds_source() There is g_idle_add(), g_timeout_add() and g_timeout_add_seconds(). We have alternatives nm_g_idle_add_source() and nm_g_timeout_add_source(). I find the previous name nm_g_timeout_add_source_seconds() inconsistent with the pattern, and get it always wrong on first try. Rename.
* all: add some README.md files describing the purpose of our sourcesThomas Haller2021-08-191-0/+15
|
* nm-sudo,dispatcher: rename and refactor code to make them more similarThomas Haller2021-08-061-54/+66
| | | | | | | | | | nm-sudo and nm-dispatcher are very similar from a high level. Both are D-Bus activated services that exit on idle and all they do, is to provide a simple D-Bus API with no objects or properties. Hence it's not surprising that they follow the same structure. Rename the code to make them look more similar.
* dispatcher: reject new requests after releasing nameThomas Haller2021-08-061-37/+63
| | | | | | | | | | | | | | | After we released the well-known name (or if we failed to ever request it), we must exit as fast as possible, so that a new instance can be started to serve new requests. At that point, reject new requests because they are targeted against the unique name, which they should not do (when talking to a D-Bus activated service that exits on idle, it's important to talk to the well-known name). Also, if we receive SIGTERM, start releasing the name. We are told to shut down, and must do so in a timely manner. Again, new requests shall not be served by this instance.
* dispatcher: add D-Bus method "Ping"Thomas Haller2021-08-041-0/+33
| | | | | This is only for testing the service. As nm-dispatcher is D-Bus activated, have a simple method to test whether it works.
* dispatcher: support enabling debug logging via environment variableThomas Haller2021-08-041-10/+43
| | | | | | | | | | | | | The advantage of environment variables is that the user can use `systemctl edit NetworkManager-dispatcher.service` for setting them, without need to change the ExecStart= line. Also, enabling debugging from the start is useful, despite that debug logging can be enabled per-request. Also, there is a difference whether we want verbose logging or whether we want to log to stdout. There should be a flag, that only increases the logging verbosity, but does not change the logging backend.
* dispatcher: fix race for exit-on-idleThomas Haller2021-08-041-83/+155
| | | | | | | | | | | | | | - exit-on-idle needs to be done correctly. Fix the race, by first notifying systemd (STOPPING=1), releasing the name, and all the while continue processing requests. - don't use g_bus_own_name_on_connection(). That one also listens to NameLost and NameAcquired signals, but we don't care about those. systemd will take care to only spawn one process at a time. And anyway, the well-known name is only important to be reachable, we don't require it to be functional. We can get the first request before RequestName completed and we can continue getting requests after releasing the name.
* dispatcher: minor various cleanup of timeout and shutdownThomas Haller2021-08-041-11/+18
| | | | | | | - use nm_g_timeout_add_source() for millisecond precision of idle timeout. - schedule the first idle timeout before registering the D-Bus object. - let the signal handler do nothing, if we are already quitting. In practice, this only silences the extra logging.
* dispatcher: use nm_g_bus_get_blocking() to create GDBusConnectionThomas Haller2021-08-041-4/+12
| | | | | | | The difference is that nm_g_bus_get_blocking() iterates the GMainContext of the caller, and thus it can process and handle SIGTERM signals. Calling g_bus_get_sync() does not iterate the context, and we cannot handle or detect early cancellation.
* dispatcher: add cancellable for tracking SIGTERMThomas Haller2021-08-041-0/+6
|
* dispatcher: ignore SIGPIPEThomas Haller2021-08-041-0/+1
|
* dispatcher: setup signal handler as firstThomas Haller2021-08-041-5/+6
| | | | | The very first and the very last thing we want to do is register (unregister) the signal handler.
* dispatcher: use GSource instead of source idsThomas Haller2021-08-041-22/+23
|
* dispatcher: replace GMainLoop by explicit context iterationThomas Haller2021-08-041-10/+12
| | | | | | | Explicitly iterating the context is more flexible, as we can control the parameters how long we iterate. GMainLoop is essentially a (thread-safe) iteration around one boolean flag (controlled by g_main_loop_run() and g_main_loop_quit()). We can maintain that boolean flag ourselves.
* dispatcher: add comment about exit-on-idle raceThomas Haller2021-08-041-0/+3
|
* all: rename nm_utils_strsplit_set*() to nm_strsplit_set*()Thomas Haller2021-08-021-4/+4
|
* build: fix linking libnm-log-null into different test programsThomas Haller2021-07-052-0/+2
| | | | | We require these, otherwise we can get a linker error about _nm_utils_monotonic_timestamp_initialized symbol being undefined.
* all: don't explicitly include <glib-unix.h>Thomas Haller2021-06-281-1/+0
| | | | We get it now always by "nm-macros-internal.h".
* core,nm-dispatcher: use nm_utils_get_process_exit_status_desc()Beniamino Galvani2021-06-111-18/+6
| | | | (cherry picked from commit 326dde6d53a2352d51585a07255e7d25bd0a6c08)
* dispatcher: set G_LOG_DOMAIN to "nm-dispatcher"Thomas Haller2021-03-181-0/+2
| | | | | | | | | | | | | | | | | Originally, we would define G_LOG_DOMAIN via CFLAGS arguments. Since commit 341b6e0704da ('all: change G_LOG_DOMAIN to "nm"') we would instead set it in source and uniformly define it as "nm". The reasons are that most parts of our source should not use g_log() directly, and there is an aim to avoid special CFLAGS to simplify the build setup. However, dispatcher indeed uses g_log() for logging, so the value there is important. Fix that, but this time by setting the define in source not via CFLAGS. Fixes: 341b6e0704da ('all: change G_LOG_DOMAIN to "nm"')
* build/meson: fix test name for "test-dispatcher-envp"Thomas Haller2021-03-151-1/+1
|
* build: move "dispatcher/" to "src/nm-dispatcher/"th/build-meson-cleanupThomas Haller2021-02-2816-0/+2786