diff options
author | Kelvin M. Klann <kmk3.code@protonmail.com> | 2023-06-16 15:42:20 -0300 |
---|---|---|
committer | Kelvin M. Klann <kmk3.code@protonmail.com> | 2023-06-28 04:00:13 -0300 |
commit | b963fe41ae2cd669e5819aded531375ddaebc8b2 (patch) | |
tree | a82794efe2b8b925d24a3fd413663cef1e987926 /src/include | |
parent | common.h: use __func__ instead of __FUNCTION__ (diff) | |
download | firejail-b963fe41a.tar.gz firejail-b963fe41a.tar.zst firejail-b963fe41a.zip |
Improve errExit error messages
Changes:
* Move msg to the end of errExit (right before perror(3p))
* Include the full file path (within the repository)
* Add "()" to function name for clarity
Before:
Error malloc: main.c:123 main: Cannot allocate memory
After:
Error src/firejail/main.c:123 main(): malloc: Cannot allocate memory
Note: This clarifies which is the exact file that the error message
comes from, as there are many source files with the same name. For
example:
$ git ls-files 'src/*/main.c' | wc -l
20
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/common.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/include/common.h b/src/include/common.h index 23b00b6f8..4a2b8c1bf 100644 --- a/src/include/common.h +++ b/src/include/common.h | |||
@@ -41,7 +41,8 @@ | |||
41 | 41 | ||
42 | #define errExit(msg) do { \ | 42 | #define errExit(msg) do { \ |
43 | char msgout[500]; \ | 43 | char msgout[500]; \ |
44 | snprintf(msgout, 500, "Error %s: %s:%d %s", msg, __FILE__, __LINE__, __func__); \ | 44 | snprintf(msgout, 500, "Error %s/%s:%d %s(): %s", \ |
45 | MOD_DIR, __FILE__, __LINE__, __func__, msg); \ | ||
45 | perror(msgout); \ | 46 | perror(msgout); \ |
46 | exit(1); \ | 47 | exit(1); \ |
47 | } while (0) | 48 | } while (0) |