[PATCH] util: Move 'virProcessLimitResourceToLabel' into same preprocessor if-block as only caller

Peter Krempa via Devel posted 1 patch 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/16e8d39a6ab9e29be3a965fb0a16ab5fd169802c.1773074892.git.pkrempa@redhat.com
src/util/virprocess.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
[PATCH] util: Move 'virProcessLimitResourceToLabel' into same preprocessor if-block as only caller
Posted by Peter Krempa via Devel 2 weeks ago
From: Peter Krempa <pkrempa@redhat.com>

'virProcessLimitResourceToLabel' is called only from
'virProcessGetLimitFromProc' but the latter has different conditions
when it's compiled. In certain cases this could lead to build failures.

Fixes: 90fe839f8a0
Closes: https://gitlab.com/libvirt/libvirt/-/work_items/848
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/util/virprocess.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index e8120c1bdc..e06ed94b0d 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -743,36 +743,36 @@ virProcessPrLimit(pid_t pid G_GNUC_UNUSED,
 #endif

 #if WITH_GETRLIMIT
+# if defined(__linux__)
 static const char*
 virProcessLimitResourceToLabel(int resource)
 {
     switch (resource) {
-# if defined(RLIMIT_MEMLOCK)
+#  if defined(RLIMIT_MEMLOCK)
         case RLIMIT_MEMLOCK:
             return "Max locked memory";
-# endif /* defined(RLIMIT_MEMLOCK) */
+#  endif /* defined(RLIMIT_MEMLOCK) */

-# if defined(RLIMIT_NPROC)
+#  if defined(RLIMIT_NPROC)
         case RLIMIT_NPROC:
             return "Max processes";
-# endif /* defined(RLIMIT_NPROC) */
+#  endif /* defined(RLIMIT_NPROC) */

-# if defined(RLIMIT_NOFILE)
+#  if defined(RLIMIT_NOFILE)
         case RLIMIT_NOFILE:
             return "Max open files";
-# endif /* defined(RLIMIT_NOFILE) */
+#  endif /* defined(RLIMIT_NOFILE) */

-# if defined(RLIMIT_CORE)
+#  if defined(RLIMIT_CORE)
         case RLIMIT_CORE:
             return "Max core file size";
-# endif /* defined(RLIMIT_CORE) */
+#  endif /* defined(RLIMIT_CORE) */

         default:
             return NULL;
     }
 }

-# if defined(__linux__)
 static int
 virProcessGetLimitFromProc(pid_t pid,
                            int resource,
-- 
2.53.0
Re: [PATCH] util: Move 'virProcessLimitResourceToLabel' into same preprocessor if-block as only caller
Posted by Roman Bogorodskiy 1 week, 6 days ago
  Peter Krempa via Devel wrote:

> From: Peter Krempa <pkrempa@redhat.com>
> 
> 'virProcessLimitResourceToLabel' is called only from
> 'virProcessGetLimitFromProc' but the latter has different conditions
> when it's compiled. In certain cases this could lead to build failures.
> 
> Fixes: 90fe839f8a0
> Closes: https://gitlab.com/libvirt/libvirt/-/work_items/848
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/util/virprocess.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/src/util/virprocess.c b/src/util/virprocess.c
> index e8120c1bdc..e06ed94b0d 100644
> --- a/src/util/virprocess.c
> +++ b/src/util/virprocess.c
> @@ -743,36 +743,36 @@ virProcessPrLimit(pid_t pid G_GNUC_UNUSED,
>  #endif
> 
>  #if WITH_GETRLIMIT
> +# if defined(__linux__)
>  static const char*
>  virProcessLimitResourceToLabel(int resource)
>  {
>      switch (resource) {
> -# if defined(RLIMIT_MEMLOCK)
> +#  if defined(RLIMIT_MEMLOCK)
>          case RLIMIT_MEMLOCK:
>              return "Max locked memory";
> -# endif /* defined(RLIMIT_MEMLOCK) */
> +#  endif /* defined(RLIMIT_MEMLOCK) */
> 
> -# if defined(RLIMIT_NPROC)
> +#  if defined(RLIMIT_NPROC)
>          case RLIMIT_NPROC:
>              return "Max processes";
> -# endif /* defined(RLIMIT_NPROC) */
> +#  endif /* defined(RLIMIT_NPROC) */
> 
> -# if defined(RLIMIT_NOFILE)
> +#  if defined(RLIMIT_NOFILE)
>          case RLIMIT_NOFILE:
>              return "Max open files";
> -# endif /* defined(RLIMIT_NOFILE) */
> +#  endif /* defined(RLIMIT_NOFILE) */
> 
> -# if defined(RLIMIT_CORE)
> +#  if defined(RLIMIT_CORE)
>          case RLIMIT_CORE:
>              return "Max core file size";
> -# endif /* defined(RLIMIT_CORE) */
> +#  endif /* defined(RLIMIT_CORE) */
> 
>          default:
>              return NULL;
>      }
>  }
> 
> -# if defined(__linux__)
>  static int
>  virProcessGetLimitFromProc(pid_t pid,
>                             int resource,
> -- 
> 2.53.0
> 

Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>