dreport: Collect journal log in case PID is not present
dreport uses PID information from the elog or core file to
collect PID based journal logs as part the BMC dump.
Existing dreport skips journal log collection in case PID
information is missing in the elog or core file.
Proposed changes help to collect the last 500 journal entries when
the PID is not present in the elog entry or core file.
Resolves openbmc/openbmc#2716
Change-Id: Ib3d8dfea64ea17f4b020b429267294c36530848b
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/tools/dreport.d/dreport b/tools/dreport.d/dreport
index c37c193..7fc1c32 100755
--- a/tools/dreport.d/dreport
+++ b/tools/dreport.d/dreport
@@ -51,6 +51,8 @@
declare -rx PLUGIN="pl_"
declare -rx DREPORT_SOURCE="/usr/share/dreport.d"
declare -rx DREPORT_INCLUDE="$DREPORT_SOURCE/include.d"
+declare -rx ZERO="0"
+declare -rx JOURNAL_LINE_LIMIT="500"
#Error Codes
declare -rx SUCCESS="0"
@@ -70,7 +72,7 @@
declare -x dreport_log=""
declare -x summary_log=""
declare -x cur_dump_size=0
-declare -x pid="0"
+declare -x pid=$ZERO
declare -x elog_id=""
#Source dreport common functions
diff --git a/tools/dreport.d/plugins.d/journalpid b/tools/dreport.d/plugins.d/journalpid
index aa6a19a..0481d4d 100644
--- a/tools/dreport.d/plugins.d/journalpid
+++ b/tools/dreport.d/plugins.d/journalpid
@@ -7,7 +7,14 @@
. $DREPORT_INCLUDE/functions
desc="Journal pid:$pid log"
-file_name="journal-pid-$pid.log"
-command="journalctl -o verbose _PID=$pid"
+
+if [ $pid -eq $ZERO ]; then
+ log_warning "Missing PID, Collecting last 500 journal entries"
+ file_name="journal.log"
+ command="journalctl -o verbose -n $JOURNAL_LINE_LIMIT"
+else
+ file_name="journal-pid-$pid.log"
+ command="journalctl -o verbose _PID=$pid"
+fi
add_cmd_output "$command" "$file_name" "$desc"