Simplify error handling (mainly, error messages)#1314
Draft
alejandro-colomar wants to merge 14 commits intoshadow-maint:masterfrom
Draft
Simplify error handling (mainly, error messages)#1314alejandro-colomar wants to merge 14 commits intoshadow-maint:masterfrom
alejandro-colomar wants to merge 14 commits intoshadow-maint:masterfrom
Conversation
1144e9d to
18af936
Compare
18af936 to
7474300
Compare
7474300 to
dc7f8c0
Compare
b09744d to
28170d7
Compare
50e3b52 to
f882a34
Compare
3ef7608 to
9e194eb
Compare
b685d4b to
441ae73
Compare
68544f3 to
796017b
Compare
e6b8952 to
590bc27
Compare
f8155a9 to
0fc969b
Compare
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>
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>
b741935 to
5d0f3ef
Compare
While we don't use it directly in tests/, exit_if_null_() uses it, so we need to link to it in its test. 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>
We don't use this anymore. It was helpful temporarily, but now we use higher-level APIs. 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>
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>
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
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 .