[PATCH] util: virdaemon: fix compilation on mingw

Rafael Fonseca posted 1 patch 4 years ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200327174047.2963859-1-r4f4rfs@gmail.com
src/util/virdaemon.c | 46 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 41 insertions(+), 5 deletions(-)
[PATCH] util: virdaemon: fix compilation on mingw
Posted by Rafael Fonseca 4 years ago
The daemons are not supported on Win32 and therefore were not compiled
in that platform. However, with the daemon code sharing, all the code in
utils *is* compiled and it failed because `waitpid`, `fork`, and
`setsid` are not available. So, as before, let's not build them on
Win32 and make the code more portable by using existing vir* wrappers.

Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
---
 src/util/virdaemon.c | 46 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 5 deletions(-)

diff --git a/src/util/virdaemon.c b/src/util/virdaemon.c
index 789adc6c50..5d92c7def7 100644
--- a/src/util/virdaemon.c
+++ b/src/util/virdaemon.c
@@ -20,9 +20,7 @@
 
 #include <config.h>
 
-#include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/wait.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <stdbool.h>
@@ -32,9 +30,13 @@
 #include "virfile.h"
 #include "virlog.h"
 #include "viralloc.h"
+#include "virprocess.h"
+#include "vircommand.h"
 
 #include "configmake.h"
 
