chiark / gitweb /
sd-journal: properly parse cursor strings
[elogind.git] / src / journal / journal-send.c
index d0f3b725ff5ee9a3a1d97e0fc5fe33f4a7fc11f8..d503f3f428e56c5cab0a4f41aaaaad897ca1f050 100644 (file)
@@ -25,6 +25,7 @@
 #include <stddef.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <printf.h>
 
 #define SD_JOURNAL_SUPPRESS_LOCATION
 
@@ -121,6 +122,7 @@ static int fill_iovec_sprintf(const char *format, va_list ap, int extra, struct
         while (format) {
                 struct iovec *c;
                 char *buffer;
+                va_list aq;
 
                 if (i >= n) {
                         n = MAX(i*2, 4);
@@ -133,10 +135,15 @@ static int fill_iovec_sprintf(const char *format, va_list ap, int extra, struct
                         iov = c;
                 }
 
-                if (vasprintf(&buffer, format, ap) < 0) {
+                va_copy(aq, ap);
+                if (vasprintf(&buffer, format, aq) < 0) {
+                        va_end(aq);
                         r = -ENOMEM;
                         goto fail;
                 }
+                va_end(aq);
+
+                VA_FORMAT_ADVANCE(format, ap);
 
                 IOVEC_SET_STRING(iov[i++], buffer);
 
@@ -439,7 +446,7 @@ _public_ int sd_journal_stream_fd(const char *identifier, int priority, int leve
 
         memcpy(header, identifier, l);
         header[l++] = '\n';
-        header[l++] = '\n';
+        header[l++] = '\n'; /* unit id */
         header[l++] = '0' + priority;
         header[l++] = '\n';
         header[l++] = '0' + !!level_prefix;