summaryrefslogtreecommitdiff
path: root/src/nmcli/utils.c
Commit message (Collapse)AuthorAgeFilesLines
* all: fix various "-Wcast-align=strict" warningsThomas Haller2022-12-091-1/+1
| | | | | | | The warning "-Wcast-align=strict" seems useful and will be enabled next. Fix places that currently cause the warning by using the new macro NM_CAST_ALIGN(). This macro also nm_assert()s that the alignment is correct.
* all: fix "-Wcast-align=strict" warnings for GArray castsThomas Haller2022-12-091-1/+1
| | | | | | | | | GArray.data is a char pointer. Most of the time we track other data in a GArray. Casting that pointer can trigger "-Wcast-align=strict" warnings. Avoid them. Most of the time, instead use the nm_g_array*() helpers, which also assert that the expected element size is correct.
* all: use nm_g_array_first()/nm_g_array_first_p() where suitableThomas Haller2022-12-091-2/+2
|
* cli: increase buffer in pager_fallback()Thomas Haller2022-10-241-1/+1
| | | | The stack is large enough. Let's use a larger buffer.
* cli: don't use unsafe functions in pager_fallback()Thomas Haller2022-10-241-6/+4
| | | | | | | | | The pager_fallback() runs in the forked child process. As such, it can only use functions from `man signal-safety` or that are explicitly allowed. We are mostly good, but g_printerr() is not allowed. It can deadlock. Just avoid it. It's not very to print those error messages anyway.
* cli: don't call setenv() after forkThomas Haller2022-10-241-13/+15
| | | | | | | | | | | | | | | | | | | | | | setenv() cannot be called after fork, because it might allocate memory, which can deadlock. Instead, prepare the environment and use execvpe(). `man 2 fork` says: After a fork() in a multithreaded program, the child can safely call only async-signal-safe functions (see signal-safety(7)) until such time as it calls execve(2). This means, we are quite strongly limited what can be done in the child process, before exec. setenv() is not listed as async-signal-safe, obviously because it allocates memory, and malloc() isn't async-signal-safe either. See also glib's documentation of GSpawnChildSetupFunc ([1]) about what can be done in the child process. [1] https://gitlab.gnome.org/GNOME/glib/-/blob/08cb200aec399b38f0cd825340a71fe6caadfb1b/glib/gspawn.h#L124
* all: use nm_g_array_{index,first,last,index_p}() instead of g_array_index()Thomas Haller2022-09-151-14/+16
| | | | | | | | | | | | | | | These variants provide additional nm_assert() checks, and are thus preferable. Note that we cannot just blindly replace &g_array_index() with &nm_g_array_index(), because the latter would not allow getting a pointer at index [arr->len]. That might be a valid (though uncommon) usecase. The correct replacement of &g_array_index() is thus nm_g_array_index_p(). I checked the code manually and replaced uses of nm_g_array_index_p() with &nm_g_array_index(), if that was a safe thing to do. The latter seems preferable, because it is familar to &g_array_index().
* clients: bulk removal of g_assert*() statementslr/assertsLubomir Rintel2022-03-281-3/+3
| | | | | Assertions should be done in tests. If we detect an unexpected situation at runtime, we shall fail more gracefully than crashing right away.
* format: reformat source tree with clang-format 13.0Thomas Haller2021-11-291-87/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* all: rename nm_utils_strsplit_set*() to nm_strsplit_set*()Thomas Haller2021-08-021-1/+1
|
* cli: move from "clients/cli/" to "src/nmcli/"Thomas Haller2021-03-151-0/+1821