#include <gio/gio.h>
#include <iniparser.h>
#include <tzplatform_config.h>
-#include <dlog.h>
#include "crash-manager.h"
+#include "shared/log.h"
#include "shared/util.h"
#undef LOG_TAG
ini = iniparser_load(CRASH_CONF_FILE);
if (!ini) {
- LOGE("Failed to load conf file");
+ _E("Failed to load conf file");
return;
}
snprintf(key, sizeof(key), "%s:%s", CRASH_SECTION, "SystemMaxUse");
value = iniparser_getint(ini, key, -1);
if (value < 0) {
- LOGD("Invalid value for SystemMaxUse. Use default value [ %d kbyte]",
+ _D("Invalid value for SystemMaxUse. Use default value [ %d kbyte]",
SYSTEM_MAX_USE);
} else {
- LOGD("SystemMaxUse [ %d kbyte]", value);
+ _D("SystemMaxUse [ %d kbyte]", value);
system_max_use = value;
}
snprintf(key, sizeof(key), "%s:%s", CRASH_SECTION, "SystemKeepFree");
value = iniparser_getint(ini, key, -1);
if (value < 0) {
- LOGD("Invalid value for SystemKeepFree. Use default value [ %d kbyte]",
+ _D("Invalid value for SystemKeepFree. Use default value [ %d kbyte]",
SYSTEM_KEEP_FREE);
} else {
- LOGD("SystemKeepFree [ %d kbyte]", value);
+ _D("SystemKeepFree [ %d kbyte]", value);
system_keep_free = value;
}
snprintf(key, sizeof(key), "%s:%s", CRASH_SECTION, "MaxRetentionSec");
value = iniparser_getint(ini, key, -1);
if (value < 0) {
- LOGD("Invalid value for MaxRetentionSec. Use default value [ %d ]",
+ _D("Invalid value for MaxRetentionSec. Use default value [ %d ]",
MAX_RETENTION_SEC);
} else {
- LOGD("MaxRetentionSec [ %d ]", value);
+ _D("MaxRetentionSec [ %d ]", value);
max_retention_sec = value;
}
snprintf(key, sizeof(key), "%s:%s", CRASH_SECTION, "MaxCrashDump");
value = iniparser_getint(ini, key, -1);
if (value < 0) {
- LOGD("Invalid value for MaxCrashDump. Use default value [ %d ]",
+ _D("Invalid value for MaxCrashDump. Use default value [ %d ]",
MAX_CRASH_DUMP);
} else {
- LOGD("MaxCrashDump [ %d ]", value);
+ _D("MaxCrashDump [ %d ]", value);
max_crash_dump = value;
}
snprintf(key, sizeof(key), "%s:%s", CRASH_SECTION, "AllowZip");
value = iniparser_getboolean(ini, key, -1);
if (value < 0) {
- LOGD("Invalid value for AllowZip. Use default value [ %s ]",
+ _D("Invalid value for AllowZip. Use default value [ %s ]",
ALLOW_ZIP ? "true" : "false" );
} else {
- LOGD("AllowZip [ %s ]", value ? "true" : "false");
+ _D("AllowZip [ %s ]", value ? "true" : "false");
allow_zip = value;
}
if (!stat(CRASH_PATH, &st)) {
if (!(st.st_mode & S_IFDIR)) {
- LOGE("%s (not DIR) is already exist", CRASH_PATH);
+ _E("%s (not DIR) is already exist", CRASH_PATH);
return -1;
}
} else {
if (mkdir(CRASH_PATH, 0775) < 0) {
- LOGE("Failed to mkdir for %s", CRASH_PATH);
+ _E("Failed to mkdir for %s", CRASH_PATH);
return -1;
}
smack_setlabel(CRASH_PATH, "System::Shared",
if (!stat(CRASH_TEMP, &st)) {
if (!(st.st_mode & S_IFDIR)) {
- LOGE("%s (not DIR) is already exist", CRASH_TEMP);
+ _E("%s (not DIR) is already exist", CRASH_TEMP);
return -1;
}
} else {
if (mkdir(CRASH_TEMP, 0775) < 0) {
- LOGE("Failed to mkdir for %s", CRASH_TEMP);
+ _E("Failed to mkdir for %s", CRASH_TEMP);
return -1;
}
smack_setlabel(CRASH_TEMP, "System::Shared",
ret = snprintf(crash_info.temp_dir, sizeof(crash_info.temp_dir),
"%s/crash.XXXXXX", CRASH_TEMP);
if (ret < 0) {
- LOGE("Failed to snprintf for temp_dir");
+ _E("Failed to snprintf for temp_dir");
return -1;
}
temp_dir_ret = mkdtemp(crash_info.temp_dir);
if (access(temp_dir_ret, F_OK)) {
- LOGE("Failed to mkdtemp for temp_dir");
+ _E("Failed to mkdtemp for temp_dir");
return -1;
}
crash_info.pid_info,
crash_info.time_info);
if (ret < 0) {
- LOGE("Failed to snprintf for name");
+ _E("Failed to snprintf for name");
goto rm_temp;
}
sizeof(crash_info.result_path),
"%s/%s", CRASH_PATH, crash_info.name);
if (ret < 0) {
- LOGE("Failed to snprintf for result path");
+ _E("Failed to snprintf for result path");
goto rm_temp;
}
ret = snprintf(crash_info.pfx, sizeof(crash_info.pfx), "%s/%s",
crash_info.temp_dir, crash_info.name);
if (ret < 0) {
- LOGE("Failed to snprintf for pfx");
+ _E("Failed to snprintf for pfx");
goto rm_temp;
}
ret = mkdir(crash_info.pfx, 0775);
if (ret < 0) {
- LOGE("Failed to mkdir for %s", crash_info.pfx);
+ _E("Failed to mkdir for %s", crash_info.pfx);
goto rm_temp;
}
ret = snprintf(crash_info.info_path, sizeof(crash_info.info_path),
"%s/%s.info", crash_info.pfx, crash_info.name);
if (ret < 0) {
- LOGE("Failed to snprintf for info path");
+ _E("Failed to snprintf for info path");
goto rm_temp;
}
ret = snprintf(crash_info.core_path, sizeof(crash_info.core_path),
"%s/%s.coredump", crash_info.pfx, crash_info.name);
if (ret < 0) {
- LOGE("Failed to snprintf for core path");
+ _E("Failed to snprintf for core path");
goto rm_temp;
}
ret = snprintf(crash_info.log_path, sizeof(crash_info.log_path),
"%s/%s.log", crash_info.pfx, crash_info.name);
if (ret < 0) {
- LOGE("Failed to snprintf for log path");
+ _E("Failed to snprintf for log path");
goto rm_temp;
}
"/tmp/crash_stack/%s_%s.info",
crash_info.cmd_info, crash_info.pid_info);
if (ret < 0) {
- LOGE("Failed to snprintf for sys-assert callstack path");
+ _E("Failed to snprintf for sys-assert callstack path");
goto rm_temp;
}
#endif
char move_path[PATH_MAX];
if (access(crash_info.sysassert_cs_path, F_OK)) {
- LOGE("The sys-assert cs file not found: %s",
+ _E("The sys-assert cs file not found: %s",
crash_info.sysassert_cs_path);
return -1;
}
ret = snprintf(move_path, sizeof(move_path), "%s/%s",
crash_info.pfx, basename(crash_info.sysassert_cs_path));
if (ret < 0) {
- LOGE("Failed to snprintf for move path");
+ _E("Failed to snprintf for move path");
return -1;
}
if (move_file(crash_info.sysassert_cs_path, move_path) < 0) {
- LOGE("Failed to move %s to %s",
+ _E("Failed to move %s to %s",
crash_info.sysassert_cs_path, move_path);
return -1;
}
char exepath[PATH_MAX] = "\0";
if (convert_path(exepath, core_exepath) <= 0) {
- LOGE("Failed to parsing exepath");
+ _E("Failed to parsing exepath");
return;
}
conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (error) {
- LOGE("Failed to get dbus: %s", error->message);
+ _E("Failed to get dbus: %s", error->message);
g_error_free(error);
return;
}
NULL,
&error);
if (error) {
- LOGE("Failed to get reply: %s", error->message);
+ _E("Failed to get reply: %s", error->message);
g_error_free(error);
goto exit;
}
g_variant_get(reply, "(i)", &ret);
- LOGI("Crash_popup is launched: (%d)", ret);
+ _I("Crash_popup is launched: (%d)", ret);
exit:
if (reply)
"/usr/bin/dump_systemstate -d -k -f %s",
crash_info.log_path);
if (ret < 0) {
- LOGE("Failed to snprintf for dump_systemstate command");
+ _E("Failed to snprintf for dump_systemstate command");
return;
}
system_command(command);
arg_append,
crash_info.info_path);
if (ret < 0) {
- LOGE("Failed to snprintf for crash-pipe command");
+ _E("Failed to snprintf for crash-pipe command");
return;
}
system_command(command);
CRASH_STACK_PATH,
crash_info.pid_info, crash_info.info_path);
if (ret < 0) {
- LOGE("Failed to snprintf for crash-stack command");
+ _E("Failed to snprintf for crash-stack command");
return;
}
system_command(command);
while ((fd = open(LOCK_FILE, O_CREAT | O_EXCL, 0644)) < 0) {
if (stat(LOCK_FILE, &st) < 0) {
- LOGE("Failed to stat lock file");
+ _E("Failed to stat lock file");
return;
}
cur_time = time(NULL);
if (st.st_mtime + LOCK_FILE_VALIDITY < cur_time) {
- LOGI("Lock file validity over");
+ _I("Lock file validity over");
if (unlink(LOCK_FILE) < 0)
- LOGE("Failed to unlink %s", LOCK_FILE);
+ _E("Failed to unlink %s", LOCK_FILE);
return;
}
sleep(LOCK_FILE_VALIDITY / 2);
static void dump_unlock(void)
{
if (unlink(LOCK_FILE) < 0)
- LOGE("Failed to unlink %s", LOCK_FILE);
+ _E("Failed to unlink %s", LOCK_FILE);
}
static void compress(void)
ret = snprintf(zip_path, sizeof(zip_path), "%s/report.zip",
crash_info.temp_dir);
if (ret < 0) {
- LOGE("Failed to snprintf for zip path");
+ _E("Failed to snprintf for zip path");
return;
}
ret = snprintf(command, sizeof(command), "cd %s && /bin/zip -r %s %s > /dev/null 2>&1",
crash_info.temp_dir, zip_path, crash_info.name);
if (ret < 0) {
- LOGE("Failed to snprintf for zip command");
+ _E("Failed to snprintf for zip command");
return;
}
system_command(command);
dump_lock();
if (rename(zip_path, crash_info.result_path) < 0)
- LOGE("Failed to move %s to %s",
- zip_path, crash_info.result_path);
+ _E("Failed to move %s to %s", zip_path, crash_info.result_path);
dump_unlock();
ret = remove_dir(crash_info.temp_dir, 1);
if (ret < 0)
- LOGE("Failed to delete temp directory");
+ _E("Failed to delete temp directory");
}
static void move_dump_dir(void)
ret = rename(crash_info.pfx, crash_info.result_path);
dump_unlock();
if (ret < 0) {
- LOGE("Failed to move %s to %s",
+ _E("Failed to move %s to %s",
crash_info.pfx, crash_info.result_path);
return;
}
ret = remove_dir(crash_info.temp_dir, 1);
if (ret < 0)
- LOGE("Failed to delete temp directory");
+ _E("Failed to delete temp directory");
}
static int dump_filter(const struct dirent *de)
int fd;
if ((fd = open(CRASH_PATH, O_DIRECTORY)) < 0 ) {
- LOGE("Failed to open %s", CRASH_PATH);
+ _E("Failed to open %s", CRASH_PATH);
return -1;
}
temp_list = (struct file_info *)calloc(scan_num,
sizeof(struct file_info));
if (!temp_list) {
- LOGE("Failed to calloc for dump list");
+ _E("Failed to calloc for dump list");
goto exit;
}
for (i = 0; i < scan_num; i++) {
if (fstatat(fd, scan_list[i]->d_name, &st, 0) < 0) {
- LOGE("Failed to fstatat");
+ _E("Failed to fstatat");
continue;
}
if (asprintf(&(temp_list[dump_num].path), "%s/%s",
CRASH_PATH, scan_list[i]->d_name) < 0) {
- LOGE("Failed to asprintf");
+ _E("Failed to asprintf");
continue;
}
qsort(temp_list, dump_num, sizeof(struct file_info), mtime_cmp);
for (i = 0; i < dump_num; i++)
- LOGD("[%d] path: %s(%s), size: %d kb, mtime: %s",
+ _D("[%d] path: %s(%s), size: %d kb, mtime: %s",
i,
temp_list[i].path,
temp_list[i].isdir ? "DIR" : "FILE",
avail_size = (int)(lstatfs.f_bavail * (lstatfs.f_bsize / 1024));
if (check_size > avail_size) {
- LOGI("avail_size is (%d)", avail_size);
+ _I("avail_size is (%d)", avail_size);
return -1;
}
dump_list[i].mtime > 0 &&
dump_list[i].mtime + max_retention_sec < cur_time) {
if (remove_file(dump_list[i]) < 0) {
- LOGE("Failed to remove %s", dump_list[i].path);
+ _E("Failed to remove %s", dump_list[i].path);
continue;
}
- LOGI("Reached the maximum retention time %d, so remove (%s)",
+ _I("Reached the maximum retention time %d, so remove (%s)",
max_retention_sec, dump_list[i].path);
dump_num--;
next = i + 1;
0 < dump_num && max_crash_dump < dump_num) {
for (i = next; i < scan_num; i++) {
if (remove_file(dump_list[i]) < 0) {
- LOGE("Failed to remove %s", dump_list[i].path);
+ _E("Failed to remove %s", dump_list[i].path);
continue;
}
- LOGI("Reached the maximum number of dump %d/%d, so remove (%s)",
+ _I("Reached the maximum number of dump %d/%d, so remove (%s)",
dump_num, max_crash_dump,
dump_list[i].path);
dump_num--;
0 < dump_num && system_max_use < usage / 1024) {
for (i = next; i < scan_num; i++) {
if (remove_file(dump_list[i]) < 0) {
- LOGE("Failed to remove %s", dump_list[i].path);
+ _E("Failed to remove %s", dump_list[i].path);
dump_num--;
continue;
}
- LOGI("Reached the maximum disk usage %d/%d kb, so remove (%s)",
+ _I("Reached the maximum disk usage %d/%d kb, so remove (%s)",
usage / 1024, system_max_use,
dump_list[i].path);
dump_num--;
if (system_keep_free &&
check_disk_available(CRASH_CHECK_DISK_PATH,
system_keep_free) < 0) {
- LOGI("Disk is not available! so set the maximum number of dump to 1");
+ _I("Disk is not available! so set the maximum number of dump to 1");
max_crash_dump = 1;
}
static int timeout_cb(gpointer data)
{
- LOGI("Time out!");
+ _I("Time out!");
g_main_loop_quit((GMainLoop *)data);
return 0;
timeout_id = g_timeout_add_seconds(TIMEOUT_INTERVAL, timeout_cb, loop);
g_mutex_unlock(&timeout_mutex);
- LOGI("Add loop timeout (%d)", TIMEOUT_INTERVAL);
+ _I("Add loop timeout (%d)", TIMEOUT_INTERVAL);
}
static void remove_timeout(void)
}
g_mutex_unlock(&timeout_mutex);
- LOGI("Remove loop timeout");
+ _I("Remove loop timeout");
}
static void method_call_handler(GDBusConnection *conn,
else if (g_strcmp0(arg, "short") == 0)
ret = log_dump(OPT_SHORT);
else
- LOGE("Wrong option for log_dump");
+ _E("Wrong option for log_dump");
} else if (g_strcmp0(method_name, "delete_dump") == 0) {
ret = delete_dump();
}
CRASH_OBJECT_PATH, introspection_data->interfaces[0],
&interface_vtable, NULL, NULL, NULL);
if (registration_id == 0)
- LOGE("Failed to g_dbus_connection_register_object");
+ _E("Failed to g_dbus_connection_register_object");
}
static void on_name_acquired(GDBusConnection *conn,
const gchar *name,
gpointer user_data)
{
- LOGD("Acquired the name %s on the system bus", name);
+ _D("Acquired the name %s on the system bus", name);
}
static void on_name_lost(GDBusConnection *conn,
const gchar *name,
gpointer user_data)
{
- LOGD("Lost the name %s on the system bus", name);
+ _D("Lost the name %s on the system bus", name);
}
static void dbus_init(void)
introspection_data =
g_dbus_node_info_new_for_xml(introspection_xml, NULL);
if (introspection_data == NULL) {
- LOGE("Failed to init g_dbus_info_new_for_xml");
+ _E("Failed to init g_dbus_info_new_for_xml");
return;
}
conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!conn) {
- LOGE("Failed to get dbus");
+ _E("Failed to get dbus");
return;
}
if (error) {
- LOGE("Failed to get dbus: %s", error->message);
+ _E("Failed to get dbus: %s", error->message);
g_error_free(error);
return;
}
g_mutex_init(&timeout_mutex);
add_timeout();
- LOGI("log_dump_dbus activated");
+ _I("log_dump_dbus activated");
g_main_loop_run(loop);
if (introspection_data)
GDBusConnection *conn;
GError *error = NULL;
- LOGI("broadcast signal: %s", signal);
+ _I("broadcast signal: %s", signal);
conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (error) {
- LOGE("Failed to get dbus: %s", error->message);
+ _E("Failed to get dbus: %s", error->message);
g_error_free(error);
return -1;
}
NULL,
&error);
if (error) {
- LOGE("Failed to emit signal: %s", error->message);
+ _E("Failed to emit signal: %s", error->message);
g_error_free(error);
return -1;
}
script_num = scandir(DUMP_SCRIPTS_DIR, &dir_list, NULL, NULL);
if (script_num < 0) {
- LOGE("Failed to scandir %s",DUMP_SCRIPTS_DIR);
+ _E("Failed to scandir %s",DUMP_SCRIPTS_DIR);
return -1;
}
snprintf(command, sizeof(command), "%s/%s %s",
DUMP_SCRIPTS_DIR, dir_list[i]->d_name,
LOG_DUMP_DIR);
- LOGD("%s", command);
+ _D("%s", command);
system_command(command);
}
ret = snprintf(command, sizeof(command),
"/usr/bin/mkdir -p %s", LOG_DUMP_DIR);
if (ret < 0) {
- LOGE("Failed to mkdir");
+ _E("Failed to mkdir");
return -1;
}
system_command(command);
ret = snprintf(command, sizeof(command),
"/usr/bin/mkdir -p %s", LOG_DUMP_RESULT);
if (ret < 0) {
- LOGE("Failed to mkdir");
+ _E("Failed to mkdir");
return -1;
}
system_command(command);
ret = system_info_get_platform_string(SYSTEM_INFO_KEY_BUILD_STRING,
&version_str);
if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOGE("Failed to system_info_get_platform_string");
+ _E("Failed to system_info_get_platform_string");
version_str = NULL;
}
"/usr/bin/dump_systemstate -k -d -f "
"%s/dump_systemstate_%s.log", LOG_DUMP_DIR, timestr);
if (ret < 0) {
- LOGE("Failed to snprintf for command");
+ _E("Failed to snprintf for command");
goto exit;
}
system_command(command);
ret = snprintf(dump_filename, sizeof(dump_filename), "%s_%s",
"log_dump", version_str);
if (ret < 0) {
- LOGE("Failed to snprintf for dump path");
+ _E("Failed to snprintf for dump path");
goto exit;
}
} else {
ret = snprintf(dump_filename, sizeof(dump_filename), "%s",
"log_dump");
if (ret < 0) {
- LOGE("Failed to snprintf for dump path");
+ _E("Failed to snprintf for dump path");
return -1;
}
}
/* Compression */
dump_dirname = strdup(LOG_DUMP_DIR);
if (!dump_dirname) {
- LOGE("Failed to strdup for dump_dirname");
+ _E("Failed to strdup for dump_dirname");
goto exit;
}
if (option == OPT_NORMAL) {
crash_dirname = strdup(CRASH_DUMP_DIR);
if (!crash_dirname) {
- LOGE("Failed to strdup for dump_dirname");
+ _E("Failed to strdup for dump_dirname");
goto exit;
}
LOG_DUMP_RESULT, dump_filename, timestr,
basename(dump_dirname), basename(crash_dirname));
if (ret < 0) {
- LOGE("Failed to snprintf for command");
+ _E("Failed to snprintf for command");
goto exit;
}
} else {
LOG_DUMP_RESULT, dump_filename, timestr,
basename(dump_dirname));
if (ret < 0) {
- LOGE("Failed to snprintf for command");
+ _E("Failed to snprintf for command");
goto exit;
}
}
/* Remove gatherd dump */
ret = remove_dir(LOG_DUMP_DIR, 0);
if (ret < 0) {
- LOGE("Failed to delete dump directory");
+ _E("Failed to delete dump directory");
goto exit;
}
if (option == OPT_NORMAL) {
ret = remove_dir(CRASH_DUMP_DIR, 0);
if (ret < 0) {
- LOGE("Failed to delete crash dump directory");
+ _E("Failed to delete crash dump directory");
goto exit;
}
}
int delete_dump(void)
{
- LOGI("delete_dump!");
+ _I("delete_dump!");
remove_dir(LOG_DUMP_DIR, 0);
remove_dir(LOG_DUMP_RESULT, 1);