5808e7
From 5006e4bd9aecea40ca3d907adc692c4c8001a6c1 Mon Sep 17 00:00:00 2001
5808e7
From: Yu Watanabe <watanabe.yu+github@gmail.com>
5808e7
Date: Mon, 22 Jul 2019 11:08:06 +0900
5808e7
Subject: [PATCH] pstore: do not add FILE= journal entry if content_size == 0
5808e7
5808e7
(cherry picked from commit 6bf18debddbe1b231f783617e054cc194bb36d1e)
5808e7
5808e7
Related: #2158832
5808e7
---
5808e7
 src/pstore/pstore.c | 25 ++++++++++++++-----------
5808e7
 1 file changed, 14 insertions(+), 11 deletions(-)
5808e7
5808e7
diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c
5808e7
index ce8080ceed..eb251d61c8 100644
5808e7
--- a/src/pstore/pstore.c
5808e7
+++ b/src/pstore/pstore.c
5808e7
@@ -114,10 +114,8 @@ static int compare_pstore_entries(const void *_a, const void *_b) {
5808e7
 
5808e7
 static int move_file(PStoreEntry *pe, const char *subdir) {
5808e7
         _cleanup_free_ char *ifd_path = NULL, *ofd_path = NULL;
5808e7
-        _cleanup_free_ void *field = NULL;
5808e7
+        const char *suffix, *message;
5808e7
         struct iovec iovec[2];
5808e7
-        const char *suffix;
5808e7
-        size_t field_size;
5808e7
         int n_iovec = 0, r;
5808e7
 
5808e7
         if (pe->handled)
5808e7
@@ -133,15 +131,20 @@ static int move_file(PStoreEntry *pe, const char *subdir) {
5808e7
 
5808e7
         /* Always log to the journal */
5808e7
         suffix = arg_storage == PSTORE_STORAGE_EXTERNAL ? strjoina(" moved to ", ofd_path) : (char *)".";
5808e7
-        field = strjoina("MESSAGE=PStore ", pe->dirent.d_name, suffix);
5808e7
-        iovec[n_iovec++] = IOVEC_MAKE_STRING(field);
5808e7
+        message = strjoina("MESSAGE=PStore ", pe->dirent.d_name, suffix);
5808e7
+        iovec[n_iovec++] = IOVEC_MAKE_STRING(message);
5808e7
 
5808e7
-        field_size = strlen("FILE=") + pe->content_size;
5808e7
-        field = malloc(field_size);
5808e7
-        if (!field)
5808e7
-                return log_oom();
5808e7
-        memcpy(stpcpy(field, "FILE="), pe->content, pe->content_size);
5808e7
-        iovec[n_iovec++] = IOVEC_MAKE(field, field_size);
5808e7
+        if (pe->content_size > 0) {
5808e7
+                _cleanup_free_ void *field = NULL;
5808e7
+                size_t field_size;
5808e7
+
5808e7
+                field_size = strlen("FILE=") + pe->content_size;
5808e7
+                field = malloc(field_size);
5808e7
+                if (!field)
5808e7
+                        return log_oom();
5808e7
+                memcpy(stpcpy(field, "FILE="), pe->content, pe->content_size);
5808e7
+                iovec[n_iovec++] = IOVEC_MAKE(field, field_size);
5808e7
+        }
5808e7
 
5808e7
         r = sd_journal_sendv(iovec, n_iovec);
5808e7
         if (r < 0)