]> xenbits.xensource.com Git - libvirt.git/commitdiff
virpidfile: Allow whitespace character at the end of pidfile
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 13 Feb 2012 13:27:15 +0000 (14:27 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 13 Feb 2012 13:40:46 +0000 (14:40 +0100)
Some programs, notably dnsmasq, which are writing pidfiles on their
own do append a whitespace character after pid, e.g. '\n'.

src/util/virpidfile.c

index 34d125000c1493ba3993bb3ed4ef1277ca3e84a8..9c299673ae139e9e1b42f5ef8366335340425755 100644 (file)
@@ -34,7 +34,7 @@
 #include "intprops.h"
 #include "logging.h"
 #include "virterror_internal.h"
-
+#include "c-ctype.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -119,6 +119,7 @@ int virPidFileReadPath(const char *path,
     ssize_t bytes;
     long long pid_value = 0;
     char pidstr[INT_BUFSIZE_BOUND(pid_value)];
+    char *endptr = NULL;
 
     *pid = 0;
 
@@ -135,7 +136,8 @@ int virPidFileReadPath(const char *path,
     }
     pidstr[bytes] = '\0';
 
-    if (virStrToLong_ll(pidstr, NULL, 10, &pid_value) < 0 ||
+    if (virStrToLong_ll(pidstr, &endptr, 10, &pid_value) < 0 ||
+        !(*endptr == '\0' || c_isspace(*endptr)) ||
         (pid_t) pid_value != pid_value) {
         rc = -1;
         goto cleanup;