1 |
Hey there folks. |
2 |
|
3 |
With the end of week 5 I'm once again here with my weekly report. As |
4 |
previous weeks this week too has been quite uneventful. I have been |
5 |
working on fixing miscellaneous bugs, constantly sharing my code with |
6 |
mentors and getting review to increase code quality. One such example |
7 |
would be of the debugedit patch [1], where I was replacing every |
8 |
instance of the error function with err for systems that does not have |
9 |
error.h header. I patch got big and was my mentor sam_ was second |
10 |
guessing to add it into ::gentoo. Upon review from developer blueness, |
11 |
who gave the advice to use a macro to redefine the err function with |
12 |
error function if error.h is not present. After a bit of research and |
13 |
help from blueness I came up with something like this: |
14 |
|
15 |
``` |
16 |
#ifdef HAVE_ERROR_H |
17 |
#include <error.h> |
18 |
#else |
19 |
#include <err.h> |
20 |
#define error(status, errno, ...) err(status, __VA_ARGS__) |
21 |
#endif |
22 |
``` |
23 |
|
24 |
Another one such example where I learned about a another macro trick was |
25 |
patching mysql-connector-c package [2]. This package not only helped me |
26 |
learn about the checking presence of functions and headers using various |
27 |
build tools (like GNU autotools, cmake, and meson), in this case it was |
28 |
cmake. I looked for the presence of three specific functions and set |
29 |
compile definitions respectively. Here is is the code snippet that does |
30 |
it: |
31 |
|
32 |
``` |
33 |
check_symbol_exists(res_ninit "resolv.h" HAVE_RES_NINIT_FUNCTION) |
34 |
check_symbol_exists(res_nsearch "resolv.h" HAVE_RES_NSEARCH_FUNCTION) |
35 |
check_symbol_exists(res_nclose "resolv.h" HAVE_RES_NCLOSE_FUNCTION) |
36 |
IF (HAVE_RES_NINIT_FUNCTION) |
37 |
add_compile_definitions(HAVE_RES_NINIT) |
38 |
ENDIF(HAVE_RES_NINIT_FUNCTION) |
39 |
IF (HAVE_RES_NSEARCH_FUNCTION) |
40 |
add_compile_definitions(HAVE_RES_NSEARCH) |
41 |
ENDIF(HAVE_RES_NSEARCH_FUNCTION) |
42 |
IF (HAVE_RES_NCLOSE_FUNCTION) |
43 |
add_compile_definitions(HAVE_RES_NCLOSE) |
44 |
ENDIF(HAVE_RES_NCLOSE_FUNCTION) |
45 |
``` |
46 |
|
47 |
With this the cmake build systems will check the resolv.h file for |
48 |
presence of res_ninit, res_nsearch, and res_nclose functions and set the |
49 |
compile definitions accordingly. We can then use this definitions to use |
50 |
the _res_n*_ fucntions which are thread safe or the non-thread-safe |
51 |
alternative ones. |
52 |
|
53 |
Last but not the least, the libratbag package [3] taught me how to |
54 |
perform the same things, check presence of functions and headers but |
55 |
using meson build system. An example to use meson build system to check |
56 |
for whether error.h is present on system and set a define accordingly |
57 |
would be: |
58 |
|
59 |
``` |
60 |
error_exists = cc.has_header('error.h') |
61 |
if error_exists |
62 |
add_global_arguments('-DHAVE_ERROR_H', language : 'c') |
63 |
endif |
64 |
``` |
65 |
|
66 |
The above snippet check is the error.h header is present in the current |
67 |
system, or provided by the current libc and then sets the HAVE_ERROR_H |
68 |
if it's true or if error.h is indeed present. |
69 |
|
70 |
So with this I'm able to now navigate around three major build systems |
71 |
to handle missing functions and headers which seems to be quite common |
72 |
when it comes to musl. |
73 |
|
74 |
Apart from all these things I'm also trying to upstream a few samba |
75 |
patches that would musl users [4], came across a GNOME bug where where |
76 |
mutter seem to be hitting a race condition on musl (from the comments on |
77 |
source code) whereas it's not the same on glibc. There is an open issue |
78 |
for this upstrem [5], so I'm still waiting for the developers to reply. |
79 |
However the original author of the issue does provide us with a |
80 |
workaround patch which seems to be working. This mutter issue is very |
81 |
specific to Xorg as I've not been able to reproduce the issue when using |
82 |
Wayland. |
83 |
|
84 |
I think this is a concise enough report for this week, there were a few |
85 |
minor patches/fixes that I did but it's nothing worthy mentioning of. |
86 |
Hope to find and fix more bugs in the future. Till then, long live |
87 |
Gentoo. |
88 |
|
89 |
[1]: https://github.com/gentoo/gentoo/pull/26223 |
90 |
[2]: https://github.com/gentoo/gentoo/pull/26353 |
91 |
[3]: https://github.com/gentoo/gentoo/pull/26437 |
92 |
[4]: https://gitlab.com/samba-team/samba/-/merge_requests/2617 |
93 |
[5]: https://gitlab.gnome.org/GNOME/mutter/-/issues/2103 |
94 |
-- |
95 |
Regards, |
96 |
listout |