[RFC PATCH] samples: fix building fs-monitor on musl systems.

Brahmajit Das posted 1 patch 3 months, 1 week ago
samples/fanotify/fs-monitor.c | 7 +++++++
1 file changed, 7 insertions(+)
[RFC PATCH] samples: fix building fs-monitor on musl systems.
Posted by Brahmajit Das 3 months, 1 week ago
On musl systems with make allyesconfig fs-monitor.c fails to build with

samples/fanotify/fs-monitor.c:22:9: error: unknown type name '__s32'
   22 |         __s32 error;
      |         ^~~~~
samples/fanotify/fs-monitor.c:23:9: error: unknown type name '__u32'
   23 |         __u32 error_count;
      |         ^~~~~
samples/fanotify/fs-monitor.c: In function 'handle_notifications':
samples/fanotify/fs-monitor.c:98:50: error: 'fsid_t' has no member named 'val'; did you mean '__val'?
   98 |                                        fid->fsid.val[0], fid->fsid.val[1]);
      |                                                  ^~~
      |                                                  __val
samples/fanotify/fs-monitor.c:98:68: error: 'fsid_t' has no member named 'val'; did you mean '__val'?
   98 |                                        fid->fsid.val[0], fid->fsid.val[1]);
      |                                                                    ^~~
      |                                                                    __val

This is due to sys/fanotify.h on musl does not include
linux/fanotify.h[0] unlike glibc which includes it. This also results in
fsid not being of type __kernel_fsid_t, rather the libc's definition of
it which does not have val, but instead __val.

[0]: https://git.musl-libc.org/cgit/musl/tree/include/sys/fanotify.h
Signed-off-by: Brahmajit Das <listout@listout.xyz>
---
 samples/fanotify/fs-monitor.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/samples/fanotify/fs-monitor.c b/samples/fanotify/fs-monitor.c
index 608db24c471e..28c0a652ffeb 100644
--- a/samples/fanotify/fs-monitor.c
+++ b/samples/fanotify/fs-monitor.c
@@ -12,6 +12,9 @@
 #include <sys/fanotify.h>
 #include <sys/types.h>
 #include <unistd.h>
+#ifndef __GLIBC__
+#include <asm-generic/int-ll64.h>
+#endif
 
 #ifndef FAN_FS_ERROR
 #define FAN_FS_ERROR		0x00008000
@@ -95,7 +98,11 @@ static void handle_notifications(char *buffer, int len)
 				fid = (struct fanotify_event_info_fid *) info;
 
 				printf("\tfsid: %x%x\n",
+#if defined(__GLIBC__)
 				       fid->fsid.val[0], fid->fsid.val[1]);
+#else
+				       fid->fsid.__val[0], fid->fsid.__val[1]);
+#endif
 				print_fh((struct file_handle *) &fid->handle);
 				break;
 
-- 
2.50.0
Re: [RFC PATCH] samples: fix building fs-monitor on musl systems.
Posted by Jan Kara 3 months, 1 week ago
On Mon 30-06-25 16:00:11, Brahmajit Das wrote:
> On musl systems with make allyesconfig fs-monitor.c fails to build with
> 
> samples/fanotify/fs-monitor.c:22:9: error: unknown type name '__s32'
>    22 |         __s32 error;
>       |         ^~~~~
> samples/fanotify/fs-monitor.c:23:9: error: unknown type name '__u32'
>    23 |         __u32 error_count;
>       |         ^~~~~
> samples/fanotify/fs-monitor.c: In function 'handle_notifications':
> samples/fanotify/fs-monitor.c:98:50: error: 'fsid_t' has no member named 'val'; did you mean '__val'?
>    98 |                                        fid->fsid.val[0], fid->fsid.val[1]);
>       |                                                  ^~~
>       |                                                  __val
> samples/fanotify/fs-monitor.c:98:68: error: 'fsid_t' has no member named 'val'; did you mean '__val'?
>    98 |                                        fid->fsid.val[0], fid->fsid.val[1]);
>       |                                                                    ^~~
>       |                                                                    __val
> 
> This is due to sys/fanotify.h on musl does not include
> linux/fanotify.h[0] unlike glibc which includes it. This also results in
> fsid not being of type __kernel_fsid_t, rather the libc's definition of
> it which does not have val, but instead __val.
> 
> [0]: https://git.musl-libc.org/cgit/musl/tree/include/sys/fanotify.h
> Signed-off-by: Brahmajit Das <listout@listout.xyz>

Thanks! Added to my tree.

								Honza

> ---
>  samples/fanotify/fs-monitor.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/samples/fanotify/fs-monitor.c b/samples/fanotify/fs-monitor.c
> index 608db24c471e..28c0a652ffeb 100644
> --- a/samples/fanotify/fs-monitor.c
> +++ b/samples/fanotify/fs-monitor.c
> @@ -12,6 +12,9 @@
>  #include <sys/fanotify.h>
>  #include <sys/types.h>
>  #include <unistd.h>
> +#ifndef __GLIBC__
> +#include <asm-generic/int-ll64.h>
> +#endif
>  
>  #ifndef FAN_FS_ERROR
>  #define FAN_FS_ERROR		0x00008000
> @@ -95,7 +98,11 @@ static void handle_notifications(char *buffer, int len)
>  				fid = (struct fanotify_event_info_fid *) info;
>  
>  				printf("\tfsid: %x%x\n",
> +#if defined(__GLIBC__)
>  				       fid->fsid.val[0], fid->fsid.val[1]);
> +#else
> +				       fid->fsid.__val[0], fid->fsid.__val[1]);
> +#endif
>  				print_fh((struct file_handle *) &fid->handle);
>  				break;
>  
> -- 
> 2.50.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR