#define APP_PATH_SUBDIR "/app/"
#define WAIT_FOR_OPT_TIMEOUT_SEC 60
+#define SPACE_REQUIRED_KB 1024
#define MINICOREDUMPER_TIMEOUT_MS DEFAULT_COMMAND_TIMEOUT_MS
#define LIVEDUMPER_TIMEOUT_MS DEFAULT_COMMAND_TIMEOUT_MS
return false;
}
+static int check_disk_available(const char *path, int check_size)
+{
+ struct statfs lstatfs;
+
+ if (!path)
+ return false;
+
+ if (statfs(path, &lstatfs) < 0) {
+ _E("Error when checking free space (%d): %m", errno);
+ return false;
+ }
+ int avail_size = (int)(lstatfs.f_bavail * (lstatfs.f_bsize / 1024));
+
+ if (check_size > avail_size) {
+ _E("Available disk space (%d) is less than (%d)", avail_size, check_size);
+ return false;
+ }
+
+ return true;
+}
+
static int prepare_paths(struct crash_info* cinfo)
{
int tmp_len;
if (mkdir(dst_dirname, 0775) < 0 && errno != EEXIST) {
_E("Failed to mkdir %s: %m", dst_dirname);
+ (void)check_disk_available(cinfo->pfx, SPACE_REQUIRED_KB);
goto out;
}
- if (copy_file(dst_filepath, src_filepath))
+ if (copy_file(dst_filepath, src_filepath)) {
_E("Cannot copy %s file to: %s", src_filepath, dst_filepath);
+ (void)check_disk_available(cinfo->app_root_path, SPACE_REQUIRED_KB);
+ }
else
is_ok = true;
out:
}
if (mkdir(dst_dirpath, 0775) < 0 && errno != EEXIST) {
_E("Failed to mkdir %s (%m)", dst_dirpath);
+ (void)check_disk_available(cinfo->pfx, SPACE_REQUIRED_KB);
goto out;
}
if (snprintf(maps_path, sizeof(maps_path), "/proc/%d/maps", cinfo->pid_info) <= 0) {
continue;
}
if (file_exists(src_filepath)) {
- if (copy_file(dst_filepath, src_filepath))
+ if (copy_file(dst_filepath, src_filepath)) {
_E("Cannot copy file from %s to: %s", src_filepath, dst_filepath);
+ (void)check_disk_available(dst_dirpath, SPACE_REQUIRED_KB);
+ }
+
}
free(src_filepath);
}
return false;
if (!execute_livedumper(cinfo, &exit_code) || exit_code != 0) {
_E("Failed to run livedumper - can not continue");
+ (void)check_disk_available(cinfo->pfx, SPACE_REQUIRED_KB);
process_continue(cinfo->pid_info);
return false;
}
_I("Starting the minicoredumper");
if (!execute_minicoredump(cinfo, &exit_code) || exit_code != 0) {
_E("Failed to run minicoredumper - can not continue");
+ (void)check_disk_available(cinfo->pfx, SPACE_REQUIRED_KB);
return false;
}
}
return dump_num;
}
-static int check_disk_available(const char *path, int check_size)
-{
- struct statfs lstatfs;
- int avail_size = 0;
-
- if (!path)
- return -1;
-
- if (statfs(path, &lstatfs) < 0)
- return -1;
- avail_size = (int)(lstatfs.f_bavail * (lstatfs.f_bsize / 1024));
-
- if (check_size > avail_size) {
- _I("avail_size is (%d)", avail_size);
- return -1;
- }
-
- return 0;
-}
-
static bool remove_file_info(struct file_info file)
{
if (file.isdir)
/* Check disk free space to keep */
if (config.system_keep_free &&
- check_disk_available(config.crash_root_path,
- config.system_keep_free) < 0) {
+ !check_disk_available(config.crash_root_path,
+ config.system_keep_free)) {
_I("Disk is not available! so set the maximum number of dump to 1");
config.max_crash_dump = 1;
}
clean_dump();
else {
_E("Failed to move %s to %s", from_path, cinfo->result_path);
+ (void)check_disk_available(crash_dump_path, SPACE_REQUIRED_KB);
is_ok = false;
}
unlock_dir(lock_fd);
{
unsigned int count = 0;
- while (check_disk_available(config.crash_root_path, 0) < 0 && count < timeout) {
+ while (!check_disk_available(config.crash_root_path, 0) && count < timeout) {
log_kmsg("crash-manager: path %s is not available\n", config.crash_root_path);
sleep(1);
count++;