[PATCH 2/4] Fix warnings about pid_t printf format on mingw64

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Define PID_FORMAT and fix warnings for mingw64 x86_64 build.
---
 configure.ac           |    1 +
 src/rpc/virnetsocket.c |    4 ++--
 src/util/command.c     |   10 +++++-----
 src/util/util.h        |    7 +++++++
 src/util/virpidfile.c  |    6 +++---
 5 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/configure.ac b/configure.ac
index 9fb7bfc..0dd4a70 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,6 +128,7 @@ fi
 AC_MSG_RESULT([$have_cpuid])
 
 AC_CHECK_SIZEOF([long])
+AC_CHECK_SIZEOF([pid_t])
 
 dnl Availability of various common functions (non-fatal if missing),
 dnl and various less common threadsafe functions
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 e3a8371..1e4c206 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -2138,7 +2138,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;
     }
@@ -2214,7 +2214,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;
     }
 
@@ -2223,7 +2223,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;
     }
 
@@ -2231,7 +2231,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;
@@ -2387,7 +2387,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 f62cb42..3e8510d 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,12 @@
 #  define MAX(a, b) ((a) > (b) ? (a) : (b))
 # endif
 
+#if SIZEOF_PID_T == 4
+# define PID_FORMAT "d"
+#elif SIZEOF_PID_T == 8
+# define PID_FORMAT "lld"
+#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.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]