Add timeout to the zip command 43/188143/4
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 31 Aug 2018 13:40:54 +0000 (15:40 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 5 Sep 2018 07:32:14 +0000 (09:32 +0200)
Change-Id: I52db6f8ccd1a2103da030c10898ec33c4a9bcc57

src/crash-manager/crash-manager.c

index 4c760bf..8add845 100644 (file)
@@ -75,6 +75,7 @@
 
 #define MINICOREDUMPER_TIMEOUT 12*60
 #define CRASH_STACK_TIMEOUT 12*60
+#define ZIP_TIMEOUT 12*60
 #define TEMP_MAPS_FILENAME   "maps.temp"
 
 enum {
@@ -1130,7 +1131,7 @@ static void compress(struct crash_info *cinfo)
 {
        int ret, lock_fd;
        char zip_path[PATH_MAX];
-       char command[PATH_MAX];
+       char cwd[PATH_MAX];
 
        ret = snprintf(zip_path, sizeof(zip_path), "%s/report.zip",
                        cinfo->temp_dir);
@@ -1139,13 +1140,31 @@ static void compress(struct crash_info *cinfo)
                return;
        }
 
-       ret = snprintf(command, sizeof(command), "cd %s && /bin/zip -y -r %s %s > /dev/null 2>&1",
-                       cinfo->temp_dir, zip_path, cinfo->name);
-       if (ret < 0) {
-               _E("Failed to snprintf for zip command");
+       if (getcwd(cwd, sizeof(cwd)) == NULL) {
+               _E("getcwd() error: %m\n");
+               return;
+       }
+
+       if (chdir(cinfo->temp_dir) == -1) {
+               _E("chdir() to %s error: %m\n", cinfo->temp_dir);
+               return;
+       }
+
+       char *args[] = {
+               "/bin/zip",
+               "-y",
+               "-r",
+               zip_path,
+               cinfo->name,
+               NULL
+       };
+
+       run_command_timeout(args[0], args, NULL, ZIP_TIMEOUT);
+
+       if (chdir(cwd) == -1) {
+               _E("chdir() to %s error: %m\n", cwd);
                return;
        }
-       system_command(command);
 
        if ((lock_fd = lock_dumpdir()) < 0)
                return;