[PATCH] Handle missing error.h (as seen in musl)

Haelwenn (lanodan) Monnier contact@hacktivis.me
Sun Dec 1 10:25:46 GMT 2024


[2024-11-30 01:32:01+0100] Mark Wielaard:
>On Fri, Nov 22, 2024 at 08:07:47PM +0100, Haelwenn (lanodan) Monnier wrote:
>> From: brahmajit das <brahmajit.xyz@gmail.com>
>>
>> musl doesn't provide error.h as a result debugedit is failing to build
>> on musl. So we're creating a error define that redefines the err
>> function and takes precedence over it. Thanks to gentoo developer
>> Anthony G. Basile <blueness@gentoo.org> for the patch idea.
>>
>> Signed-off-by: brahmajit das <brahmajit.xyz@gmail.com>
>> Ref: https://github.com/gentoo/gentoo/pull/26223
>> Signed-off-by: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
>> ---
>>
>> Note: I'm not subscribed to the list so please CC me on replies
>> [...]
>> +#ifdef HAVE_ERROR_H
>>  #include <error.h>
>> +#else
>> +#include <err.h>
>> +#define error(status, errno, ...) err(status, __VA_ARGS__)
>> +#endif
>
>I am not sure this really works as error does.  There seem to be some
>differences that might matter in how error is used in some of the
>debugedit programs.
>
>- error exits only when status is not zero, but err always does.
>  e.g. error (0, 0, "Stabs debuginfo not supported: %s", file);
>  prints just a warning, but
>  err (0, "Stabs debuginfo not supported: %s", file);
>  exits the program with exit code zero.
>
>- err always uses errno to print what happened, but error uses its
>  second argument (which the macro throws away). Some times the second
>  argument to error is errno, but not always. e.g.
>  error (0, ENOMEM, "Could not open DSO");
>  or it is zero, which means don't use, as in:
>  error (1, 0, "--build-id-seed (-s) needs --build-id (-i)");
>  which prints
>  ./debugedit: --build-id-seed (-s) needs --build-id (-i)
>  while with err it will always use whatever value errno has,
>  even if errno is zero it will print the confusing:
>  debugedit: --build-id-seed (-s) needs --build-id (-i): Success
>
>I think it might be better if you must compile against musl that you
>just link against a real error implementation like error-standalone?
>
>Cheers,
>
>Mark

Right, thanks for the detailed feedback.

By the way, Alpine has musl-legacy-error[1] but found it a bit lacking
compared to the manpage (like lack of error_print_progname handling),
so I ended up creating https://hacktivis.me/git/error-standalone/
to fullfill it better.

[1]: https://git.alpinelinux.org/aports/tree/main/musl-legacy-error/error.h

Best Regards


More information about the Debugedit mailing list