Add checking if CRASH_ROOT_PATH exists 18/183918/4
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 14 Jun 2018 11:18:22 +0000 (13:18 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 19 Jul 2018 09:58:14 +0000 (11:58 +0200)
When system booting, /opt may not be mounted yet. In this case if any
program will crash, the crash-manager will wait about 60 seconds for
/opt. After this time the the crash report will be lost.

Change-Id: I97e9541262d1a0f9844aa260ac23972f70e27638

src/crash-manager/crash-manager.c
src/crash-manager/crash-manager.h.in
src/shared/util.c
src/shared/util.h

index 172327c..0ec94e6 100644 (file)
@@ -62,6 +62,7 @@
 #define ALLOW_ZIP            true
 
 #define CRASH_CHECK_DISK_PATH "/opt/usr"
+#define WAIT_FOR_OPT_TIMEOUT_SEC 60
 
 #define MINICOREDUMPER_TIMEOUT 12*60
 
@@ -852,6 +853,24 @@ static void move_dump_dir(void)
                _E("Failed to delete temp directory");
 }
 
+static int wait_for_opt(unsigned int timeout)
+{
+       unsigned int count = 0;
+
+       while (check_disk_available(CRASH_ROOT_PATH, 0) < 0 && count < timeout) {
+               log_kmsg("crash-manager: path %s is not available\n", CRASH_ROOT_PATH);
+               sleep(1);
+               count++;
+       }
+       if (count >= timeout) {
+               log_kmsg("crash-manager: timeout (%ds) while waiting for %s."
+                       "Probably /opt is not mounted.\n", timeout, CRASH_ROOT_PATH);
+               return 0;
+       }
+
+       return 1;
+}
+
 int main(int argc, char *argv[])
 {
        /* Execute dump_systemstate in parallel */
@@ -866,8 +885,10 @@ int main(int argc, char *argv[])
         * value that prevents from running crash-manager recursively.
         */
 
-       /* Get Configuration */
+       if (!wait_for_opt(WAIT_FOR_OPT_TIMEOUT_SEC))
+               exit(EXIT_FAILURE);
 
+       /* Get Configuration */
        get_config();
 
        /* Create crash directories */
index 84c9775..9206737 100644 (file)
@@ -21,6 +21,7 @@
 
 /* Make build variables to string */
 #define CRASH_PATH       "@CRASH_PATH@"
+#define CRASH_ROOT_PATH  "@CRASH_ROOT_PATH@"
 #define CRASH_TEMP       "@CRASH_TEMP@"
 #define SYS_ASSERT       "@SYS_ASSERT@"
 #ifdef TIZEN_FEATURE_PTRACE_CALLSTACK
index 084a57c..8d8bcc4 100644 (file)
@@ -713,6 +713,28 @@ int validate_file_name(char *name, int len)
 
        return 0;
 }
+
+int log_kmsg(char *fmt, ...)
+{
+       int result = 1;
+       va_list ap;
+       FILE *file;
+
+       file = fopen("/dev/kmsg", "w");
+       if (file == NULL) {
+               _E("Open /dev/kmsg error: %m");
+               return 0;
+       }
+
+       va_start(ap, fmt);
+       if (vfprintf(file, fmt, ap) < 0) {
+               _E("Write to /dev/kmsg error: %m");
+               result = 0;
+       }
+       va_end(ap);
+       fclose(file);
+       return result;
+}
 /**
  * @}
  */
index eb34a6b..a4044e2 100644 (file)
@@ -58,6 +58,8 @@ int get_directory_usage(char *path);
 int validate_env_name(char *name, int len);
 
 int validate_file_name(char *name, int len);
+
+int log_kmsg(char *fmt, ...);
 /**
  * @}
  */