-
Notifications
You must be signed in to change notification settings - Fork 255
Simplify error handling (mainly, error messages) #1314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
alejandro-colomar
wants to merge
20
commits into
shadow-maint:master
Choose a base branch
from
alejandro-colomar:serr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+1,894
−2,597
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1144e9d to
18af936
Compare
18af936 to
7474300
Compare
7474300 to
dc7f8c0
Compare
b09744d to
28170d7
Compare
50e3b52 to
f882a34
Compare
3ef7608 to
9e194eb
Compare
0699803 to
89e540d
Compare
89e540d to
c00f42a
Compare
The double parentheses were used to fake a variadic macro with a non-variadic one. With a variadic macro, we remove the weird double parentheses that were needed to call this macro, which BTW were error-prone. This would have prevented the bug fixed in 3f5ae5d (2025-09-10; "src/su.c: Fix incorrect (non-matching) parentheses"). Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
The name of this macro makes it more evident what it does. It's a C-locale version of syslog(3). We need to implement it as a macro so that arguments such as strerror(3) are evaluated after setting the C locale. This would be impossible with a function. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
There's no need for two variables, and this avoids one assignment. Signed-off-by: Alejandro Colomar <alx@kernel.org>
…nally Both setlocale(3) and free(3) are okay to call with a null pointer. Signed-off-by: Alejandro Colomar <alx@kernel.org>
In some cases, we print strerrno() with this macro. Because this is a macro, and internal calls such as strdup(3) may set errno, that value could be corrupted when we arrive at syslog(3). While we could solve this here, it's not robust. Instead, we'll use a dedicated wrapper for that, which will be added in the following commits: SYSLOGE(). What we'll do here is preserve errno when we exit from this macro, as we often follow SYSLOG() calls with fprintf(stderr,) calls, which also use the errno value, and we don't want to pollute that. Signed-off-by: Alejandro Colomar <alx@kernel.org>
c00f42a to
bd70823
Compare
Signed-off-by: Alejandro Colomar <alx@kernel.org>
These functions print a formatted string, followed by a colon and a space, followed by an error string produced by strerror($2). That is, the output is as follows: fmt: error message string For example, fprintec(stderr, ENOMEM, "foo(%d)", 42); prints foo(42): Cannot allocate memory These functions return the number of characters printed, or a negative value on error, like fprintf(3). Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
fprinte() is like fprintec(), but uses errno instead of an error code. It is implemented as a macro so that it can read the value in errno before evaluating any of its arguments, thus not corrupting it. It also preserves errno so that the error can be printed more than once. This is useful because we often print to stderr or log_get_logfd(), and immediately after print to the system log with syslog(3). Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
like the fprintf(3) wrappers, these print an error message. SYSLOGE() uses errno, and SYSLOGEC() uses an errno-like error code. This time we need to be careful to name the local copy of errno differently than within SYSLOG() --which we call--. Let's use a double underscore. In the future, C might have function literals (similar to lambdas), which will solve this issue. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Having such long and complex format strings and variadic arguments is error-prone, as can be seen in the previous commit, which fixes a bug of this kind. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This will allow having shorter lines for writing to stderr. This name is commonly used in other projects, it seems (see link below). Link: <https://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/Variadic-Macros.html> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Print simpler messages that don't need translation. Check libc errors with ==-1 and ==NULL instead of <0 (or !=0) and !p. Signed-off-by: Alejandro Colomar <alx@kernel.org>
bd70823 to
7f1e64c
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Queued after #1289 .