NetworkManager/contrib/scripts
Thomas Haller ad7d5887cd
all: cleanup close() handling and clarify nm_close()/nm_close_with_error()
Cleanup the handling of close().

First of all, closing an invalid (non-negative) file descriptor (EBADF) is
always a serious bug. We want to catch that. Hence, we should use nm_close()
(or nm_close_with_error()) which asserts against such bugs. Don't ever use
close() directly, to get that additional assertion.

Also, our nm_close() handles EINTR internally and correctly. Recent
POSIX defines that on EINTR the close should be retried. On Linux,
that is never correct. After close() returns, the file descriptor is
always closed (or invalid). nm_close() gets this right, and pretends
that EINTR is a success (without retrying).

The majority of our file descriptors are sockets, etc. That means,
often an error from close isn't something that we want to handle. Adjust
nm_close() to return no error and preserve the caller's errno. That is
the appropriate reaction to error (ignoring it) in most of our cases.

And error from close may mean that there was an IO error (except EINTR
and EBADF). In a few cases, we may want to handle that. For those
cases we have nm_close_with_error().

TL;DR: use almost always nm_close(). Unless you want to handle the error
code, then use nm_close_with_error(). Never use close() directly.

There is much reading on the internet about handling errors of close and
in particular EINTR. See the following links:

https://lwn.net/Articles/576478/
https://askcodes.net/coding/what-to-do-if-a-posix-close-call-fails-
https://www.austingroupbugs.net/view.php?id=529
https://sourceware.org/bugzilla/show_bug.cgi?id=14627
https://news.ycombinator.com/item?id=3363819
https://peps.python.org/pep-0475/
2022-10-25 13:12:48 +02:00
..
nm-in-container.d contrib: setup "nm-in-container.sh" on start via rc.local script 2022-09-09 17:46:00 +02:00
btmodem.pl all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
checkpatch-feature-branch.sh contrib/scripts: use "main" branch name in "checkpatch-feature-branch.sh" 2021-04-01 22:28:59 +02:00
checkpatch-git-post-commit-hook contrib/scripts: add "checkpatch-git-post-commit-hook" script to contrib/ 2020-02-21 07:40:10 +01:00
checkpatch.pl all: cleanup close() handling and clarify nm_close()/nm_close_with_error() 2022-10-25 13:12:48 +02:00
code-style-git-post-commit-hook contrib: explicitly pass "-n" to "nm-code-format.sh" in "code-style-git-post-commit-hook" 2021-09-16 08:47:38 +02:00
find-backports contrib: fail "find-backports" script if we have no "refs/notes/bugs" notes 2022-04-06 13:23:37 +02:00
git-subtree-reimport.sh contrib: show diff of git subtrees in "git-subtree-reimport.sh" script 2022-07-25 10:27:33 +02:00
modemu.pl contrib/modemu: extend PDP support 2022-02-04 15:54:15 +01:00
nm-ci-patch-gtkdoc.sh gitlab-ci: patch gtk-doc to generate valid documentation 2018-12-01 08:55:44 +01:00
nm-ci-run.sh tests/client: run "test-client.py" also for meson 2021-03-15 17:10:56 +01:00
nm-code-format-container.sh all: reformat with clang-format (clang-tools-extra-14.0.0-1.fc36) and update gitlab-ci to f36 2022-07-06 11:06:53 +02:00
nm-code-format.sh contrib: handle non-existing files with nm-code-format.sh -u 2022-09-23 15:32:28 +02:00
nm-copr-build-nm-git-bundle.sh contrib/scripts: better explain the purpose of nm-git-bundle 2022-01-06 10:01:51 +01:00
nm-copr-build.sh contrib/scripts: update "nm-copr-build.sh" script to use new nm-git-bundle 2022-01-06 10:03:57 +01:00
nm-import-openconnect all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
nm-import-openvpn all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
nm-import-vpnc all: update deprecated SPDX license identifiers 2021-01-05 09:46:21 +01:00
nm-in-container.sh contrib: add entries to bash_history for nm-in-container.sh script 2022-09-28 18:35:48 +02:00
NM-log contrib: use less -f in NM-log to avoid prompt for non-text input 2022-06-10 08:24:58 +02:00
nm-python-black-format.sh contrib: fix "nm-python-black-format.sh" script to ignore systemd,c-util,nettools files 2022-07-06 10:44:18 +02:00
nm-setup-git.sh contrib: set git-blame options in "nm-setup-git.sh" 2022-06-08 21:27:57 +02:00
test-create-many-device-setup.sh contrib: extend "test-create-many-device-setup.sh" script 2021-06-22 09:47:44 +02:00
test-macsec tests: use "/run" instead of "/var/run" 2019-05-17 21:24:18 +02:00
test-ppp.sh contrib: add "contrib/scripts/test-ppp.sh" test script 2021-10-04 15:40:15 +02:00
test-prefix-delegation.sh contrib: add script to test IPv6 prefix delegation 2021-07-13 09:43:04 +02:00