Add option to release the crashed process as soon as possible 96/234096/6
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 21 May 2020 09:28:12 +0000 (11:28 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 22 May 2020 15:00:53 +0000 (17:00 +0200)
Change-Id: Idd951c4b8c50ba1e29524339358475acdbacd382

src/crash-manager/crash-manager.c
src/crash-manager/crash-manager.conf
src/shared/config.c
src/shared/config.h

index ddd38cc..ea4c3b7 100644 (file)
@@ -1251,6 +1251,23 @@ void crash_info_init(struct crash_info *cinfo)
        cinfo->lock_fd = -1;
 }
 
+static void release_crashed_process()
+{
+       /* Release the core pipe as passed by kernel, allowing another
+        * coredump to be handled.
+        *
+        * Due to usage of core_pipe_limit there is limited number of
+        * crash-manager processes that kernel is going to invoke
+        * concurrently.  As the next and last step is a _synchronous_
+        * call to crash-popup we close the descriptor here.
+        *
+        * Note: for VIP processes this will likely cause the system
+        * to reboot without showing popup.
+        */
+       close(STDIN_FILENO);
+       _I("Released crashed process lock");
+}
+
 static bool run(struct crash_info *cinfo)
 {
        /* Execute processes in parallel */
@@ -1277,6 +1294,9 @@ static bool run(struct crash_info *cinfo)
                return false;
        }
 
+       if (!cinfo->livedump && config.release_early)
+               release_crashed_process();
+
        char *temp_report;
        if (config.report_type >= REP_TYPE_FULL) {
                /* Save shared objects info (file names, bulid IDs, rpm package names) */
@@ -1304,18 +1324,8 @@ static bool run(struct crash_info *cinfo)
                printf("REPORT_PATH=%s\n", cinfo->result_path);
 
        if (!cinfo->livedump) {
-               /* Release the core pipe as passed by kernel, allowing another
-                * coredump to be handled.
-                *
-                * Due to usage of core_pipe_limit there is limited number of
-                * crash-manager processes that kernel is going to invoke
-                * concurrently.  As the next and last step is a _synchronous_
-                * call to crash-popup we close the descriptor here.
-                *
-                * Note: for VIP processes this will likely cause the system
-                * to reboot without showing popup.
-                */
-               close(STDIN_FILENO);
+               if (!config.release_early)
+                       release_crashed_process();
 
                launch_dbus_notify(cinfo);
 
index 09f3926..d1f58af 100644 (file)
@@ -5,6 +5,14 @@ MaxRetentionSec=0
 MaxCrashDump=0
 AllowZip=yes
 
+# Release process before report completion (default - no)
+# This option determines whether the crashing process should be released
+# immediately after reading the necessary data from /proc/<PID>/ to allow the
+# process to be cleaned up. This is important for VIP processes because if they
+# are cleaned up too early, the device will be rebooted before the full report
+# is written.
+# ReleaseProcessLockEarly=no
+
 # Crash report path must exist for the reports to be created
 # CrashRootPath=/usr/opt/share/crash/
 
index 60f168e..947095f 100644 (file)
@@ -154,6 +154,7 @@ static bool config_load_from_dict(config_t *c, const dictionary *ini)
        UPDATE(c->dump_so_info, boolean, "DumpSharedObjectInfo");
        UPDATE(c->allow_zip, boolean, "AllowZip");
        UPDATE(c->legacy_notification, boolean, "UseLegacyNotification");
+       UPDATE(c->release_early, boolean, "ReleaseProcessLockEarly");
 
 #undef UPDATE
 
@@ -251,6 +252,7 @@ static bool config_apply_defaults(config_t *c)
        c->dump_so_info = DUMP_SO_INFO;
        c->allow_zip = ALLOW_ZIP;
        c->legacy_notification = LEGACY_NOTIFICATION;
+       c->release_early = RELEASE_EARLY;
 
        return c->crash_root_path != NULL;
 }
@@ -269,7 +271,8 @@ static void config_dump(config_t *c)
           "config: dump_core = %d\n"
           "config: dump_so_info = %d\n"
           "config: allow_zip = %d\n"
-          "config: legacy_notification = %d\n",
+          "config: legacy_notification = %d\n"
+          "config: release_early = %d\n",
           c->crash_root_path,
           c->extra_script,
           report_type_to_str(c->report_type),
@@ -280,7 +283,8 @@ static void config_dump(config_t *c)
           c->dump_core,
           c->dump_so_info,
           c->allow_zip,
-          c->legacy_notification);
+          c->legacy_notification,
+          c->release_early);
 }
 
 bool config_init(config_t *c, const char *const path)
index 00b71b7..a50c437 100644 (file)
@@ -29,6 +29,7 @@
 #define DUMP_SO_INFO         1
 #define ALLOW_ZIP            1
 #define LEGACY_NOTIFICATION  0
+#define RELEASE_EARLY        0
 
 #define CRASH_SECTION        "CrashManager"
 #define EXCLUDEPATHS_SECTION  "ExcludePaths"
@@ -45,6 +46,7 @@ typedef struct config {
        bool dump_core;
        bool dump_so_info;
        bool legacy_notification;
+       bool release_early;
        enum ReportType report_type;
        int system_max_use;
        int system_keep_free;