[PATCH 15/24] Make libs/light build on NetBSD

Manuel Bouyer posted 24 patches 5 years, 1 month ago
[PATCH 15/24] Make libs/light build on NetBSD
Posted by Manuel Bouyer 5 years, 1 month ago
---
 tools/libs/light/libxl_dm.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c
index 5948ace60d..c93bdf2cc9 100644
--- a/tools/libs/light/libxl_dm.c
+++ b/tools/libs/light/libxl_dm.c
@@ -3659,6 +3659,14 @@ static int kill_device_model_uid_child(libxl__destroy_devicemodel_state *ddms,
 
     LOGD(DEBUG, domid, "DM reaper: calling setresuid(%d, %d, 0)",
          reaper_uid, dm_kill_uid);
+#ifdef __NetBSD__
+    r = setuid(dm_kill_uid);
+    if (r) {
+        LOGED(ERROR, domid, "setuid to %d", dm_kill_uid);
+        rc = rc ?: ERROR_FAIL;
+        goto out;
+    }
+#else /* __NetBSD__ */
     r = setresuid(reaper_uid, dm_kill_uid, 0);
     if (r) {
         LOGED(ERROR, domid, "setresuid to (%d, %d, 0)",
@@ -3666,6 +3674,7 @@ static int kill_device_model_uid_child(libxl__destroy_devicemodel_state *ddms,
         rc = rc ?: ERROR_FAIL;
         goto out;
     }
+#endif /* __NetBSD__ */
 
     /*
      * And kill everyone but me.
-- 
2.28.0


Re: [PATCH 15/24] Make libs/light build on NetBSD
Posted by Roger Pau Monné 5 years, 1 month ago
On Mon, Dec 14, 2020 at 05:36:14PM +0100, Manuel Bouyer wrote:
> ---
>  tools/libs/light/libxl_dm.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c
> index 5948ace60d..c93bdf2cc9 100644
> --- a/tools/libs/light/libxl_dm.c
> +++ b/tools/libs/light/libxl_dm.c
> @@ -3659,6 +3659,14 @@ static int kill_device_model_uid_child(libxl__destroy_devicemodel_state *ddms,
>  
>      LOGD(DEBUG, domid, "DM reaper: calling setresuid(%d, %d, 0)",

For correctness you should change this log message also on NetBSD.

>           reaper_uid, dm_kill_uid);
> +#ifdef __NetBSD__
> +    r = setuid(dm_kill_uid);
> +    if (r) {
> +        LOGED(ERROR, domid, "setuid to %d", dm_kill_uid);
> +        rc = rc ?: ERROR_FAIL;
> +        goto out;
> +    }
> +#else /* __NetBSD__ */
>      r = setresuid(reaper_uid, dm_kill_uid, 0);
>      if (r) {
>          LOGED(ERROR, domid, "setresuid to (%d, %d, 0)",
> @@ -3666,6 +3674,7 @@ static int kill_device_model_uid_child(libxl__destroy_devicemodel_state *ddms,
>          rc = rc ?: ERROR_FAIL;
>          goto out;
>      }
> +#endif /* __NetBSD__ */

Instead of adding this NetBSD specific bodge here I would add a test
for setresuid in tools/configure.ac using AC_CHECK_FUNCS and use the
result from that. Then if/when NetBSD implements setresuid the switch
will be done transparently.

Thanks, Roger.