[libvirt] [PATCH libvirt 3/6] Fix warnings about pid_t printf format on mingw64

Marc-André Lureau marcandre.lureau at gmail.com
Wed Jan 25 20:13:23 UTC 2012


Define PID_FORMAT and fix warnings for mingw64 x86_64 build.

Unfortunately, gnu_printf attribute check expect %lld while normal
printf is PRId64. So one warning remains.
---
 src/rpc/virnetsocket.c |    4 ++--
 src/util/command.c     |   10 +++++-----
 src/util/util.h        |    8 ++++++++
 src/util/virpidfile.c  |    6 +++---
 4 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 67d33b7..20bee4b 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -114,7 +114,7 @@ static virNetSocketPtr virNetSocketNew(virSocketAddrPtr localAddr,
     virNetSocketPtr sock;
     int no_slow_start = 1;
 
-    VIR_DEBUG("localAddr=%p remoteAddr=%p fd=%d errfd=%d pid=%d",
+    VIR_DEBUG("localAddr=%p remoteAddr=%p fd=%d errfd=%d pid=%" PID_FORMAT,
               localAddr, remoteAddr,
               fd, errfd, pid);
 
@@ -174,7 +174,7 @@ static virNetSocketPtr virNetSocketNew(virSocketAddrPtr localAddr,
     sock->client = isClient;
 
     PROBE(RPC_SOCKET_NEW,
-          "sock=%p refs=%d fd=%d errfd=%d pid=%d localAddr=%s, remoteAddr=%s",
+          "sock=%p refs=%d fd=%d errfd=%d pid=%" PID_FORMAT " localAddr=%s, remoteAddr=%s",
           sock, sock->refs, fd, errfd,
           pid, NULLSTR(sock->localAddrStr), NULLSTR(sock->remoteAddrStr));
 
diff --git a/src/util/command.c b/src/util/command.c
index dc3cfc5..1dc0090 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -2103,7 +2103,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
 
     if (cmd->pid != -1) {
         virCommandError(VIR_ERR_INTERNAL_ERROR,
-                        _("command is already running as pid %d"),
+                        _("command is already running as pid %" PID_FORMAT),
                         cmd->pid);
         return -1;
     }
@@ -2178,7 +2178,7 @@ virPidWait(pid_t pid, int *exitstatus)
     int status;
 
     if (pid <= 0) {
-        virReportSystemError(EINVAL, _("unable to wait for process %d"), pid);
+        virReportSystemError(EINVAL, _("unable to wait for process %" PID_FORMAT), pid);
         return -1;
     }
 
@@ -2187,7 +2187,7 @@ virPidWait(pid_t pid, int *exitstatus)
            errno == EINTR);
 
     if (ret == -1) {
-        virReportSystemError(errno, _("unable to wait for process %d"), pid);
+        virReportSystemError(errno, _("unable to wait for process %" PID_FORMAT), pid);
         return -1;
     }
 
@@ -2195,7 +2195,7 @@ virPidWait(pid_t pid, int *exitstatus)
         if (status != 0) {
             char *st = virCommandTranslateStatus(status);
             virCommandError(VIR_ERR_INTERNAL_ERROR,
-                            _("Child process (%d) status unexpected: %s"),
+                            _("Child process (%" PID_FORMAT ") status unexpected: %s"),
                             pid, NULLSTR(st));
             VIR_FREE(st);
             return -1;
@@ -2351,7 +2351,7 @@ void
 virPidAbort(pid_t pid)
 {
     /* Not yet ported to mingw.  Any volunteers?  */
-    VIR_DEBUG("failed to reap child %d, abandoning it", pid);
+    VIR_DEBUG("failed to reap child %" PID_FORMAT ", abandoning it", pid);
 }
 
 void
diff --git a/src/util/util.h b/src/util/util.h
index 94d9282..01c29ea 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -31,6 +31,7 @@
 # include <sys/select.h>
 # include <sys/types.h>
 # include <stdarg.h>
+# include <inttypes.h>
 
 # ifndef MIN
 #  define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -39,6 +40,13 @@
 #  define MAX(a, b) ((a) > (b) ? (a) : (b))
 # endif
 
+#ifdef _WIN64
+/* XXX gnu_printf prefers lld while non-gnu printf expect PRId64... */
+# define PID_FORMAT "lld"
+#else
+# define PID_FORMAT "d"
+#endif
+
 ssize_t saferead(int fd, void *buf, size_t count) ATTRIBUTE_RETURN_CHECK;
 ssize_t safewrite(int fd, const void *buf, size_t count)
     ATTRIBUTE_RETURN_CHECK;
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index 1fd6318..f2532d4 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -69,7 +69,7 @@ int virPidFileWritePath(const char *pidfile,
         goto cleanup;
     }
 
-    if (fprintf(file, "%d", pid) < 0) {
+    if (fprintf(file, "%" PID_FORMAT, pid) < 0) {
         rc = -errno;
         goto cleanup;
     }
@@ -127,7 +127,7 @@ int virPidFileReadPath(const char *path,
         goto cleanup;
     }
 
-    if (fscanf(file, "%d", pid) != 1) {
+    if (fscanf(file, "%" PID_FORMAT, pid) != 1) {
         rc = -EINVAL;
         VIR_FORCE_FCLOSE(file);
         goto cleanup;
@@ -209,7 +209,7 @@ int virPidFileReadPathIfAlive(const char *path,
     }
 #endif
 
-    if (virAsprintf(&procpath, "/proc/%d/exe", *pid) < 0) {
+    if (virAsprintf(&procpath, "/proc/%" PID_FORMAT "/exe", *pid) < 0) {
         *pid = -1;
         return -1;
     }
-- 
1.7.7.5




More information about the libvir-list mailing list