Skip to content
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

modif: improve errExit error messages #5871

Merged
merged 4 commits into from
Jul 1, 2023
Merged

Conversation

kmk3
Copy link
Collaborator

@kmk3 kmk3 commented Jun 28, 2023

Main 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

Kind of relates to #3325.

kmk3 added 3 commits June 28, 2023 03:43
Use errExit in every place that uses __FILE__ and __LINE__ manually.

Note: This currently only happens in the duplicated `is_dir` function.
For increased portability.

The former is in C99, the latter is from gcc.
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
@kmk3 kmk3 merged commit 33c75b8 into netblue30:master Jul 1, 2023
9 checks passed
@kmk3 kmk3 deleted the improve-errexit branch July 1, 2023 17:35
kmk3 added a commit that referenced this pull request Jul 19, 2023
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 16, 2024
Make it more similar to the assert() message format for consistency.
Example:

Before:

    firejail: main.c:100: main: Assertion `1 == 2' failed.
    Error src/firecfg/main.c:100 main(): malloc: Cannot allocate memory

After:

    firejail: main.c:100: main: Assertion `1 == 2' failed.
    Error src/firecfg/main.c:100: main: malloc: Cannot allocate memory

This amends commit b963fe4 ("Improve errExit error messages",
2023-06-16) / PR netblue30#5871.
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 16, 2024
This makes the compile commands clearer when building in parallel (with
`make -j`) and ensures that `__FILE__` includes the full build-time path
(relative to the root of the repository) whenever it is referenced, such
as in failed assert() messages (currently the full path is only shown in
errExit() messages).  Example:

Before:

    firejail: main.c:100: main: Assertion `1 == 2' failed.
    Error src/firecfg/main.c:100: main: malloc: Cannot allocate memory

After:

    firejail: ../../src/firejail/main.c:100: main: Assertion `1 == 2' failed.
    Error ../../src/firecfg/main.c:100: main: malloc: Cannot allocate memory

Commands used to search and replace:

    $ git grep -Ilz '^MOD_DIR =' -- '*Makefile' | xargs -0 -I '{}' \
      sh -c "printf '%s\n' \"\$(sed -E \
        -e 's|^MOD_DIR = src/(.*)|MOD = \\1\\nMOD_DIR = \$(ROOT)/src/\$(MOD)|' \
        -e 's:^(PROG|SO) = [^.]+(\.so)?$:\\1 = \$(MOD_DIR)/\$(MOD)\2:' \
	'{}')\" >'{}'"
    $ git grep -Ilz '^HDRS :=' -- '*.mk' | xargs -0 -I '{}' \
      sh -c "printf '%s\n' \"\$(sed -E \
        -e 's|wildcard (\*\..)|wildcard \$(MOD_DIR)/\\1|' '{}')\" >'{}'"

Note: config.mk.in, src/fnettrace/Makefile and src/include/common.h were
edited manually.

This is a follow-up to netblue30#5871.
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 16, 2024
This makes the compile commands clearer when building in parallel (with
`make -j`) and ensures that `__FILE__` includes the full build-time path
(relative to the root of the repository) whenever it is referenced, such
as in failed assert() messages (currently the full path is only shown in
errExit() messages).  Example:

Before:

    firejail: main.c:100: main: Assertion `1 == 2' failed.
    Error src/firecfg/main.c:100: main: malloc: Cannot allocate memory

After:

    firejail: ../../src/firejail/main.c:100: main: Assertion `1 == 2' failed.
    Error ../../src/firecfg/main.c:100: main: malloc: Cannot allocate memory

Commands used to search and replace:

    $ git grep -Ilz '^MOD_DIR =' -- '*Makefile' | xargs -0 -I '{}' \
      sh -c "printf '%s\n' \"\$(sed -E \
        -e 's|^MOD_DIR = src/(.*)|MOD = \\1\\nMOD_DIR = \$(ROOT)/src/\$(MOD)|' \
        -e 's:^(PROG|SO) = [^.]+(\.so)?$:\\1 = \$(MOD_DIR)/\$(MOD)\2:' \
	'{}')\" >'{}'"
    $ git grep -Ilz '^HDRS :=' -- '*.mk' | xargs -0 -I '{}' \
      sh -c "printf '%s\n' \"\$(sed -E \
        -e 's|wildcard (\*\..)|wildcard \$(MOD_DIR)/\\1|' '{}')\" >'{}'"

Note: config.mk.in, src/fnettrace/Makefile and src/include/common.h were
edited manually.

This is a follow-up to netblue30#5871.
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 19, 2024
This makes the compile commands clearer when building in parallel (with
`make -j`) and ensures that `__FILE__` includes the full build-time path
(relative to the root of the repository) whenever it is referenced, such
as in failed assert() messages (currently the full path is only shown in
errExit() messages).  Example:

Before:

    firejail: main.c:100: main: Assertion `1 == 2' failed.
    Error src/firecfg/main.c:100: main: malloc: Cannot allocate memory

After:

    firejail: ../../src/firejail/main.c:100: main: Assertion `1 == 2' failed.
    Error ../../src/firecfg/main.c:100: main: malloc: Cannot allocate memory

Commands used to search and replace:

    $ git grep -Ilz '^MOD_DIR =' -- '*Makefile' | xargs -0 -I '{}' \
      sh -c "printf '%s\n' \"\$(sed -E \
        -e 's|^MOD_DIR = src/(.*)|MOD = \\1\\nMOD_DIR = \$(ROOT)/src/\$(MOD)|' \
        -e 's:^(PROG|SO) = [^.]+(\.so)?$:\\1 = \$(MOD_DIR)/\$(MOD)\2:' \
        '{}')\" >'{}'"
    $ git grep -Ilz '^HDRS :=' -- '*.mk' | xargs -0 -I '{}' \
      sh -c "printf '%s\n' \"\$(sed -E \
        -e 's|wildcard (\*\..)|wildcard \$(MOD_DIR)/\\1|' '{}')\" >'{}'"

Note: config.mk.in, src/fnettrace/Makefile and src/include/common.h were
edited manually.

This is a follow-up to netblue30#5871.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant