Move unlocking and removing of the temp dir to a separate function 37/230837/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 14 Apr 2020 09:55:41 +0000 (11:55 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 15 Apr 2020 09:27:35 +0000 (11:27 +0200)
Change-Id: If38fcfda5737e8d39cb496692ca663e2a3d7c6a2

src/crash-manager/crash-manager.c

index 3ae4981..8a9ec5a 100644 (file)
@@ -1111,12 +1111,6 @@ static bool move_dump_data(const char *from_path, const struct crash_info *cinfo
                is_ok = false;
        }
        unlock_dir(lock_fd);
-       unlock_dir(cinfo->lock_fd);
-
-       if (remove_dir(cinfo->temp_dir, 1) < 0)
-               _E("Failed to delete temp directory");
-
-       clean_temp(crash_temp_path);
 
        return is_ok;
 }
@@ -1299,6 +1293,17 @@ static void write_dump_reason(const char *reason, const char *base_dir, const ch
        }
 }
 
+static void crash_manager_cleanup(struct crash_info *cinfo)
+{
+       assert(cinfo);
+       unlock_dir(cinfo->lock_fd);
+
+       if (remove_dir(cinfo->temp_dir, 1) < 0)
+               _E("Failed to delete temp directory");
+
+       clean_temp(crash_temp_path);
+}
+
 void crash_manager_free(struct crash_info *cinfo)
 {
        if (cinfo->prstatus_fd >= 0)
@@ -1315,7 +1320,10 @@ bool crash_manager_direct(struct crash_info *cinfo)
        if (!crash_manager_prepare(cinfo))
                return false;
 
-       return run(cinfo);
+       bool result = run(cinfo);
+       crash_manager_cleanup(cinfo);
+
+       return result;
 }
 
 bool crash_manager_livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t report_path_len)
@@ -1332,7 +1340,10 @@ bool crash_manager_livedump_pid(pid_t pid, const char *dump_reason, char *report
 
        write_dump_reason(dump_reason, cinfo.pfx, cinfo.name);
 
-       if (!run(&cinfo))
+       result = run(&cinfo);
+       crash_manager_cleanup(&cinfo);
+
+       if (!result)
                goto exit;
 
        strncpy(report_path, cinfo.result_path, report_path_len);