Fix for missing core file in the ApplicationCored type BMC dump

During application core, Systemd-coredump creates a temporary core
file first, compresses the file and renames it to systemd-coredump
name format.

dreport relies on inotify notifications to initiate the core dump
collection.

Usually inotify generates IN_MOVED_TO events followed
by IN_CLOSE_WRITE event on creation of system-coredump file.

In UBI filesystem, inotify notification events behave
differently as summarized below:

--------------------------------------------------------------------
   Inotifiy Event   :         UBI FS       :             COW
--------------------------------------------------------------------
- IN_MOVED_TO       :          _NA_        :  notification event
                    :                      :  structure provides the
                    :                      :  name of the core file.
                    :                      :
- IN_CREATE         : notification event   :           _NA_
                    : structure provides   :
                    : the name of the core :
                    : file.                :
                    :                      :
- IN_CLOSE_NOWRITE  : notification triggers:           _NA_
                    : directory  level and :
                    : size of name field   :
                    : shows zero.          :
                    :                      :
                    :                      :
- IN_CLOSE_WRITE    : notification event   : notification event
                    : structure provides   : structure provides the
                    : the INODE number     : name of the core file.
                    : instead of name of   :
                    : the core file.       :
----------------------------------------------------------------------

Current implementation relies on inotify IN_CLOSE_WRITE event with the
name of the core file to trigger the dump collection.

However, in UBI FS, the inode number is sent in the inotify instead of
the name of the core file.

Hence the copying of the core file during the dump collection process
fails due to lack of the file name information.

While IN_CLOSE_WRITE is the appropriate event, IN_CREATE is the
closest match for UBI FS.

Hence the *workaround* published by this patch watches for IN_CREATE
event for the UBI FS based systems.

One possible side effect is premature handling of large systemd-core
file resulting in an incomplete file. However, this was _not_ observed
during testing due to the time interval between the inotify and
dreport consuming the file.

A more generic fix may be explored for issue #2287.

Resolves openbmc/openbmc#2240

Change-Id: Id88181c62a34c05646eed4ac7e67d9b37a523733
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/configure.ac b/configure.ac
index d2565d7..776c440 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,5 +87,14 @@
 AS_IF([test "x$CLASS_VERSION" == "x"], [CLASS_VERSION=1])
 AC_DEFINE_UNQUOTED([CLASS_VERSION], [$CLASS_VERSION], [Class version to register with Cereal])
 
+AC_ARG_ENABLE([ubifs-workaround],
+    AS_HELP_STRING([--enable-ubifs-workaround],
+                   [Turn on ubi workaround for core file])
+)
+AS_IF([test "x$enable_ubifs_workaround" != "xno"],
+      [AC_DEFINE([UBI_CORE_FILE_WORKAROUND], [],
+      [Turn on ubi workaround for core file])]
+)
+
 AC_CONFIG_FILES([Makefile])
 AC_OUTPUT