+#ifndef WIN32
+
 int
 virDaemonForkIntoBackground(const char *argv0)
 {
@@ -42,7 +44,7 @@ virDaemonForkIntoBackground(const char *argv0)
     if (virPipeQuiet(statuspipe) < 0)
         return -1;
 
-    pid_t pid = fork();
+    pid_t pid = virFork();
     switch (pid) {
     case 0:
         {
@@ -71,7 +73,7 @@ virDaemonForkIntoBackground(const char *argv0)
             if (setsid() < 0)
                 goto cleanup;
 
-            nextpid = fork();
+            nextpid = virFork();
             switch (nextpid) {
             case 0: /* grandchild */
                 return statuspipe[1];
@@ -102,7 +104,7 @@ virDaemonForkIntoBackground(const char *argv0)
             VIR_FORCE_CLOSE(statuspipe[1]);
 
             /* We wait to make sure the first child forked successfully */
-            if ((got = waitpid(pid, &exitstatus, 0)) < 0 ||
+            if ((got = virProcessWait(pid, &exitstatus, 0)) < 0 ||
                 got != pid ||
                 exitstatus != 0) {
                 goto error;
@@ -250,3 +252,37 @@ virDaemonUnixSocketPaths(const char *sock_prefix,
     VIR_FREE(rundir);
     return ret;
 }
+
+#else /* WIN32 */
+
+int virDaemonForkIntoBackground(const char *argv0 G_GNUC_UNUSED)
+{
+    errno = ENOTSUP;
+    return -1;
+}
+
+void virDaemonSetupLogging(const char *daemon_name G_GNUC_UNUSED,
+                           unsigned int log_level G_GNUC_UNUSED,
+                           char *log_filters G_GNUC_UNUSED,
+                           char *log_outputs G_GNUC_UNUSED,
+                           bool privileged G_GNUC_UNUSED,
+                           bool verbose G_GNUC_UNUSED,
+                           bool godaemon G_GNUC_UNUSED)
+{
+    /* NOOP */
+    errno = ENOTSUP;
+    return;
+}
+
+int virDaemonUnixSocketPaths(const char *sock_prefix G_GNUC_UNUSED,
+                             bool privileged G_GNUC_UNUSED,
+                             char *unix_sock_dir G_GNUC_UNUSED,
+                             char **sockfile G_GNUC_UNUSED,
+                             char **rosockfile G_GNUC_UNUSED,
+                             char **adminSockfile G_GNUC_UNUSED)
+{
+    errno = ENOTSUP;
+    return -1;
+}
+
+#endif /* WIN32 */
-- 
2.25.1


Re: [PATCH] util: virdaemon: fix compilation on mingw
Posted by Marc-André Lureau 3 years, 12 months ago
On Fri, Mar 27, 2020 at 6:41 PM Rafael Fonseca <r4f4rfs@gmail.com> wrote:
>
> The daemons are not supported on Win32 and therefore were not compiled
> in that platform. However, with the daemon code sharing, all the code in
> utils *is* compiled and it failed because `waitpid`, `fork`, and
> `setsid` are not available. So, as before, let's not build them on
> Win32 and make the code more portable by using existing vir* wrappers.
>
> Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  src/util/virdaemon.c | 46 +++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 41 insertions(+), 5 deletions(-)
>
> diff --git a/src/util/virdaemon.c b/src/util/virdaemon.c
> index 789adc6c50..5d92c7def7 100644
> --- a/src/util/virdaemon.c
> +++ b/src/util/virdaemon.c
> @@ -20,9 +20,7 @@
>
>  #include <config.h>
>
> -#include <sys/types.h>
>  #include <sys/stat.h>
> -#include <sys/wait.h>
>  #include <fcntl.h>
>  #include <unistd.h>
>  #include <stdbool.h>
> @@ -32,9 +30,13 @@
>  #include "virfile.h"
>  #include "virlog.h"
>  #include "viralloc.h"
> +#include "virprocess.h"
> +#include "vircommand.h"
>
>  #include "configmake.h"
>
> +#ifndef WIN32
> +
>  int
>  virDaemonForkIntoBackground(const char *argv0)
>  {
> @@ -42,7 +44,7 @@ virDaemonForkIntoBackground(const char *argv0)
>      if (virPipeQuiet(statuspipe) < 0)
>          return -1;
>
> -    pid_t pid = fork();
> +    pid_t pid = virFork();
>      switch (pid) {
>      case 0:
>          {
> @@ -71,7 +73,7 @@ virDaemonForkIntoBackground(const char *argv0)
>              if (setsid() < 0)
>                  goto cleanup;
>
> -            nextpid = fork();
> +            nextpid = virFork();
>              switch (nextpid) {
>              case 0: /* grandchild */
>                  return statuspipe[1];
> @@ -102,7 +104,7 @@ virDaemonForkIntoBackground(const char *argv0)
>              VIR_FORCE_CLOSE(statuspipe[1]);
>
>              /* We wait to make sure the first child forked successfully */
> -            if ((got = waitpid(pid, &exitstatus, 0)) < 0 ||
> +            if ((got = virProcessWait(pid, &exitstatus, 0)) < 0 ||
>                  got != pid ||
>                  exitstatus != 0) {
>                  goto error;
> @@ -250,3 +252,37 @@ virDaemonUnixSocketPaths(const char *sock_prefix,
>      VIR_FREE(rundir);
>      return ret;
>  }
> +
> +#else /* WIN32 */
> +
> +int virDaemonForkIntoBackground(const char *argv0 G_GNUC_UNUSED)
> +{
> +    errno = ENOTSUP;
> +    return -1;
> +}
> +
> +void virDaemonSetupLogging(const char *daemon_name G_GNUC_UNUSED,
> +                           unsigned int log_level G_GNUC_UNUSED,
> +                           char *log_filters G_GNUC_UNUSED,
> +                           char *log_outputs G_GNUC_UNUSED,
> +                           bool privileged G_GNUC_UNUSED,
> +                           bool verbose G_GNUC_UNUSED,
> +                           bool godaemon G_GNUC_UNUSED)
> +{
> +    /* NOOP */
> +    errno = ENOTSUP;
> +    return;
> +}
> +
> +int virDaemonUnixSocketPaths(const char *sock_prefix G_GNUC_UNUSED,
> +                             bool privileged G_GNUC_UNUSED,
> +                             char *unix_sock_dir G_GNUC_UNUSED,
> +                             char **sockfile G_GNUC_UNUSED,
> +                             char **rosockfile G_GNUC_UNUSED,
> +                             char **adminSockfile G_GNUC_UNUSED)
> +{
> +    errno = ENOTSUP;
> +    return -1;
> +}
> +
> +#endif /* WIN32 */
> --
> 2.25.1
>
>


-- 
Marc-André Lureau


Re: [PATCH] util: virdaemon: fix compilation on mingw
Posted by Michal Prívozník 3 years, 12 months ago
On 27. 3. 2020 18:40, Rafael Fonseca wrote:
> The daemons are not supported on Win32 and therefore were not compiled
> in that platform. However, with the daemon code sharing, all the code in
> utils *is* compiled and it failed because `waitpid`, `fork`, and
> `setsid` are not available. So, as before, let's not build them on
> Win32 and make the code more portable by using existing vir* wrappers.
> 
> Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
> ---
>  src/util/virdaemon.c | 46 +++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 41 insertions(+), 5 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

and pushed.

Michal