diff mbox series

[v2,1/1] lapi/fsmount.h: Fix headers conflict

Message ID 20240105002914.1463989-1-pvorel@suse.cz
State Changes Requested
Headers show
Series [v2,1/1] lapi/fsmount.h: Fix headers conflict | expand

Commit Message

Petr Vorel Jan. 5, 2024, 12:29 a.m. UTC
glibc doc [1] mentions conflict between <linux/mount.h> and
<sys/mount.h>. Because <linux/fs.h> includes <linux/mount.h> it's easy
to get <linux/mount.h> mounted indirectly.

Problem was fixed on glibc 2.37:
774058d729 ("linux: Fix sys/mount.h usage with kernel headers")
and it got backported to git tree for 2.36 and to some distros.
But it still fails for older glibc.

Therefore include <sys/mount.h> only if <linux/mount.h> not already
included.

[1] https://sourceware.org/glibc/wiki/Synchronizing_Headers

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v1->v2:
* Really fix the inlusion.

Tested:
https://github.com/pevik/ltp/actions/runs/7416363524

 include/lapi/fsmount.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Li Wang Jan. 8, 2024, 9:05 a.m. UTC | #1
On Fri, Jan 5, 2024 at 8:29 AM Petr Vorel <pvorel@suse.cz> wrote:

> glibc doc [1] mentions conflict between <linux/mount.h> and
> <sys/mount.h>. Because <linux/fs.h> includes <linux/mount.h> it's easy
> to get <linux/mount.h> mounted indirectly.
>
> Problem was fixed on glibc 2.37:
> 774058d729 ("linux: Fix sys/mount.h usage with kernel headers")
> and it got backported to git tree for 2.36 and to some distros.
> But it still fails for older glibc.
>
> Therefore include <sys/mount.h> only if <linux/mount.h> not already
> included.
>
> [1] https://sourceware.org/glibc/wiki/Synchronizing_Headers
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> Changes v1->v2:
> * Really fix the inlusion.
>
> Tested:
> https://github.com/pevik/ltp/actions/runs/7416363524
>
>  include/lapi/fsmount.h | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/include/lapi/fsmount.h b/include/lapi/fsmount.h
> index 07eb42ffa..a9491a16d 100644
> --- a/include/lapi/fsmount.h
> +++ b/include/lapi/fsmount.h
> @@ -1,6 +1,6 @@
>  // SPDX-License-Identifier: GPL-2.0-or-later
>  /*
> - * Copyright (c) Linux Test Project, 2021-2022
> + * Copyright (c) Linux Test Project, 2021-2024
>   * Copyright (c) 2020 Linaro Limited. All rights reserved.
>   * Author: Viresh Kumar <viresh.kumar@linaro.org>
>   */
> @@ -11,12 +11,11 @@
>  #include "config.h"
>  #include <sys/syscall.h>
>  #include <sys/types.h>
> -#include <sys/mount.h>
>
> -#ifndef HAVE_FSOPEN
> -# ifdef HAVE_LINUX_MOUNT_H
> -#  include <linux/mount.h>
> -# endif
> +#if !defined(HAVE_FSOPEN) && defined(HAVE_LINUX_MOUNT_H)
> +# include <linux/mount.h>
> +#else
> +# include <sys/mount.h>
>

This narrows down the usage conditions of the sys/mount.h header,
I am not sure if the benefits are more, but it seems strict and safe. So:

Reviewed-by: Li Wang <liwang@redhat.com>



>  #endif
>
>  #include "lapi/fcntl.h"
> --
> 2.43.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
diff mbox series

Patch

diff --git a/include/lapi/fsmount.h b/include/lapi/fsmount.h
index 07eb42ffa..a9491a16d 100644
--- a/include/lapi/fsmount.h
+++ b/include/lapi/fsmount.h
@@ -1,6 +1,6 @@ 
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) Linux Test Project, 2021-2022
+ * Copyright (c) Linux Test Project, 2021-2024
  * Copyright (c) 2020 Linaro Limited. All rights reserved.
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
@@ -11,12 +11,11 @@ 
 #include "config.h"
 #include <sys/syscall.h>
 #include <sys/types.h>
-#include <sys/mount.h>
 
-#ifndef HAVE_FSOPEN
-# ifdef HAVE_LINUX_MOUNT_H
-#  include <linux/mount.h>
-# endif
+#if !defined(HAVE_FSOPEN) && defined(HAVE_LINUX_MOUNT_H)
+# include <linux/mount.h>
+#else
+# include <sys/mount.h>
 #endif
 
 #include "lapi/fcntl.h"