From 3f708e7f6909faad307bdb60ed0f8d68e84f6584 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 22 Jul 2019 10:46:53 +0900 Subject: [PATCH 1/8] meson: drop redundant line Found by @mattiasb. --- meson.build | 2 -- 1 file changed, 2 deletions(-) diff --git a/meson.build b/meson.build index 3593eac710..04a830cdfa 100644 --- a/meson.build +++ b/meson.build @@ -2269,8 +2269,6 @@ if conf.get('ENABLE_PSTORE') == 1 install_rpath : rootlibexecdir, install : true, install_dir : rootlibexecdir) - - public_programs += exe endif if conf.get('ENABLE_BINFMT') == 1 From 2e4effd129343d22bfed34e94810d3f87c8f0e85 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 22 Jul 2019 10:52:12 +0900 Subject: [PATCH 2/8] pstore: drop unnecessary initializations --- src/pstore/pstore.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index 0c4e2f08a3..0febbcb716 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -116,14 +116,12 @@ static int compare_pstore_entries(const void *_a, const void *_b) { } static int move_file(PStoreEntry *pe, const char *subdir) { - _cleanup_free_ char *ifd_path = NULL; - _cleanup_free_ char *ofd_path = NULL; - int r = 0; - struct iovec iovec[2] = {}; - int n_iovec = 0; + _cleanup_free_ char *ifd_path = NULL, *ofd_path = NULL; _cleanup_free_ void *field = NULL; - const char *suffix = NULL; + struct iovec iovec[2]; + const char *suffix; size_t field_size; + int n_iovec = 0, r; if (pe->handled) return 0; @@ -205,10 +203,9 @@ static int write_dmesg(const char *dmesg, size_t size, const char *id) { static void process_dmesg_files(PStoreList *list) { /* Move files, reconstruct dmesg.txt */ - PStoreEntry *pe; - _cleanup_free_ char *dmesg = NULL; + _cleanup_free_ char *dmesg = NULL, *dmesg_id = NULL; size_t dmesg_size = 0; - _cleanup_free_ char *dmesg_id = NULL; + PStoreEntry *pe; /* Handle each dmesg file: files processed in reverse * order so as to properly reconstruct original dmesg */ From 337874a45fff46a80e4974c681a5e651f3a0fac9 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 22 Jul 2019 10:55:10 +0900 Subject: [PATCH 3/8] pstopre: fix return value of list_files() Previously, the return value of the last read_full_file() is returned. This makes the error in read_full_file() is always ignored. --- src/pstore/pstore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index 0febbcb716..86361d8ebc 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -314,7 +314,7 @@ static void process_dmesg_files(PStoreList *list) { static int list_files(PStoreList *list, const char *sourcepath) { _cleanup_(closedirp) DIR *dirp = NULL; struct dirent *de; - int r = 0; + int r; dirp = opendir(sourcepath); if (!dirp) @@ -333,7 +333,7 @@ static int list_files(PStoreList *list, const char *sourcepath) { /* Now read contents of pstore file */ r = read_full_file(ifd_path, &buf, &buf_size); if (r < 0) { - log_warning_errno(r, "Failed to read file %s: %m", ifd_path); + log_warning_errno(r, "Failed to read file %s, skipping: %m", ifd_path); continue; } @@ -349,7 +349,7 @@ static int list_files(PStoreList *list, const char *sourcepath) { }; } - return r; + return 0; } static int run(int argc, char *argv[]) { From f677270ebb4c57c1da3b948455250b38a75b89fb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 22 Jul 2019 10:58:13 +0900 Subject: [PATCH 4/8] pstore: drop commented out line --- src/pstore/pstore.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index 86361d8ebc..58db27fe1a 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -179,8 +179,6 @@ static int write_dmesg(const char *dmesg, size_t size, const char *id) { if (isempty(dmesg) || size == 0) return 0; - /* log_info("Record ID %s", id); */ - ofd_path = path_join(arg_archivedir, id, "dmesg.txt"); if (!ofd_path) return log_oom(); From 03c5f6cc02648eeff3179b2b762d46b9e1889bb1 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 22 Jul 2019 11:01:43 +0900 Subject: [PATCH 5/8] pstore: remove temporary file on failure --- src/pstore/pstore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index 58db27fe1a..dfa95742d3 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -170,8 +170,8 @@ static int move_file(PStoreEntry *pe, const char *subdir) { } static int write_dmesg(const char *dmesg, size_t size, const char *id) { - _cleanup_(unlink_and_freep) char *ofd_path = NULL; - _cleanup_free_ char *tmp_path = NULL; + _cleanup_(unlink_and_freep) char *tmp_path = NULL; + _cleanup_free_ char *ofd_path = NULL; _cleanup_close_ int ofd = -1; ssize_t wr; int r; @@ -194,7 +194,7 @@ static int write_dmesg(const char *dmesg, size_t size, const char *id) { r = link_tmpfile(ofd, tmp_path, ofd_path); if (r < 0) return log_error_errno(r, "Failed to write temporary file %s: %m", ofd_path); - ofd_path = mfree(ofd_path); + tmp_path = mfree(tmp_path); return 0; } From 6bf18debddbe1b231f783617e054cc194bb36d1e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 22 Jul 2019 11:08:06 +0900 Subject: [PATCH 6/8] pstore: do not add FILE= journal entry if content_size == 0 --- src/pstore/pstore.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index dfa95742d3..47301b1280 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -117,10 +117,8 @@ static int compare_pstore_entries(const void *_a, const void *_b) { static int move_file(PStoreEntry *pe, const char *subdir) { _cleanup_free_ char *ifd_path = NULL, *ofd_path = NULL; - _cleanup_free_ void *field = NULL; + const char *suffix, *message; struct iovec iovec[2]; - const char *suffix; - size_t field_size; int n_iovec = 0, r; if (pe->handled) @@ -136,15 +134,20 @@ static int move_file(PStoreEntry *pe, const char *subdir) { /* Always log to the journal */ suffix = arg_storage == PSTORE_STORAGE_EXTERNAL ? strjoina(" moved to ", ofd_path) : (char *)"."; - field = strjoina("MESSAGE=PStore ", pe->dirent.d_name, suffix); - iovec[n_iovec++] = IOVEC_MAKE_STRING(field); + message = strjoina("MESSAGE=PStore ", pe->dirent.d_name, suffix); + iovec[n_iovec++] = IOVEC_MAKE_STRING(message); - field_size = strlen("FILE=") + pe->content_size; - field = malloc(field_size); - if (!field) - return log_oom(); - memcpy(stpcpy(field, "FILE="), pe->content, pe->content_size); - iovec[n_iovec++] = IOVEC_MAKE(field, field_size); + if (pe->content_size > 0) { + _cleanup_free_ void *field = NULL; + size_t field_size; + + field_size = strlen("FILE=") + pe->content_size; + field = malloc(field_size); + if (!field) + return log_oom(); + memcpy(stpcpy(field, "FILE="), pe->content, pe->content_size); + iovec[n_iovec++] = IOVEC_MAKE(field, field_size); + } r = sd_journal_sendv(iovec, n_iovec); if (r < 0) From baa2ea8681aac261bd5d028d175442f3bc12335a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 22 Jul 2019 13:14:28 +0900 Subject: [PATCH 7/8] pstore: use log_setup_service() --- src/pstore/pstore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index 47301b1280..4bb1293e15 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -357,7 +357,7 @@ static int run(int argc, char *argv[]) { _cleanup_(pstore_entries_reset) PStoreList list = {}; int r; - log_open(); + log_setup_service(); /* Ignore all parse errors */ (void) parse_config(); From 6d4f213b1f6afb2901f0d97cec0e28e20809b713 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 22 Jul 2019 14:09:12 +0900 Subject: [PATCH 8/8] pstore: run only when /sys/fs/pstore is not empty --- units/systemd-pstore.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/units/systemd-pstore.service.in b/units/systemd-pstore.service.in index fec2b1aebf..dde21bc33e 100644 --- a/units/systemd-pstore.service.in +++ b/units/systemd-pstore.service.in @@ -10,6 +10,7 @@ [Unit] Description=Platform Persistent Storage Archival Documentation=man:systemd-pstore(8) +ConditionDirectoryNotEmpty=/sys/fs/pstore DefaultDependencies=no Wants=systemd-remount-fs.service After=systemd-remount-fs.service