[libcamera-devel,v2,1/2] meson: check if secure_getenv() is present

Message ID 20190426084220.71500-2-giulio.benetti@micronovasrl.com
State Accepted
Headers show
Series
  • improve secure_getenv()
Related show

Commit Message

Giulio Benetti April 26, 2019, 8:42 a.m. UTC
Not all libc make secure_getenv() available, this could lead to build
failure on certain build systems.

Check if secure_getenv() and emit #define HAVE_SECURE_GETENV to config.h
Include config.h to every c/c++ file during building by adding `-include
config.h` to project arguments for both c and c++.

Signed-off-by: Giulio Benetti <giulio.benetti@micronovasrl.com>
---
Changes:
V1->V2: use common_arguments to -include config.h and move secure_getenv()
        check before common_arguments list.

 meson.build | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Laurent Pinchart April 26, 2019, 10:30 a.m. UTC | #1
Hi Giulio,

Thank you for the patch.

On Fri, Apr 26, 2019 at 10:42:19AM +0200, Giulio Benetti wrote:
> Not all libc make secure_getenv() available, this could lead to build
> failure on certain build systems.
> 
> Check if secure_getenv() and emit #define HAVE_SECURE_GETENV to config.h

"if secure_getenv() is available" ?

> Include config.h to every c/c++ file during building by adding `-include
> config.h` to project arguments for both c and c++.
> 
> Signed-off-by: Giulio Benetti <giulio.benetti@micronovasrl.com>
> ---
> Changes:
> V1->V2: use common_arguments to -include config.h and move secure_getenv()
>         check before common_arguments list.
> 
>  meson.build | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/meson.build b/meson.build
> index 6e68c3e..9099909 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -13,8 +13,19 @@ project('libcamera', 'c', 'cpp',
>  #       generated from this too.
>  api_version = '0.1'
>  
> +cc = meson.get_compiler('c')
> +config_h = configuration_data()
> +
> +if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: '#define _GNU_SOURCE')

This doesn't need to be fixed as part of this patch series, but
shouldn't we also define GNU_SOURCE in our common arguments ?

> +    config_h.set('HAVE_SECURE_GETENV', 1)
> +else
> +    message('C library does not support secure_getenv, using getenv instead')

This isn't completely accurate, we condition that with issetugid(), it's
not as bad as using getenv() unconditionally. I wonder if we shouldn't
just drop this message.

Apart from that,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +endif
> +configure_file(output: 'config.h', configuration: config_h)
> +
>  common_arguments = [
>      '-Wno-unused-parameter',
> +    '-include', 'config.h',
>  ]
>  
>  c_arguments = common_arguments

Patch

diff --git a/meson.build b/meson.build
index 6e68c3e..9099909 100644
--- a/meson.build
+++ b/meson.build
@@ -13,8 +13,19 @@  project('libcamera', 'c', 'cpp',
 #       generated from this too.
 api_version = '0.1'
 
+cc = meson.get_compiler('c')
+config_h = configuration_data()
+
+if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix: '#define _GNU_SOURCE')
+    config_h.set('HAVE_SECURE_GETENV', 1)
+else
+    message('C library does not support secure_getenv, using getenv instead')
+endif
+configure_file(output: 'config.h', configuration: config_h)
+
 common_arguments = [
     '-Wno-unused-parameter',
+    '-include', 'config.h',
 ]
 
 c_arguments = common_arguments