[PATCH] SQLite3.cpp: replace std::vector by GList
by Nikola Pajkovsky
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
inc/abrtlib.h | 3 +
inc/database.h | 59 +++++++++++++++------
lib/plugins/Makefile.am | 4 +-
lib/plugins/SQLite3.cpp | 122 ++++++++++++++++++++++++------------------
lib/plugins/SQLite3.h | 5 +-
src/daemon/CrashWatcher.cpp | 24 ++++++---
src/daemon/MiddleWare.cpp | 94 +++++++++++++++++++++------------
7 files changed, 198 insertions(+), 113 deletions(-)
diff --git a/inc/abrtlib.h b/inc/abrtlib.h
index 2fc5101..a1ad9c3 100644
--- a/inc/abrtlib.h
+++ b/inc/abrtlib.h
@@ -64,6 +64,9 @@ int vdprintf(int d, const char *format, va_list ap);
#undef NORETURN
#define NORETURN __attribute__ ((noreturn))
+#undef ERR_PTR
+#define ERR_PTR ((void*)(uintptr_t)1)
+
#undef ARRAY_SIZE
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
diff --git a/inc/database.h b/inc/database.h
index df109bd..c197ddf 100644
--- a/inc/database.h
+++ b/inc/database.h
@@ -21,6 +21,7 @@
#ifndef DATABASE_H_
#define DATABASE_H_
+#include <glib.h>
#include <string>
#include <vector>
#include "plugin.h"
@@ -36,22 +37,48 @@
/**
* A struct contains one database row.
*/
-typedef struct database_row_t
+struct db_row
{
- std::string m_sUUID; /**< A local UUID.*/
- std::string m_sUID; /**< An UID of an user.*/
- std::string m_sInformAll;
- std::string m_sDebugDumpDir; /**< A debugdump directory of a crash.*/
- std::string m_sCount; /**< Crash rate.*/
- std::string m_sReported; /**< Is a row reported?*/
- std::string m_sMessage; /**< if a row is reported, then there can be store message abotu that*/
- std::string m_sTime; /**< Time of last occurred crash with same local UUID*/
-} database_row_t;
+ char *db_uuid; /**< A local UUID.*/
+ char *db_uid; /**< An UID of an user.*/
+ char *db_inform_all;
+ char *db_dump_dir; /**< A debugdump directory of a crash.*/
+ char *db_count; /**< Crash rate.*/
+ char *db_reported; /**< Is a row reported?*/
+ char *db_message; /**< if a row is reported, then there can be store message abotu that*/
+ char *db_time; /**< Time of last occurred crash with same local UUID*/
+};
-/**
- * A vector contains one or more database rows.
- */
-typedef std::vector<database_row_t> vector_database_rows_t;
+static inline void db_row_free(struct db_row *row)
+{
+ if (!row)
+ return;
+
+ free(row->db_uuid);
+ free(row->db_uid);
+ free(row->db_inform_all);
+ free(row->db_dump_dir);
+ free(row->db_count);
+ free(row->db_reported);
+ free(row->db_message);
+ free(row->db_time);
+
+ free(row);
+}
+
+static inline void db_list_free(GList *list)
+{
+ if (!list)
+ return;
+
+ struct db_row *row = NULL;
+ for (GList *li = list; li != NULL; li = g_list_next(li))
+ {
+ row = (struct db_row*)li->data;
+ db_row_free(row);
+ }
+ g_list_free(list);
+}
/**
* An abstract class. The class defines a database plugin interface.
@@ -104,7 +131,7 @@ class CDatabase : public CPlugin
* @param pUID An UID of an user.
* @return A vector of matched rows.
*/
- virtual vector_database_rows_t GetUIDData(long caller_uid) = 0;
+ virtual GList *GetUIDData(long caller_uid) = 0;
/**
* A method, which returns one row accordind to UUID of a crash and
* UID of an user. If there are no row, empty row is returned.
@@ -112,7 +139,7 @@ class CDatabase : public CPlugin
* @param pUID An UID of an user.
* @return A matched row.
*/
- virtual database_row_t GetRow(const char *crash_id) = 0;
+ virtual struct db_row *GetRow(const char *crash_id) = 0;
};
#endif
diff --git a/lib/plugins/Makefile.am b/lib/plugins/Makefile.am
index a896e14..ca874e1 100644
--- a/lib/plugins/Makefile.am
+++ b/lib/plugins/Makefile.am
@@ -98,8 +98,8 @@ libMailx_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) -DPLUGINS_LIB_DIR=\"$(PLUGI
# SQLite3
libSQLite3_la_SOURCES = SQLite3.cpp SQLite3.h
libSQLite3_la_LDFLAGS = -avoid-version
-libSQLite3_la_LIBADD = $(SQLITE3_LIBS)
-libSQLite3_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) $(SQLITE3_CFLAGS) -DLOCALSTATEDIR='"$(localstatedir)"'
+libSQLite3_la_LIBADD = $(SQLITE3_LIBS) $(GLIB_LIBS)
+libSQLite3_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) $(SQLITE3_CFLAGS) -DLOCALSTATEDIR='"$(localstatedir)"' $(GLIB_CFLAGS)
# Logger
libLogger_la_SOURCES = Logger.cpp Logger.h
diff --git a/lib/plugins/SQLite3.cpp b/lib/plugins/SQLite3.cpp
index 322f15a..3cd9f7d 100644
--- a/lib/plugins/SQLite3.cpp
+++ b/lib/plugins/SQLite3.cpp
@@ -103,13 +103,9 @@ static string sql_escape(const char *str)
/* Note:
* expects "SELECT * FROM ...", not "SELECT <only some fields> FROM ..."
*/
-static void get_table(vector_database_rows_t& pTable,
- sqlite3 *db, const char *fmt, ...)
+static GList *vget_table(sqlite3 *db, const char *fmt, va_list p)
{
- va_list p;
- va_start(p, fmt);
char *sql = xvasprintf(fmt, p);
- va_end(p);
char **table;
int ncol, nrow;
@@ -117,39 +113,54 @@ static void get_table(vector_database_rows_t& pTable,
int ret = sqlite3_get_table(db, sql, &table, &nrow, &ncol, &err);
if (ret != SQLITE_OK)
{
- string errstr = ssprintf("Error in SQL:'%s' error: %s", sql, err);
+ error_msg("Error in SQL:'%s' error: %s", sql, err);
free(sql);
sqlite3_free(err);
- throw CABRTException(EXCEP_PLUGIN, errstr.c_str());
+ return (GList*)ERR_PTR;
}
- VERB2 log("%d rows returned by SQL:%s", nrow, sql);
+ VERB2 log("%s: %d rows returned by SQL:%s", __func__, nrow, sql);
free(sql);
- pTable.clear();
+ GList *rows = NULL;
int ii;
for (ii = 0; ii < nrow; ii++)
{
int jj;
- database_row_t row;
+ struct db_row *row = (struct db_row*)xzalloc(sizeof(struct db_row));
for (jj = 0; jj < ncol; jj++)
{
char *val = table[jj + (ncol*ii) + ncol];
switch (jj)
{
- case 0: row.m_sUUID = val; break;
- case 1: row.m_sUID = val; break;
- case 2: row.m_sInformAll = val; break;
- case 3: row.m_sDebugDumpDir = val; break;
- case 4: row.m_sCount = val; break;
- case 5: row.m_sReported = val; break;
- case 6: row.m_sTime = val; break;
- case 7: row.m_sMessage = val; break;
+ case 0: row->db_uuid = xstrdup(val); break;
+ case 1: row->db_uid = xstrdup(val); break;
+ case 2: row->db_inform_all = xstrdup(val); break;
+ case 3: row->db_dump_dir = xstrdup(val); break;
+ case 4: row->db_count = xstrdup(val); break;
+ case 5: row->db_reported = xstrdup(val); break;
+ case 6: row->db_time = xstrdup(val); break;
+ case 7: row->db_message = xstrdup(val); break;
}
}
- pTable.push_back(row);
+ rows = g_list_append(rows, row);
}
sqlite3_free_table(table);
+
+ return rows;
+}
+
+static GList *get_table_or_die(sqlite3 *db, const char *fmt, ...)
+{
+ va_list p;
+ va_start(p, fmt);
+ GList *table = vget_table(db, fmt, p);
+ va_end(p);
+
+ if (table == (GList*)ERR_PTR)
+ xfunc_die();
+
+ return table;
}
static int execute_sql(sqlite3 *db, const char *fmt, ...)
@@ -177,13 +188,17 @@ static int execute_sql(sqlite3 *db, const char *fmt, ...)
static bool exists_uuid_uid(sqlite3 *db, const char *UUID, const char *UID)
{
- vector_database_rows_t table;
- get_table(table, db,
- "SELECT * FROM "ABRT_TABLE
- " WHERE "COL_UUID"='%s' AND "COL_UID"='%s';",
- UUID, UID
+ GList *table = get_table_or_die(db, "SELECT * FROM "ABRT_TABLE
+ " WHERE "COL_UUID"='%s' AND "COL_UID"='%s';",
+ UUID, UID
);
- return !table.empty();
+
+ if (!table)
+ return false;
+
+ db_list_free(table);
+
+ return true;
}
static void update_from_old_ver(sqlite3 *db, int old_version)
@@ -496,27 +511,26 @@ void CSQLite3::DeleteRows_by_dir(const char *dump_dir)
}
/* Get UID:UUID pair(s) to delete */
- vector_database_rows_t table;
- get_table(table, m_pDB,
- "SELECT * FROM "ABRT_TABLE
- " WHERE "COL_DEBUG_DUMP_PATH"='%s';",
- dump_dir
+ GList *table = get_table_or_die(m_pDB, "SELECT * FROM "ABRT_TABLE
+ " WHERE "COL_DEBUG_DUMP_PATH"='%s';",
+ dump_dir
);
- if (table.empty())
+
+ if (!table)
{
return;
}
+ struct db_row *row = NULL;
/* Delete from both tables */
- vector_database_rows_t::iterator it = table.begin();
- while (it != table.end())
+ for (GList *li = table; li != NULL; li = g_list_next(li))
{
+ row = (struct db_row*)li->data;
execute_sql(m_pDB,
"DELETE FROM "ABRT_REPRESULT_TABLE
" WHERE "COL_UUID"='%s' AND "COL_UID"='%s';",
- it->m_sUUID.c_str(), it->m_sUID.c_str()
+ row->db_uuid, row->db_uid
);
- it++;
}
execute_sql(m_pDB,
"DELETE FROM "ABRT_TABLE
@@ -601,32 +615,31 @@ void CSQLite3::SetReportedPerReporter(const char *crash_id,
}
}
-vector_database_rows_t CSQLite3::GetUIDData(long caller_uid)
+GList *CSQLite3::GetUIDData(long caller_uid)
{
- vector_database_rows_t table;
+ GList *table = NULL;
if (caller_uid == 0)
{
- get_table(table, m_pDB, "SELECT * FROM "ABRT_TABLE";");
+ table = get_table_or_die(m_pDB, "SELECT * FROM "ABRT_TABLE";");
}
else
{
- get_table(table, m_pDB,
- "SELECT * FROM "ABRT_TABLE
- " WHERE "COL_UID"='%ld' OR "COL_INFORMALL"=1;",
- caller_uid
+ table = get_table_or_die(m_pDB, "SELECT * FROM "ABRT_TABLE
+ " WHERE "COL_UID"='%ld' OR "COL_INFORMALL"=1;",
+ caller_uid
);
}
return table;
}
-database_row_t CSQLite3::GetRow(const char *crash_id)
+struct db_row *CSQLite3::GetRow(const char *crash_id)
{
const char *UUID = strchr(crash_id, ':');
if (!UUID
|| !is_string_safe(crash_id)
) {
- return database_row_t();
+ return NULL;
}
/* Split crash_id into UID:UUID */
@@ -636,18 +649,23 @@ database_row_t CSQLite3::GetRow(const char *crash_id)
strncpy(UID, crash_id, uid_len);
UID[uid_len] = '\0';
- vector_database_rows_t table;
- get_table(table, m_pDB,
- "SELECT * FROM "ABRT_TABLE
- " WHERE "COL_UUID"='%s' AND "COL_UID"='%s';",
- UUID, UID
+ GList *table = get_table_or_die(m_pDB, "SELECT * FROM "ABRT_TABLE
+ " WHERE "COL_UUID"='%s' AND "COL_UID"='%s';",
+ UUID, UID
);
- if (table.size() == 0)
+ if (!table)
{
- return database_row_t();
+ return NULL;
}
- return table[0];
+
+ GList *first = g_list_first(table);
+ struct db_row *row = (struct db_row*)xzalloc(sizeof(struct db_row));
+ memcpy(row, first->data, sizeof(struct db_row));
+
+ db_list_free(table);
+
+ return row;
}
void CSQLite3::SetSettings(const map_plugin_settings_t& pSettings)
diff --git a/lib/plugins/SQLite3.h b/lib/plugins/SQLite3.h
index d2af864..3dfd0a9 100644
--- a/lib/plugins/SQLite3.h
+++ b/lib/plugins/SQLite3.h
@@ -47,10 +47,11 @@ class CSQLite3 : public CDatabase
virtual void SetReportedPerReporter(const char *crash_id,
const char *reporter,
const char *pMessage);
- virtual vector_database_rows_t GetUIDData(long caller_uid);
- virtual database_row_t GetRow(const char *crash_id);
+ virtual GList *GetUIDData(long caller_uid);
+ virtual struct db_row *GetRow(const char *crash_id);
virtual void SetSettings(const map_plugin_settings_t& pSettings);
};
+
#endif
diff --git a/src/daemon/CrashWatcher.cpp b/src/daemon/CrashWatcher.cpp
index 6310118..6e04628 100644
--- a/src/daemon/CrashWatcher.cpp
+++ b/src/daemon/CrashWatcher.cpp
@@ -188,27 +188,37 @@ int DeleteDebugDump(const char *crash_id, long caller_uid)
{
CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str());
database->Connect();
- database_row_t row = database->GetRow(crash_id);
- if (row.m_sUUID == "")
+ struct db_row *row = database->GetRow(crash_id);
+ if (!row)
+ return EIO;
+
+ if (!row->db_uuid)
{
database->DisConnect();
+ db_row_free(row);
return ENOENT;
}
+
+ char caller_uid_str[sizeof(long) * 3 + 2];
+ sprintf(caller_uid_str, "%li", caller_uid);
+
if (caller_uid != 0 /* not called by root */
- && row.m_sInformAll != "1"
- && to_string(caller_uid) != row.m_sUID
+ && row->db_inform_all[0] != '1'
+ && strcmp(caller_uid_str, row->db_uid) != 0
) {
database->DisConnect();
+ db_row_free(row);
return EPERM;
}
database->DeleteRow(crash_id);
database->DisConnect();
- const char *dump_dir = row.m_sDebugDumpDir.c_str();
- if (dump_dir[0] != '\0')
+ if (row->db_dump_dir[0] != '\0')
{
- delete_debug_dump_dir(dump_dir);
+ delete_debug_dump_dir(row->db_dump_dir);
+ db_row_free(row);
return 0; /* success */
}
+ db_row_free(row);
}
catch (CABRTException& e)
{
diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp
index 7752dc3..d97e10f 100644
--- a/src/daemon/MiddleWare.cpp
+++ b/src/daemon/MiddleWare.cpp
@@ -278,21 +278,27 @@ mw_result_t CreateCrashReport(const char *crash_id,
{
VERB2 log("CreateCrashReport('%s',%ld,result)", crash_id, caller_uid);
- database_row_t row;
CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str());
database->Connect();
- row = database->GetRow(crash_id);
+
+ struct db_row *row = database->GetRow(crash_id);
database->DisConnect();
- if (row.m_sUUID == "")
+ if (row && !row->db_uuid)
{
error_msg("crash '%s' is not in database", crash_id);
+ db_row_free(row);
return MW_IN_DB_ERROR;
}
+
+ char caller_uid_str[sizeof(long) * 3 + 2];
+ sprintf(caller_uid_str, "%li", caller_uid);
+
if (caller_uid != 0 /* not called by root */
- && row.m_sInformAll != "1"
- && to_string(caller_uid) != row.m_sUID
+ && row->db_inform_all[0] != '1'
+ && strcmp(caller_uid_str, row->db_uid) != 0
) {
error_msg("crash '%s' can't be accessed by user with uid %ld", crash_id, caller_uid);
+ db_row_free(row);
return MW_IN_DB_ERROR;
}
@@ -300,9 +306,10 @@ mw_result_t CreateCrashReport(const char *crash_id,
try
{
dump_dir_t *dd = dd_init();
- if (!dd_opendir(dd, row.m_sDebugDumpDir.c_str()))
+ if (!dd_opendir(dd, row->db_dump_dir))
{
dd_close(dd);
+ db_row_free(row);
return MW_ERROR;
}
@@ -319,24 +326,26 @@ mw_result_t CreateCrashReport(const char *crash_id,
// Why do we reload dump dir's data via DebugDumpToCrashReport?
VERB3 log(" run_analyser_CreateReport('%s')", analyzer.c_str());
- run_analyser_CreateReport(analyzer.c_str(), row.m_sDebugDumpDir.c_str(), force);
+ run_analyser_CreateReport(analyzer.c_str(), row->db_dump_dir, force);
- std::string dup_hash = GetGlobalUUID(analyzer.c_str(), row.m_sDebugDumpDir.c_str());
+ std::string dup_hash = GetGlobalUUID(analyzer.c_str(), row->db_dump_dir);
VERB3 log(" DUPHASH:'%s'", dup_hash.c_str());
- VERB3 log(" RunAnalyzerActions('%s','%s','%s',force=%d)", analyzer.c_str(), package_name, row.m_sDebugDumpDir.c_str(), force);
- RunAnalyzerActions(analyzer.c_str(), package_name, row.m_sDebugDumpDir.c_str(), force);
+ VERB3 log(" RunAnalyzerActions('%s','%s','%s',force=%d)", analyzer.c_str(), package_name, row->db_dump_dir, force);
+ RunAnalyzerActions(analyzer.c_str(), package_name, row->db_dump_dir, force);
free(package_name);
- if (DebugDumpToCrashReport(row.m_sDebugDumpDir.c_str(), pCrashData))
+ if (DebugDumpToCrashReport(row->db_dump_dir, pCrashData))
{
- add_to_crash_data_ext(pCrashData, CD_UUID , CD_SYS, CD_ISNOTEDITABLE, row.m_sUUID.c_str());
+ add_to_crash_data_ext(pCrashData, CD_UUID , CD_SYS, CD_ISNOTEDITABLE, row->db_uuid);
add_to_crash_data_ext(pCrashData, CD_DUPHASH, CD_TXT, CD_ISNOTEDITABLE, dup_hash.c_str());
}
else
{
+ db_row_free(row);
error_msg("Error loading crash data");
return MW_ERROR;
}
+ db_row_free(row);
}
catch (CABRTException& e)
{
@@ -611,20 +620,23 @@ static bool is_debug_dump_saved(long uid, const char *debug_dump_dir)
CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str());
database->Connect();
- vector_database_rows_t rows = database->GetUIDData(uid);
+ GList *table = database->GetUIDData(uid);
database->DisConnect();
- size_t ii;
bool found = false;
- for (ii = 0; ii < rows.size(); ii++)
+ struct db_row *row = NULL;
+ for (GList *li = table; li != NULL; li = g_list_next(li))
{
- if (0 == strcmp(rows[ii].m_sDebugDumpDir.c_str(), debug_dump_dir))
+ row = (struct db_row*)li->data;
+ if (0 == strcmp(row->db_dump_dir, debug_dump_dir))
{
found = true;
break;
}
}
+ db_list_free(table);
+
return found;
}
@@ -1012,24 +1024,28 @@ static mw_result_t SaveDebugDumpToDatabase(const char *crash_id,
database->Connect();
/* note: if [UUID,UID] record exists, pDebugDumpDir is not updated in the record */
database->Insert_or_Update(crash_id, inform_all_users, pDebugDumpDir, pTime);
- database_row_t row = database->GetRow(crash_id);
+
+ struct db_row *row = database->GetRow(crash_id);
database->DisConnect();
mw_result_t res = FillCrashInfo(crash_id, pCrashData);
if (res == MW_OK)
{
const char *first = get_crash_data_item_content(pCrashData, CD_DUMPDIR).c_str();
- if (row.m_sReported == "1")
+ if (row && row->db_reported[0] == '1')
{
log("Crash is in database already (dup of %s) and is reported", first);
+ db_row_free(row);
return MW_REPORTED;
}
- if (row.m_sCount != "1")
+ if (row && row->db_count[0] != '1')
{
+ db_row_free(row);
log("Crash is in database already (dup of %s)", first);
return MW_OCCURRED;
}
}
+ db_row_free(row);
return res;
}
@@ -1122,7 +1138,11 @@ mw_result_t FillCrashInfo(const char *crash_id,
{
CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str());
database->Connect();
- database_row_t row = database->GetRow(crash_id);
+
+ struct db_row *row = database->GetRow(crash_id);
+ if (!row)
+ return MW_ERROR;
+
database->DisConnect();
std::string package;
@@ -1131,23 +1151,26 @@ mw_result_t FillCrashInfo(const char *crash_id,
std::string analyzer;
dump_dir_t *dd = dd_init();
- if (!dd_opendir(dd, row.m_sDebugDumpDir.c_str()))
+ if (!dd_opendir(dd, row->db_dump_dir))
{
dd_close(dd);
+ db_row_free(row);
return MW_ERROR;
}
load_crash_data_from_debug_dump(dd, pCrashData);
dd_close(dd);
- add_to_crash_data(pCrashData, CD_UID , row.m_sUID.c_str() );
- add_to_crash_data(pCrashData, CD_UUID , row.m_sUUID.c_str() );
- add_to_crash_data(pCrashData, CD_INFORMALL , row.m_sInformAll.c_str() );
- add_to_crash_data(pCrashData, CD_COUNT , row.m_sCount.c_str() );
- add_to_crash_data(pCrashData, CD_REPORTED , row.m_sReported.c_str() );
- add_to_crash_data(pCrashData, CD_MESSAGE , row.m_sMessage.c_str() );
- add_to_crash_data(pCrashData, CD_DUMPDIR , row.m_sDebugDumpDir.c_str());
- add_to_crash_data(pCrashData, FILENAME_TIME , row.m_sTime.c_str() );
+ add_to_crash_data(pCrashData, CD_UID , row->db_uid );
+ add_to_crash_data(pCrashData, CD_UUID , row->db_uuid );
+ add_to_crash_data(pCrashData, CD_INFORMALL , row->db_inform_all );
+ add_to_crash_data(pCrashData, CD_COUNT , row->db_count );
+ add_to_crash_data(pCrashData, CD_REPORTED , row->db_reported );
+ add_to_crash_data(pCrashData, CD_MESSAGE , row->db_message );
+ add_to_crash_data(pCrashData, CD_DUMPDIR , row->db_dump_dir );
+ add_to_crash_data(pCrashData, FILENAME_TIME , row->db_time );
+
+ db_row_free(row);
return MW_OK;
}
@@ -1155,17 +1178,20 @@ mw_result_t FillCrashInfo(const char *crash_id,
void GetUUIDsOfCrash(long caller_uid, vector_string_t &result)
{
CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str());
- vector_database_rows_t rows;
database->Connect();
- rows = database->GetUIDData(caller_uid);
+ GList *rows = database->GetUIDData(caller_uid);
database->DisConnect();
- unsigned ii;
- for (ii = 0; ii < rows.size(); ii++)
+ struct db_row *row = NULL;
+ for (GList *li = rows; li != NULL; li = g_list_next(li))
{
- string crash_id = ssprintf("%s:%s", rows[ii].m_sUID.c_str(), rows[ii].m_sUUID.c_str());
+ row = (struct db_row*)li->data;
+ string crash_id = ssprintf("%s:%s", row->db_uid, row->db_uuid);
result.push_back(crash_id);
}
+
+ // TODO: return GList
+ db_list_free(rows);
}
void AddAnalyzerActionOrReporter(const char *pAnalyzer,
--
1.7.1
13 years, 8 months
Vos impayés traités immédiatement, honoraires sur résultats
by VSF
Victoria Service Finance ®
C o n t e n t i e u x R e c o u v r e m e n t
Société Courtage Recouvrement Finance
Siret 494 240 203 R.C.S A.P.E 748K N° intracommunautaire F.R 584 942 402 03 000 13
42/48, Rue des Mousses « Le Prado Plaza » 13008 Marseille
Pour traiter vos impayés
V.S.F a mis en place une action de recouvrement ultra rapide et performante
SANS FRAIS , SANS ABONNEMENT
INTERVENTION SUR PLACE
HONORAIRES UNIQUEMENT SUR RESULTATS
TRANSMISSION SIMPLE ET IMMEDIATE, SANS AUCUNE FORMALITE DE VOS DOSSIERS
Pour tout renseignement complémentaire
Appelez au: 04.91.22.60.50
ou
remplissez le formulaire de contact en cliquant sur le lien ci-dessous:
www.recouvrement-de-creances.eu/crfimpayes3.html
V.S.F : des hommes de terrain, pour une efficacité maximum
Si vous désirez vous désabonner, merci de cliquer sur le lien suivant: desabonnement(a)recouvrement-de-creances.eu
13 years, 8 months
That's me
by John Smith
Hi, my name is John Smith and I am happy !
13 years, 8 months
[PATCH] DebugDump.* -> dump_dir.*
by Nikola Pajkovsky
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
inc/Makefile.am | 2 +-
inc/abrtlib.h | 2 +
inc/crash_types.h | 2 +
inc/debug_dump.h | 58 ----
inc/dump_dir.h | 58 ++++
lib/plugins/Bugzilla.cpp | 1 -
lib/plugins/CCpp.cpp | 1 -
lib/plugins/FileTransfer.cpp | 1 -
lib/plugins/Kerneloops.cpp | 1 -
lib/plugins/KerneloopsScanner.cpp | 1 -
lib/plugins/Logger.cpp | 1 -
lib/plugins/Mailx.cpp | 1 -
lib/plugins/Python.cpp | 1 -
lib/plugins/RHTSupport.cpp | 1 -
lib/plugins/ReportUploader.cpp | 1 -
lib/plugins/RunApp.cpp | 1 -
lib/plugins/SOSreport.cpp | 1 -
lib/utils/DebugDump.cpp | 536 -------------------------------------
lib/utils/Makefile.am | 2 +-
lib/utils/dump_dir.c | 535 ++++++++++++++++++++++++++++++++++++
lib/utils/hooklib.c | 1 -
lib/utils/make_descr.cpp | 1 -
src/cli/report.cpp | 1 -
src/daemon/CrashWatcher.cpp | 1 -
src/daemon/Daemon.cpp | 1 -
src/daemon/MiddleWare.cpp | 1 -
src/daemon/dumpsocket.cpp | 1 -
src/hooks/abrt-hook-ccpp.cpp | 1 -
28 files changed, 599 insertions(+), 616 deletions(-)
delete mode 100644 inc/debug_dump.h
create mode 100644 inc/dump_dir.h
delete mode 100644 lib/utils/DebugDump.cpp
create mode 100644 lib/utils/dump_dir.c
diff --git a/inc/Makefile.am b/inc/Makefile.am
index 901c23f..a6b52be 100644
--- a/inc/Makefile.am
+++ b/inc/Makefile.am
@@ -9,7 +9,7 @@ HEADER_FILES = \
crash_types.h \
database.h \
dbus_common.h \
- debug_dump.h \
+ dump_dir.h \
observer.h \
plugin.h \
reporter.h \
diff --git a/inc/abrtlib.h b/inc/abrtlib.h
index 4d96aa1..2fc5101 100644
--- a/inc/abrtlib.h
+++ b/inc/abrtlib.h
@@ -72,6 +72,8 @@ int vdprintf(int d, const char *format, va_list ap);
#include "logging.h"
#include "read_write.h"
#include "strbuf.h"
+#include "crash_types.h"
+#include "dump_dir.h"
#ifdef __cplusplus
diff --git a/inc/crash_types.h b/inc/crash_types.h
index 25dbcd4..d892754 100644
--- a/inc/crash_types.h
+++ b/inc/crash_types.h
@@ -90,6 +90,7 @@ extern const char *const must_have_files[];
bool is_editable_file(const char *file_name);
+#ifdef __cplusplus
// <key, data>
typedef map_vector_string_t map_crash_data_t;
typedef std::vector<map_crash_data_t> vector_map_crash_data_t;
@@ -109,5 +110,6 @@ const char *get_crash_data_item_content_or_NULL(const map_crash_data_t& crash_da
const std::string& get_crash_data_item_content(const map_crash_data_t& crash_data, const char *key);
void log_map_crash_data(const map_crash_data_t& data, const char *name);
+#endif
#endif
diff --git a/inc/debug_dump.h b/inc/debug_dump.h
deleted file mode 100644
index 96d50d3..0000000
--- a/inc/debug_dump.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- DebugDump.h - header file for the library caring of writing new reports
- to the specific directory
-
- Copyright (C) 2009 Zdenek Prikryl (zprikryl(a)redhat.com)
- Copyright (C) 2009 RedHat inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-#ifndef DEBUGDUMP_H_
-#define DEBUGDUMP_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct dump_dir {
- char *dd_dir;
- DIR *next_dir;
- int opened;
- int locked;
- uid_t uid;
- gid_t gid;
-} dump_dir_t;
-
-dump_dir_t* dd_init(void);
-void dd_close(dump_dir_t *dd);
-
-int dd_opendir(dump_dir_t *dd, const char *dir);
-int dd_exist(dump_dir_t *dd, const char *path);
-int dd_create(dump_dir_t *dd, const char *dir, uid_t uid);
-int dd_init_next_file(dump_dir_t *dd);
-int dd_get_next_file(dump_dir_t *dd, char **short_name, char **full_name);
-
-char* dd_load_text(const dump_dir_t *dd, const char* name);
-void dd_save_text(dump_dir_t *dd, const char *name, const char *data);
-void dd_save_binary(dump_dir_t* dd, const char* name, const char* data, unsigned size);
-void dd_delete(dump_dir_t *dd);
-
-void delete_debug_dump_dir(const char *dd_dir);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/inc/dump_dir.h b/inc/dump_dir.h
new file mode 100644
index 0000000..96d50d3
--- /dev/null
+++ b/inc/dump_dir.h
@@ -0,0 +1,58 @@
+/*
+ DebugDump.h - header file for the library caring of writing new reports
+ to the specific directory
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl(a)redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#ifndef DEBUGDUMP_H_
+#define DEBUGDUMP_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct dump_dir {
+ char *dd_dir;
+ DIR *next_dir;
+ int opened;
+ int locked;
+ uid_t uid;
+ gid_t gid;
+} dump_dir_t;
+
+dump_dir_t* dd_init(void);
+void dd_close(dump_dir_t *dd);
+
+int dd_opendir(dump_dir_t *dd, const char *dir);
+int dd_exist(dump_dir_t *dd, const char *path);
+int dd_create(dump_dir_t *dd, const char *dir, uid_t uid);
+int dd_init_next_file(dump_dir_t *dd);
+int dd_get_next_file(dump_dir_t *dd, char **short_name, char **full_name);
+
+char* dd_load_text(const dump_dir_t *dd, const char* name);
+void dd_save_text(dump_dir_t *dd, const char *name, const char *data);
+void dd_save_binary(dump_dir_t* dd, const char* name, const char* data, unsigned size);
+void dd_delete(dump_dir_t *dd);
+
+void delete_debug_dump_dir(const char *dd_dir);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/plugins/Bugzilla.cpp b/lib/plugins/Bugzilla.cpp
index 6e5ffd9..752d8c5 100644
--- a/lib/plugins/Bugzilla.cpp
+++ b/lib/plugins/Bugzilla.cpp
@@ -21,7 +21,6 @@
#include "abrt_xmlrpc.h"
#include "Bugzilla.h"
#include "crash_types.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "comm_layer_inner.h"
diff --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp
index c01b195..9f52b97 100644
--- a/lib/plugins/CCpp.cpp
+++ b/lib/plugins/CCpp.cpp
@@ -23,7 +23,6 @@
#include "abrtlib.h"
#include "CCpp.h"
#include "abrt_exception.h"
-#include "debug_dump.h"
#include "comm_layer_inner.h"
#include "Polkit.h"
#include "backtrace.h"
diff --git a/lib/plugins/FileTransfer.cpp b/lib/plugins/FileTransfer.cpp
index 41874d2..4e4b581 100644
--- a/lib/plugins/FileTransfer.cpp
+++ b/lib/plugins/FileTransfer.cpp
@@ -27,7 +27,6 @@
#include "abrtlib.h"
#include "abrt_curl.h"
#include "FileTransfer.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "comm_layer_inner.h"
diff --git a/lib/plugins/Kerneloops.cpp b/lib/plugins/Kerneloops.cpp
index 1b58cd1..e12be7e 100644
--- a/lib/plugins/Kerneloops.cpp
+++ b/lib/plugins/Kerneloops.cpp
@@ -19,7 +19,6 @@
#include "abrtlib.h"
#include "Kerneloops.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "comm_layer_inner.h"
diff --git a/lib/plugins/KerneloopsScanner.cpp b/lib/plugins/KerneloopsScanner.cpp
index 2a1bc47..9b45402 100644
--- a/lib/plugins/KerneloopsScanner.cpp
+++ b/lib/plugins/KerneloopsScanner.cpp
@@ -23,7 +23,6 @@
#include <syslog.h>
#include <asm/unistd.h> /* __NR_syslog */
#include "abrtlib.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "comm_layer_inner.h"
#include "KerneloopsSysLog.h"
diff --git a/lib/plugins/Logger.cpp b/lib/plugins/Logger.cpp
index 0c4aad6..6a02e71 100644
--- a/lib/plugins/Logger.cpp
+++ b/lib/plugins/Logger.cpp
@@ -20,7 +20,6 @@
*/
#include "abrtlib.h"
#include "Logger.h"
-#include "debug_dump.h"
#include "comm_layer_inner.h"
#include "abrt_exception.h"
diff --git a/lib/plugins/Mailx.cpp b/lib/plugins/Mailx.cpp
index 2580bab..2bb125b 100644
--- a/lib/plugins/Mailx.cpp
+++ b/lib/plugins/Mailx.cpp
@@ -20,7 +20,6 @@
*/
#include "abrtlib.h"
#include "Mailx.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "comm_layer_inner.h"
diff --git a/lib/plugins/Python.cpp b/lib/plugins/Python.cpp
index 96ba03e..257fe80 100644
--- a/lib/plugins/Python.cpp
+++ b/lib/plugins/Python.cpp
@@ -18,7 +18,6 @@
*/
#include "abrtlib.h"
#include "Python.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "Python_hash.h"
diff --git a/lib/plugins/RHTSupport.cpp b/lib/plugins/RHTSupport.cpp
index 1caea09..94615fe 100644
--- a/lib/plugins/RHTSupport.cpp
+++ b/lib/plugins/RHTSupport.cpp
@@ -23,7 +23,6 @@
#include "abrt_curl.h"
#include "abrt_rh_support.h"
#include "crash_types.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "comm_layer_inner.h"
#include "RHTSupport.h"
diff --git a/lib/plugins/ReportUploader.cpp b/lib/plugins/ReportUploader.cpp
index 7c31d51..cab2ada 100644
--- a/lib/plugins/ReportUploader.cpp
+++ b/lib/plugins/ReportUploader.cpp
@@ -20,7 +20,6 @@
#include "abrtlib.h"
#include "abrt_curl.h"
#include "ReportUploader.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "comm_layer_inner.h"
diff --git a/lib/plugins/RunApp.cpp b/lib/plugins/RunApp.cpp
index 2f9d128..085a133 100644
--- a/lib/plugins/RunApp.cpp
+++ b/lib/plugins/RunApp.cpp
@@ -20,7 +20,6 @@
*/
#include "abrtlib.h"
#include "RunApp.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "comm_layer_inner.h"
#include "abrtlib.h"
diff --git a/lib/plugins/SOSreport.cpp b/lib/plugins/SOSreport.cpp
index 5180266..237fa10 100644
--- a/lib/plugins/SOSreport.cpp
+++ b/lib/plugins/SOSreport.cpp
@@ -20,7 +20,6 @@
#include "abrtlib.h"
#include "abrt_exception.h"
#include "SOSreport.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "comm_layer_inner.h"
diff --git a/lib/utils/DebugDump.cpp b/lib/utils/DebugDump.cpp
deleted file mode 100644
index 689c9da..0000000
--- a/lib/utils/DebugDump.cpp
+++ /dev/null
@@ -1,536 +0,0 @@
-/*
- DebugDump.cpp
-
- Copyright (C) 2009 Zdenek Prikryl (zprikryl(a)redhat.com)
- Copyright (C) 2009 RedHat inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-#include <sys/utsname.h>
-#include "abrtlib.h"
-#include "debug_dump.h"
-#include "comm_layer_inner.h"
-#include "strbuf.h"
-
-static bool isdigit_str(const char *str)
-{
- do
- {
- if (*str < '0' || *str > '9') return false;
- str++;
- } while (*str);
- return true;
-}
-
-static char* rm_trailing_slashes(const char *dir)
-{
- unsigned len = strlen(dir);
- while (len != 0 && dir[len-1] == '/')
- len--;
- return xstrndup(dir, len);
-}
-
-static bool exist_file_dir(const char *path)
-{
- struct stat buf;
- if (stat(path, &buf) == 0)
- {
- if (S_ISDIR(buf.st_mode) || S_ISREG(buf.st_mode))
- {
- return true;
- }
- }
- return false;
-}
-
-static char *load_text_file(const char *path);
-static void dd_lock(dump_dir_t *dd);
-static void dd_unlock(dump_dir_t *dd);
-
-dump_dir_t* dd_init(void)
-{
- return (dump_dir_t*)xzalloc(sizeof(dump_dir_t));
-}
-
-void dd_close(dump_dir_t *dd)
-{
- if (!dd)
- return;
-
- dd_unlock(dd);
- if (dd->next_dir)
- {
- closedir(dd->next_dir);
- free(dd->next_dir);
- }
-
- free(dd->dd_dir);
- free(dd);
-}
-
-int dd_opendir(dump_dir_t *dd, const char *dir)
-{
- if (dd->opened)
- error_msg_and_die("CDebugDump is already opened");
-
- dd->dd_dir = rm_trailing_slashes(dir);
- if (!dd->dd_dir || !exist_file_dir(dd->dd_dir))
- {
- error_msg("'%s' does not exist", dd->dd_dir);
- return 0;
- }
-
- dd_lock(dd);
- dd->opened = 1;
-
- /* In case caller would want to create more files, he'll need uid:gid */
- struct stat stat_buf;
- if (stat(dd->dd_dir, &stat_buf) == 0)
- {
- dd->uid = stat_buf.st_uid;
- dd->gid = stat_buf.st_gid;
- }
-
- return 1;
-}
-
-int dd_exist(dump_dir_t *dd, const char *path)
-{
- char *full_path = concat_path_file(dd->dd_dir, path);
- int ret = exist_file_dir(full_path);
- free(full_path);
- return ret;
-}
-
-static bool get_and_set_lock(const char* lock_file, const char* pid)
-{
- while (symlink(pid, lock_file) != 0)
- {
- if (errno != EEXIST)
- perror_msg_and_die("Can't create lock file '%s'", lock_file);
-
- char pid_buf[sizeof(pid_t)*3 + 4];
- ssize_t r = readlink(lock_file, pid_buf, sizeof(pid_buf) - 1);
- if (r < 0)
- {
- if (errno == ENOENT)
- {
- /* Looks like lock_file was deleted */
- usleep(10 * 1000); /* avoid CPU eating loop */
- continue;
- }
- perror_msg_and_die("Can't read lock file '%s'", lock_file);
- }
- pid_buf[r] = '\0';
-
- if (strcmp(pid_buf, pid) == 0)
- {
- log("Lock file '%s' is already locked by us", lock_file);
- return false;
- }
- if (isdigit_str(pid_buf))
- {
- char pid_str[sizeof("/proc/") + strlen(pid_buf)];
- sprintf(pid_str, "/proc/%s", pid_buf);
- if (access(pid_str, F_OK) == 0)
- {
- log("Lock file '%s' is locked by process %s", lock_file, pid_buf);
- return false;
- }
- log("Lock file '%s' was locked by process %s, but it crashed?", lock_file, pid_buf);
- }
- /* The file may be deleted by now by other process. Ignore ENOENT */
- if (unlink(lock_file) != 0 && errno != ENOENT)
- {
- perror_msg_and_die("Can't remove stale lock file '%s'", lock_file);
- }
- }
-
- VERB1 log("Locked '%s'", lock_file);
- return true;
-
-#if 0
-/* Old code was using ordinary files instead of symlinks,
- * but it had a race window between open and write, during which file was
- * empty. It was seen to happen in practice.
- */
- int fd;
- while ((fd = open(pLockFile, O_WRONLY | O_CREAT | O_EXCL, 0640)) < 0)
- {
- if (errno != EEXIST)
- perror_msg_and_die("Can't create lock file '%s'", pLockFile);
- fd = open(pLockFile, O_RDONLY);
- if (fd < 0)
- {
- if (errno == ENOENT)
- continue; /* someone else deleted the file */
- perror_msg_and_die("Can't open lock file '%s'", pLockFile);
- }
- char pid_buf[sizeof(pid_t)*3 + 4];
- int r = read(fd, pid_buf, sizeof(pid_buf) - 1);
- if (r < 0)
- perror_msg_and_die("Can't read lock file '%s'", pLockFile);
- close(fd);
- if (r == 0)
- {
- /* Other process did not write out PID yet.
- * We HOPE it did not crash... */
- continue;
- }
- pid_buf[r] = '\0';
- if (strcmp(pid_buf, pPID) == 0)
- {
- log("Lock file '%s' is already locked by us", pLockFile);
- return -1;
- }
- if (isdigit_str(pid_buf))
- {
- if (access(ssprintf("/proc/%s", pid_buf).c_str(), F_OK) == 0)
- {
- log("Lock file '%s' is locked by process %s", pLockFile, pid_buf);
- return -1;
- }
- log("Lock file '%s' was locked by process %s, but it crashed?", pLockFile, pid_buf);
- }
- /* The file may be deleted by now by other process. Ignore errors */
- unlink(pLockFile);
- }
-
- int len = strlen(pPID);
- if (write(fd, pPID, len) != len)
- {
- unlink(pLockFile);
- /* close(fd); - not needed, exiting does it too */
- perror_msg_and_die("Can't write lock file '%s'", pLockFile);
- }
- close(fd);
-
- VERB1 log("Locked '%s'", pLockFile);
- return true;
-#endif
-}
-
-static void dd_lock(dump_dir_t *dd)
-{
- if (dd->locked)
- error_msg_and_die("Locking bug on '%s'", dd->dd_dir);
-
- char lock_buf[strlen(dd->dd_dir) + sizeof(".lock")];
- sprintf(lock_buf, "%s.lock", dd->dd_dir);
-
- char pid_buf[sizeof(long)*3 + 2];
- sprintf(pid_buf, "%lu", (long)getpid());
- while ((dd->locked = get_and_set_lock(lock_buf, pid_buf)) != true)
- {
- sleep(1); /* was 0.5 seconds */
- }
-}
-
-static void dd_unlock(dump_dir_t *dd)
-{
- if (dd->locked)
- {
- char lock_buf[strlen(dd->dd_dir) + sizeof(".lock")];
- sprintf(lock_buf, "%s.lock", dd->dd_dir);
- xunlink(lock_buf);
- VERB1 log("Unlocked '%s'", lock_buf);
- }
-}
-
-/* Create a fresh empty debug dump dir.
- *
- * Security: we should not allow users to write new files or write
- * into existing ones, but they should be able to read them.
- *
- * @param uid
- * Crashed application's User Id
- *
- * We currently have only three callers:
- * kernel oops hook: uid=0
- * this hook runs under 0:0
- * ccpp hook: uid=uid of crashed user's binary
- * this hook runs under 0:0
- * python hook: uid=uid of crashed user's script
- * this hook runs under abrt:gid
- *
- * Currently, we set dir's gid to passwd(uid)->pw_gid parameter, and we set uid to
- * abrt's user id. We do not allow write access to group.
- */
-int dd_create(dump_dir_t *dd, const char *dir, uid_t uid)
-{
- if (dd->opened)
- error_msg_and_die("DebugDump is already opened");
-
- dd->dd_dir = rm_trailing_slashes(dir);
- if (exist_file_dir(dd->dd_dir))
- {
- error_msg("'%s' already exists", dd->dd_dir);
- return 0;
- }
-
- dd_lock(dd);
- dd->opened = 1;
-
- /* Was creating it with mode 0700 and user as the owner, but this allows
- * the user to replace any file in the directory, changing security-sensitive data
- * (e.g. "uid", "analyzer", "executable")
- */
- if (mkdir(dd->dd_dir, 0750) == -1)
- {
- dd_unlock(dd);
- dd->opened = 0;
- error_msg("Can't create dir '%s'", dir);
- return 0;
- }
-
- /* mkdir's mode (above) can be affected by umask, fix it */
- if (chmod(dd->dd_dir, 0750) == -1)
- {
- dd_unlock(dd);
- dd->opened = false;
- error_msg("Can't change mode of '%s'", dir);
- return false;
- }
-
- /* Get ABRT's user id */
- dd->uid = 0;
- struct passwd *pw = getpwnam("abrt");
- if (pw)
- dd->uid = pw->pw_uid;
- else
- error_msg("User 'abrt' does not exist, using uid 0");
-
- /* Get crashed application's group id */
- dd->gid = 0;
- pw = getpwuid(uid);
- if (pw)
- dd->gid = pw->pw_gid;
- else
- error_msg("User %lu does not exist, using gid 0", (long)uid);
-
- if (chown(dd->dd_dir, dd->uid, dd->gid) == -1)
- {
- perror_msg("can't change '%s' ownership to %lu:%lu", dd->dd_dir,
- (long)dd->uid, (long)dd->gid);
- }
-
- char uid_str[sizeof(long) * 3 + 2];
- sprintf(uid_str, "%lu", (long)uid);
- dd_save_text(dd, CD_UID, uid_str);
-
- {
- struct utsname buf;
- if (uname(&buf) != 0)
- {
- perror_msg_and_die("uname");
- }
- dd_save_text(dd, FILENAME_KERNEL, buf.release);
- dd_save_text(dd, FILENAME_ARCHITECTURE, buf.machine);
- char *release = load_text_file("/etc/redhat-release");
- strchrnul(release, '\n')[0] = '\0';
- dd_save_text(dd, FILENAME_RELEASE, release);
- free(release);
- }
-
- time_t t = time(NULL);
- char t_str[sizeof(time_t) * 3 + 2];
- sprintf(t_str, "%lu", (time_t)t);
- dd_save_text(dd, FILENAME_TIME, t_str);
-
- return 1;
-}
-
-static bool delete_file_dir(const char *dir)
-{
- if (!exist_file_dir(dir))
- return true;
-
- DIR *d = opendir(dir);
- if (!d)
- {
- error_msg("Can't open dir '%s'", dir);
- return false;
- }
-
- struct dirent *dent;
- while ((dent = readdir(d)) != NULL)
- {
- if (dot_or_dotdot(dent->d_name))
- continue;
- char *full_path = concat_path_file(dir, dent->d_name);
- if (unlink(full_path) == -1)
- {
- if (errno != EISDIR)
- {
- closedir(d);
- error_msg("Can't remove dir '%s'", full_path);
- free(full_path);
- return false;
- }
- delete_file_dir(full_path);
- }
- free(full_path);
- }
- closedir(d);
- if (rmdir(dir) == -1)
- {
- error_msg("Can't remove dir %s", dir);
- return false;
- }
-
- return true;
-}
-
-void dd_delete(dump_dir_t *dd)
-{
- if (!exist_file_dir(dd->dd_dir))
- {
- return;
- }
-
- delete_file_dir(dd->dd_dir);
-}
-
-static char *load_text_file(const char *path)
-{
- FILE *fp = fopen(path, "r");
- if (!fp)
- {
- perror_msg("Can't open file '%s'", path);
- return xstrdup("");
- }
-
- struct strbuf *buf_content = strbuf_new();
- int ch;
- while ((ch = fgetc(fp)) != EOF)
- {
- if (ch == '\0')
- strbuf_append_char(buf_content, ' ');
- else if (isspace(ch) || (isascii(ch) && !iscntrl(ch)))
- strbuf_append_char(buf_content, ch);
- }
- fclose(fp);
-
- return strbuf_free_nobuf(buf_content);
-}
-
-static bool save_binary_file(const char *path, const char* data, unsigned size, uid_t uid, gid_t gid)
-{
- /* "Why 0640?!" See ::Create() for security analysis */
- unlink(path);
- int fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0640);
- if (fd < 0)
- {
- error_msg("Can't open file '%s': %s", path, errno ? strerror(errno) : "errno == 0");
- return false;
- }
- if (fchown(fd, uid, gid) == -1)
- {
- perror_msg("can't change '%s' ownership to %lu:%lu", path, (long)uid, (long)gid);
- }
- unsigned r = full_write(fd, data, size);
- close(fd);
- if (r != size)
- {
- error_msg("Can't save file '%s'", path);
- return false;
- }
-
- return true;
-}
-
-char* dd_load_text(const dump_dir_t *dd, const char *name)
-{
- if (!dd->opened)
- error_msg_and_die("DebugDump is not opened");
-
- char *full_path = concat_path_file(dd->dd_dir, name);
- char *ret = load_text_file(full_path);
- free(full_path);
-
- return ret;
-}
-
-void dd_save_text(dump_dir_t *dd, const char *name, const char *data)
-{
- if (!dd->opened)
- error_msg_and_die("DebugDump is not opened");
-
- char *full_path = concat_path_file(dd->dd_dir, name);
- save_binary_file(full_path, data, strlen(data), dd->uid, dd->gid);
- free(full_path);
-}
-
-void dd_save_binary(dump_dir_t* dd, const char* name, const char* data, unsigned size)
-{
- if (dd->opened)
- error_msg_and_die("DebugDump is not opened");
-
- char *full_path = concat_path_file(dd->dd_dir, name);
- save_binary_file(full_path, data, size, dd->uid, dd->gid);
- free(full_path);
-}
-
-int dd_init_next_file(dump_dir_t *dd)
-{
- if (!dd->opened)
- error_msg_and_die("DebugDump is not opened");
-
- if (dd->next_dir)
- closedir(dd->next_dir);
-
- dd->next_dir = opendir(dd->dd_dir);
- if (!dd->next_dir)
- {
- error_msg("Can't open dir '%s'", dd->dd_dir);
- return 0;
- }
-
- return 1;
-}
-
-int dd_get_next_file(dump_dir_t *dd, char **short_name, char **full_name)
-{
- if (dd->next_dir == NULL)
- return 0;
-
- struct dirent *dent;
- while ((dent = readdir(dd->next_dir)) != NULL)
- {
- if (is_regular_file(dent, dd->dd_dir))
- {
- if (short_name)
- *short_name = xstrdup(dent->d_name);
- if (full_name)
- *full_name = concat_path_file(dd->dd_dir, dent->d_name);
- return 1;
- }
- }
-
- closedir(dd->next_dir);
- dd->next_dir = NULL;
- return 0;
-}
-
-/* Utility function */
-void delete_debug_dump_dir(const char *dd_dir)
-{
- dump_dir_t *dd = dd_init();
- if (dd_opendir(dd, dd_dir))
- dd_delete(dd);
- else
- VERB1 log("Unable to open debug dump '%s'", dd_dir);
- dd_close(dd);
-}
diff --git a/lib/utils/Makefile.am b/lib/utils/Makefile.am
index d35ffb8..cc77c82 100644
--- a/lib/utils/Makefile.am
+++ b/lib/utils/Makefile.am
@@ -23,7 +23,7 @@ libABRTUtils_la_SOURCES = \
spawn.c \
stringops.cpp \
dirsize.c \
- DebugDump.cpp \
+ dump_dir.c \
abrt_dbus.c abrt_dbus.h \
CrashTypes.cpp \
ABRTException.cpp \
diff --git a/lib/utils/dump_dir.c b/lib/utils/dump_dir.c
new file mode 100644
index 0000000..7ce9ab0
--- /dev/null
+++ b/lib/utils/dump_dir.c
@@ -0,0 +1,535 @@
+/*
+ DebugDump.cpp
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl(a)redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include <sys/utsname.h>
+#include "abrtlib.h"
+#include "comm_layer_inner.h"
+#include "strbuf.h"
+
+static bool isdigit_str(const char *str)
+{
+ do
+ {
+ if (*str < '0' || *str > '9') return false;
+ str++;
+ } while (*str);
+ return true;
+}
+
+static char* rm_trailing_slashes(const char *dir)
+{
+ unsigned len = strlen(dir);
+ while (len != 0 && dir[len-1] == '/')
+ len--;
+ return xstrndup(dir, len);
+}
+
+static bool exist_file_dir(const char *path)
+{
+ struct stat buf;
+ if (stat(path, &buf) == 0)
+ {
+ if (S_ISDIR(buf.st_mode) || S_ISREG(buf.st_mode))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+static char *load_text_file(const char *path);
+static void dd_lock(dump_dir_t *dd);
+static void dd_unlock(dump_dir_t *dd);
+
+dump_dir_t* dd_init(void)
+{
+ return (dump_dir_t*)xzalloc(sizeof(dump_dir_t));
+}
+
+void dd_close(dump_dir_t *dd)
+{
+ if (!dd)
+ return;
+
+ dd_unlock(dd);
+ if (dd->next_dir)
+ {
+ closedir(dd->next_dir);
+ free(dd->next_dir);
+ }
+
+ free(dd->dd_dir);
+ free(dd);
+}
+
+int dd_opendir(dump_dir_t *dd, const char *dir)
+{
+ if (dd->opened)
+ error_msg_and_die("CDebugDump is already opened");
+
+ dd->dd_dir = rm_trailing_slashes(dir);
+ if (!dd->dd_dir || !exist_file_dir(dd->dd_dir))
+ {
+ error_msg("'%s' does not exist", dd->dd_dir);
+ return 0;
+ }
+
+ dd_lock(dd);
+ dd->opened = 1;
+
+ /* In case caller would want to create more files, he'll need uid:gid */
+ struct stat stat_buf;
+ if (stat(dd->dd_dir, &stat_buf) == 0)
+ {
+ dd->uid = stat_buf.st_uid;
+ dd->gid = stat_buf.st_gid;
+ }
+
+ return 1;
+}
+
+int dd_exist(dump_dir_t *dd, const char *path)
+{
+ char *full_path = concat_path_file(dd->dd_dir, path);
+ int ret = exist_file_dir(full_path);
+ free(full_path);
+ return ret;
+}
+
+static bool get_and_set_lock(const char* lock_file, const char* pid)
+{
+ while (symlink(pid, lock_file) != 0)
+ {
+ if (errno != EEXIST)
+ perror_msg_and_die("Can't create lock file '%s'", lock_file);
+
+ char pid_buf[sizeof(pid_t)*3 + 4];
+ ssize_t r = readlink(lock_file, pid_buf, sizeof(pid_buf) - 1);
+ if (r < 0)
+ {
+ if (errno == ENOENT)
+ {
+ /* Looks like lock_file was deleted */
+ usleep(10 * 1000); /* avoid CPU eating loop */
+ continue;
+ }
+ perror_msg_and_die("Can't read lock file '%s'", lock_file);
+ }
+ pid_buf[r] = '\0';
+
+ if (strcmp(pid_buf, pid) == 0)
+ {
+ log("Lock file '%s' is already locked by us", lock_file);
+ return false;
+ }
+ if (isdigit_str(pid_buf))
+ {
+ char pid_str[sizeof("/proc/") + strlen(pid_buf)];
+ sprintf(pid_str, "/proc/%s", pid_buf);
+ if (access(pid_str, F_OK) == 0)
+ {
+ log("Lock file '%s' is locked by process %s", lock_file, pid_buf);
+ return false;
+ }
+ log("Lock file '%s' was locked by process %s, but it crashed?", lock_file, pid_buf);
+ }
+ /* The file may be deleted by now by other process. Ignore ENOENT */
+ if (unlink(lock_file) != 0 && errno != ENOENT)
+ {
+ perror_msg_and_die("Can't remove stale lock file '%s'", lock_file);
+ }
+ }
+
+ VERB1 log("Locked '%s'", lock_file);
+ return true;
+
+#if 0
+/* Old code was using ordinary files instead of symlinks,
+ * but it had a race window between open and write, during which file was
+ * empty. It was seen to happen in practice.
+ */
+ int fd;
+ while ((fd = open(pLockFile, O_WRONLY | O_CREAT | O_EXCL, 0640)) < 0)
+ {
+ if (errno != EEXIST)
+ perror_msg_and_die("Can't create lock file '%s'", pLockFile);
+ fd = open(pLockFile, O_RDONLY);
+ if (fd < 0)
+ {
+ if (errno == ENOENT)
+ continue; /* someone else deleted the file */
+ perror_msg_and_die("Can't open lock file '%s'", pLockFile);
+ }
+ char pid_buf[sizeof(pid_t)*3 + 4];
+ int r = read(fd, pid_buf, sizeof(pid_buf) - 1);
+ if (r < 0)
+ perror_msg_and_die("Can't read lock file '%s'", pLockFile);
+ close(fd);
+ if (r == 0)
+ {
+ /* Other process did not write out PID yet.
+ * We HOPE it did not crash... */
+ continue;
+ }
+ pid_buf[r] = '\0';
+ if (strcmp(pid_buf, pPID) == 0)
+ {
+ log("Lock file '%s' is already locked by us", pLockFile);
+ return -1;
+ }
+ if (isdigit_str(pid_buf))
+ {
+ if (access(ssprintf("/proc/%s", pid_buf).c_str(), F_OK) == 0)
+ {
+ log("Lock file '%s' is locked by process %s", pLockFile, pid_buf);
+ return -1;
+ }
+ log("Lock file '%s' was locked by process %s, but it crashed?", pLockFile, pid_buf);
+ }
+ /* The file may be deleted by now by other process. Ignore errors */
+ unlink(pLockFile);
+ }
+
+ int len = strlen(pPID);
+ if (write(fd, pPID, len) != len)
+ {
+ unlink(pLockFile);
+ /* close(fd); - not needed, exiting does it too */
+ perror_msg_and_die("Can't write lock file '%s'", pLockFile);
+ }
+ close(fd);
+
+ VERB1 log("Locked '%s'", pLockFile);
+ return true;
+#endif
+}
+
+static void dd_lock(dump_dir_t *dd)
+{
+ if (dd->locked)
+ error_msg_and_die("Locking bug on '%s'", dd->dd_dir);
+
+ char lock_buf[strlen(dd->dd_dir) + sizeof(".lock")];
+ sprintf(lock_buf, "%s.lock", dd->dd_dir);
+
+ char pid_buf[sizeof(long)*3 + 2];
+ sprintf(pid_buf, "%lu", (long)getpid());
+ while ((dd->locked = get_and_set_lock(lock_buf, pid_buf)) != true)
+ {
+ sleep(1); /* was 0.5 seconds */
+ }
+}
+
+static void dd_unlock(dump_dir_t *dd)
+{
+ if (dd->locked)
+ {
+ char lock_buf[strlen(dd->dd_dir) + sizeof(".lock")];
+ sprintf(lock_buf, "%s.lock", dd->dd_dir);
+ xunlink(lock_buf);
+ VERB1 log("Unlocked '%s'", lock_buf);
+ }
+}
+
+/* Create a fresh empty debug dump dir.
+ *
+ * Security: we should not allow users to write new files or write
+ * into existing ones, but they should be able to read them.
+ *
+ * @param uid
+ * Crashed application's User Id
+ *
+ * We currently have only three callers:
+ * kernel oops hook: uid=0
+ * this hook runs under 0:0
+ * ccpp hook: uid=uid of crashed user's binary
+ * this hook runs under 0:0
+ * python hook: uid=uid of crashed user's script
+ * this hook runs under abrt:gid
+ *
+ * Currently, we set dir's gid to passwd(uid)->pw_gid parameter, and we set uid to
+ * abrt's user id. We do not allow write access to group.
+ */
+int dd_create(dump_dir_t *dd, const char *dir, uid_t uid)
+{
+ if (dd->opened)
+ error_msg_and_die("DebugDump is already opened");
+
+ dd->dd_dir = rm_trailing_slashes(dir);
+ if (exist_file_dir(dd->dd_dir))
+ {
+ error_msg("'%s' already exists", dd->dd_dir);
+ return 0;
+ }
+
+ dd_lock(dd);
+ dd->opened = 1;
+
+ /* Was creating it with mode 0700 and user as the owner, but this allows
+ * the user to replace any file in the directory, changing security-sensitive data
+ * (e.g. "uid", "analyzer", "executable")
+ */
+ if (mkdir(dd->dd_dir, 0750) == -1)
+ {
+ dd_unlock(dd);
+ dd->opened = 0;
+ error_msg("Can't create dir '%s'", dir);
+ return 0;
+ }
+
+ /* mkdir's mode (above) can be affected by umask, fix it */
+ if (chmod(dd->dd_dir, 0750) == -1)
+ {
+ dd_unlock(dd);
+ dd->opened = false;
+ error_msg("Can't change mode of '%s'", dir);
+ return false;
+ }
+
+ /* Get ABRT's user id */
+ dd->uid = 0;
+ struct passwd *pw = getpwnam("abrt");
+ if (pw)
+ dd->uid = pw->pw_uid;
+ else
+ error_msg("User 'abrt' does not exist, using uid 0");
+
+ /* Get crashed application's group id */
+ dd->gid = 0;
+ pw = getpwuid(uid);
+ if (pw)
+ dd->gid = pw->pw_gid;
+ else
+ error_msg("User %lu does not exist, using gid 0", (long)uid);
+
+ if (chown(dd->dd_dir, dd->uid, dd->gid) == -1)
+ {
+ perror_msg("can't change '%s' ownership to %lu:%lu", dd->dd_dir,
+ (long)dd->uid, (long)dd->gid);
+ }
+
+ char uid_str[sizeof(long) * 3 + 2];
+ sprintf(uid_str, "%lu", (long)uid);
+ dd_save_text(dd, CD_UID, uid_str);
+
+ {
+ struct utsname buf;
+ if (uname(&buf) != 0)
+ {
+ perror_msg_and_die("uname");
+ }
+ dd_save_text(dd, FILENAME_KERNEL, buf.release);
+ dd_save_text(dd, FILENAME_ARCHITECTURE, buf.machine);
+ char *release = load_text_file("/etc/redhat-release");
+ strchrnul(release, '\n')[0] = '\0';
+ dd_save_text(dd, FILENAME_RELEASE, release);
+ free(release);
+ }
+
+ time_t t = time(NULL);
+ char t_str[sizeof(time_t) * 3 + 2];
+ sprintf(t_str, "%lu", (time_t)t);
+ dd_save_text(dd, FILENAME_TIME, t_str);
+
+ return 1;
+}
+
+static bool delete_file_dir(const char *dir)
+{
+ if (!exist_file_dir(dir))
+ return true;
+
+ DIR *d = opendir(dir);
+ if (!d)
+ {
+ error_msg("Can't open dir '%s'", dir);
+ return false;
+ }
+
+ struct dirent *dent;
+ while ((dent = readdir(d)) != NULL)
+ {
+ if (dot_or_dotdot(dent->d_name))
+ continue;
+ char *full_path = concat_path_file(dir, dent->d_name);
+ if (unlink(full_path) == -1)
+ {
+ if (errno != EISDIR)
+ {
+ closedir(d);
+ error_msg("Can't remove dir '%s'", full_path);
+ free(full_path);
+ return false;
+ }
+ delete_file_dir(full_path);
+ }
+ free(full_path);
+ }
+ closedir(d);
+ if (rmdir(dir) == -1)
+ {
+ error_msg("Can't remove dir %s", dir);
+ return false;
+ }
+
+ return true;
+}
+
+void dd_delete(dump_dir_t *dd)
+{
+ if (!exist_file_dir(dd->dd_dir))
+ {
+ return;
+ }
+
+ delete_file_dir(dd->dd_dir);
+}
+
+static char *load_text_file(const char *path)
+{
+ FILE *fp = fopen(path, "r");
+ if (!fp)
+ {
+ perror_msg("Can't open file '%s'", path);
+ return xstrdup("");
+ }
+
+ struct strbuf *buf_content = strbuf_new();
+ int ch;
+ while ((ch = fgetc(fp)) != EOF)
+ {
+ if (ch == '\0')
+ strbuf_append_char(buf_content, ' ');
+ else if (isspace(ch) || (isascii(ch) && !iscntrl(ch)))
+ strbuf_append_char(buf_content, ch);
+ }
+ fclose(fp);
+
+ return strbuf_free_nobuf(buf_content);
+}
+
+static bool save_binary_file(const char *path, const char* data, unsigned size, uid_t uid, gid_t gid)
+{
+ /* "Why 0640?!" See ::Create() for security analysis */
+ unlink(path);
+ int fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0640);
+ if (fd < 0)
+ {
+ error_msg("Can't open file '%s': %s", path, errno ? strerror(errno) : "errno == 0");
+ return false;
+ }
+ if (fchown(fd, uid, gid) == -1)
+ {
+ perror_msg("can't change '%s' ownership to %lu:%lu", path, (long)uid, (long)gid);
+ }
+ unsigned r = full_write(fd, data, size);
+ close(fd);
+ if (r != size)
+ {
+ error_msg("Can't save file '%s'", path);
+ return false;
+ }
+
+ return true;
+}
+
+char* dd_load_text(const dump_dir_t *dd, const char *name)
+{
+ if (!dd->opened)
+ error_msg_and_die("DebugDump is not opened");
+
+ char *full_path = concat_path_file(dd->dd_dir, name);
+ char *ret = load_text_file(full_path);
+ free(full_path);
+
+ return ret;
+}
+
+void dd_save_text(dump_dir_t *dd, const char *name, const char *data)
+{
+ if (!dd->opened)
+ error_msg_and_die("DebugDump is not opened");
+
+ char *full_path = concat_path_file(dd->dd_dir, name);
+ save_binary_file(full_path, data, strlen(data), dd->uid, dd->gid);
+ free(full_path);
+}
+
+void dd_save_binary(dump_dir_t* dd, const char* name, const char* data, unsigned size)
+{
+ if (dd->opened)
+ error_msg_and_die("DebugDump is not opened");
+
+ char *full_path = concat_path_file(dd->dd_dir, name);
+ save_binary_file(full_path, data, size, dd->uid, dd->gid);
+ free(full_path);
+}
+
+int dd_init_next_file(dump_dir_t *dd)
+{
+ if (!dd->opened)
+ error_msg_and_die("DebugDump is not opened");
+
+ if (dd->next_dir)
+ closedir(dd->next_dir);
+
+ dd->next_dir = opendir(dd->dd_dir);
+ if (!dd->next_dir)
+ {
+ error_msg("Can't open dir '%s'", dd->dd_dir);
+ return 0;
+ }
+
+ return 1;
+}
+
+int dd_get_next_file(dump_dir_t *dd, char **short_name, char **full_name)
+{
+ if (dd->next_dir == NULL)
+ return 0;
+
+ struct dirent *dent;
+ while ((dent = readdir(dd->next_dir)) != NULL)
+ {
+ if (is_regular_file(dent, dd->dd_dir))
+ {
+ if (short_name)
+ *short_name = xstrdup(dent->d_name);
+ if (full_name)
+ *full_name = concat_path_file(dd->dd_dir, dent->d_name);
+ return 1;
+ }
+ }
+
+ closedir(dd->next_dir);
+ dd->next_dir = NULL;
+ return 0;
+}
+
+/* Utility function */
+void delete_debug_dump_dir(const char *dd_dir)
+{
+ dump_dir_t *dd = dd_init();
+ if (dd_opendir(dd, dd_dir))
+ dd_delete(dd);
+ else
+ VERB1 log("Unable to open debug dump '%s'", dd_dir);
+ dd_close(dd);
+}
diff --git a/lib/utils/hooklib.c b/lib/utils/hooklib.c
index b0d161d..243d269 100644
--- a/lib/utils/hooklib.c
+++ b/lib/utils/hooklib.c
@@ -17,7 +17,6 @@
*/
#include "abrtlib.h"
#include "hooklib.h"
-#include "debug_dump.h"
#include <sys/statvfs.h>
void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSize, bool *setting_MakeCompatCore, bool *setting_SaveBinaryImage)
diff --git a/lib/utils/make_descr.cpp b/lib/utils/make_descr.cpp
index 131a0a3..bfe2a10 100644
--- a/lib/utils/make_descr.cpp
+++ b/lib/utils/make_descr.cpp
@@ -18,7 +18,6 @@
*/
#include "abrtlib.h"
#include "crash_types.h"
-#include "debug_dump.h" /* FILENAME_ARCHITECTURE etc */
using namespace std;
diff --git a/src/cli/report.cpp b/src/cli/report.cpp
index f56050f..4396889 100644
--- a/src/cli/report.cpp
+++ b/src/cli/report.cpp
@@ -22,7 +22,6 @@
#include "run-command.h"
#include "dbus.h"
#include "abrtlib.h"
-#include "debug_dump.h"
#include "crash_types.h" // FILENAME_* defines
#include "plugin.h" // LoadPluginSettings
diff --git a/src/daemon/CrashWatcher.cpp b/src/daemon/CrashWatcher.cpp
index dad4381..6310118 100644
--- a/src/daemon/CrashWatcher.cpp
+++ b/src/daemon/CrashWatcher.cpp
@@ -19,7 +19,6 @@
#include "abrtlib.h"
#include "Daemon.h"
#include "abrt_exception.h"
-#include "debug_dump.h"
#include "CrashWatcher.h"
void CCrashWatcher::Status(const char *pMessage, const char* peer)
diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp
index ac845b1..a0406f4 100644
--- a/src/daemon/Daemon.cpp
+++ b/src/daemon/Daemon.cpp
@@ -31,7 +31,6 @@
#include "abrtlib.h"
#include "abrt_exception.h"
#include "CrashWatcher.h"
-#include "debug_dump.h"
#include "Daemon.h"
#include "dumpsocket.h"
#include "rpm.h"
diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp
index 65d4a4b..7752dc3 100644
--- a/src/daemon/MiddleWare.cpp
+++ b/src/daemon/MiddleWare.cpp
@@ -24,7 +24,6 @@
#include "Daemon.h"
#include "Settings.h"
#include "rpm.h"
-#include "debug_dump.h"
#include "abrt_exception.h"
#include "abrt_packages.h"
#include "comm_layer_inner.h"
diff --git a/src/daemon/dumpsocket.cpp b/src/daemon/dumpsocket.cpp
index c72e366..0132b07 100644
--- a/src/daemon/dumpsocket.cpp
+++ b/src/daemon/dumpsocket.cpp
@@ -19,7 +19,6 @@
#include <sys/un.h>
#include "abrtlib.h"
#include "dumpsocket.h"
-#include "debug_dump.h"
#include "crash_types.h"
#include "abrt_exception.h"
#include "hooklib.h"
diff --git a/src/hooks/abrt-hook-ccpp.cpp b/src/hooks/abrt-hook-ccpp.cpp
index 9a7500b..6faa6a6 100644
--- a/src/hooks/abrt-hook-ccpp.cpp
+++ b/src/hooks/abrt-hook-ccpp.cpp
@@ -20,7 +20,6 @@
*/
#include "abrtlib.h"
#include "hooklib.h"
-#include "debug_dump.h"
#include "crash_types.h"
#include "abrt_exception.h"
#include <syslog.h>
--
1.7.1
13 years, 8 months
Approved way abrtd is running + catching cores
by Jan Kratochvil
Hi,
GDB sometimes reports an internal error, one can artifically simulate it by a
command:
(gdb) maintenance internal-error
../../gdb/maint.c:124: internal-error:
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y
../../gdb/maint.c:124: internal-error:
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) y
Aborted (core dumped)
It gets dumped from automatic sessions (in recent GDB even just by --batch):
$ gdb -nx -ex 'maint internal-error' </dev/null
[...]
Quit this debugging session? (y or n) [answered Y; input not from terminal]
[...]
Create a core file of GDB? (y or n) [answered Y; input not from terminal]
I would like to adjust it to always report the problem to abrt even during
interactive sessions.
Is there an approved way to detect abrtd will catch+report a core?
Like whether to check /var/run/abrt/abrtd.lock or strncmp
of "|/usr/libexec/abrt-hook-ccpp " in /proc/sys/kernel/core_pattern ?
Thanks,
Jan
13 years, 8 months
[PATCH 1/2] DebugDump.cpp: lowercase and rename functions
by Nikola Pajkovsky
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
inc/debug_dump.h | 6 ++--
lib/plugins/CCpp.cpp | 42 +++++++++++++-------------
lib/plugins/Kerneloops.cpp | 2 +-
lib/plugins/KerneloopsScanner.cpp | 12 ++++----
lib/plugins/Python.cpp | 2 +-
lib/plugins/RunApp.cpp | 2 +-
lib/utils/DebugDump.cpp | 58 ++++++++++++++++++------------------
src/daemon/MiddleWare.cpp | 34 +++++++++++-----------
src/daemon/dumpsocket.cpp | 12 ++++----
src/hooks/abrt-hook-ccpp.cpp | 8 ++--
10 files changed, 89 insertions(+), 89 deletions(-)
diff --git a/inc/debug_dump.h b/inc/debug_dump.h
index 60cddd7..96d50d3 100644
--- a/inc/debug_dump.h
+++ b/inc/debug_dump.h
@@ -44,9 +44,9 @@ int dd_create(dump_dir_t *dd, const char *dir, uid_t uid);
int dd_init_next_file(dump_dir_t *dd);
int dd_get_next_file(dump_dir_t *dd, char **short_name, char **full_name);
-char* dd_loadtxt(const dump_dir_t *dd, const char* name);
-void dd_savetxt(dump_dir_t *dd, const char *name, const char *data);
-void dd_savebin(dump_dir_t* dd, const char* name, const char* data, unsigned size);
+char* dd_load_text(const dump_dir_t *dd, const char* name);
+void dd_save_text(dump_dir_t *dd, const char *name, const char *data);
+void dd_save_binary(dump_dir_t* dd, const char* name, const char* data, unsigned size);
void dd_delete(dump_dir_t *dd);
void delete_debug_dump_dir(const char *dd_dir);
diff --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp
index 7665cad..c01b195 100644
--- a/lib/plugins/CCpp.cpp
+++ b/lib/plugins/CCpp.cpp
@@ -194,8 +194,8 @@ static char *get_backtrace(const char *pDebugDumpDir, const char *pDebugInfoDirs
return NULL;
}
- char *uid = dd_loadtxt(dd, CD_UID);
- char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE);
+ char *uid = dd_load_text(dd, CD_UID);
+ char *executable = dd_load_text(dd, FILENAME_EXECUTABLE);
dd_close(dd);
// Workaround for
@@ -343,7 +343,7 @@ static char* run_unstrip_n(const char *pDebugDumpDir)
return NULL;
}
- char *uid = dd_loadtxt(dd, CD_UID);
+ char *uid = dd_load_text(dd, CD_UID);
dd_close(dd);
char* args[4];
@@ -537,8 +537,8 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir)
return string("");
}
- char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE);
- char *package = dd_loadtxt(dd, FILENAME_PACKAGE);
+ char *executable = dd_load_text(dd, FILENAME_EXECUTABLE);
+ char *package = dd_load_text(dd, FILENAME_PACKAGE);
dd_close(dd);
string independentBuildIdPC;
@@ -599,7 +599,7 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir)
if (dd_exist(dd, FILENAME_GLOBAL_UUID))
{
- char *uuid = dd_loadtxt(dd, FILENAME_GLOBAL_UUID);
+ char *uuid = dd_load_text(dd, FILENAME_GLOBAL_UUID);
dd_close(dd);
string ret = uuid;
free(uuid);
@@ -612,9 +612,9 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir)
log(_("Getting global universal unique identification..."));
string backtrace_path = concat_path_file(pDebugDumpDir, FILENAME_BACKTRACE);
- char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE);
- char *package = dd_loadtxt(dd, FILENAME_PACKAGE);
- char *uid_str = m_bBacktrace ? dd_loadtxt(dd, CD_UID) : xstrdup("");
+ char *executable = dd_load_text(dd, FILENAME_EXECUTABLE);
+ char *package = dd_load_text(dd, FILENAME_PACKAGE);
+ char *uid_str = m_bBacktrace ? dd_load_text(dd, CD_UID) : xstrdup("");
string independent_backtrace;
if (m_bBacktrace)
@@ -712,7 +712,7 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir)
*/
else
{
- dd_savetxt(dd, FILENAME_RATING, "0");
+ dd_save_text(dd, FILENAME_RATING, "0");
}
dd_close(dd);
@@ -770,7 +770,7 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
/* Skip remote crashes. */
if (dd_exist(dd, FILENAME_REMOTE))
{
- char *remote_str = dd_loadtxt(dd, FILENAME_REMOTE);
+ char *remote_str = dd_load_text(dd, FILENAME_REMOTE);
bool remote = (remote_str[0] != '1');
free(remote_str);
if (remote && !m_bBacktraceRemotes)
@@ -796,9 +796,9 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
}
}
- char *package = dd_loadtxt(dd, FILENAME_PACKAGE);
- char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE);
- char *uid = dd_loadtxt(dd, CD_UID);
+ char *package = dd_load_text(dd, FILENAME_PACKAGE);
+ char *executable = dd_load_text(dd, FILENAME_EXECUTABLE);
+ char *uid = dd_load_text(dd, CD_UID);
dd_close(dd); /* do not keep dir locked longer than needed */
char *build_ids = NULL;
@@ -829,11 +829,11 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
VERB1 log(_("Unable to open debug dump '%s'"), pDebugDumpDir);
return;
}
- dd_savetxt(dd, FILENAME_BACKTRACE, bt_build_ids);
+ dd_save_text(dd, FILENAME_BACKTRACE, bt_build_ids);
free(bt_build_ids);
if (m_bMemoryMap)
- dd_savetxt(dd, FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet");
+ dd_save_text(dd, FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet");
/* Compute and store UUID from the backtrace. */
char *backtrace_cpy = xstrdup(backtrace_str);
@@ -870,7 +870,7 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
struct strbuf *bt = backtrace_tree_as_str(backtrace, false);
strbuf_prepend_str(bt, executable);
strbuf_prepend_str(bt, package);
- dd_savetxt(dd, FILENAME_GLOBAL_UUID, create_hash(bt->buf).c_str());
+ dd_save_text(dd, FILENAME_GLOBAL_UUID, create_hash(bt->buf).c_str());
strbuf_free(bt);
/* Compute and store backtrace rating. */
@@ -886,7 +886,7 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
else if (qtot < 0.8f) rating = "2";
else if (qtot < 0.9f) rating = "3";
else rating = "4";
- dd_savetxt(dd, FILENAME_RATING, rating);
+ dd_save_text(dd, FILENAME_RATING, rating);
/* Get the function name from the crash frame. */
if (crash_thread)
@@ -896,7 +896,7 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
if (abort_frame)
crash_frame = abort_frame->next;
if (crash_frame && crash_frame->function && 0 != strcmp(crash_frame->function, "??"))
- dd_savetxt(dd, FILENAME_CRASH_FUNCTION, crash_frame->function);
+ dd_save_text(dd, FILENAME_CRASH_FUNCTION, crash_frame->function);
}
backtrace_free(backtrace);
@@ -910,12 +910,12 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
struct strbuf *ibt = independent_backtrace(backtrace_str);
strbuf_prepend_str(ibt, executable);
strbuf_prepend_str(ibt, package);
- dd_savetxt(dd, FILENAME_GLOBAL_UUID, create_hash(ibt->buf).c_str());
+ dd_save_text(dd, FILENAME_GLOBAL_UUID, create_hash(ibt->buf).c_str());
strbuf_free(ibt);
/* Compute and store backtrace rating. */
/* Crash frame is not known so store nothing. */
- dd_savetxt(dd, FILENAME_RATING, to_string(backtrace_rate_old(backtrace_str)).c_str());
+ dd_save_text(dd, FILENAME_RATING, to_string(backtrace_rate_old(backtrace_str)).c_str());
}
free(executable);
free(package);
diff --git a/lib/plugins/Kerneloops.cpp b/lib/plugins/Kerneloops.cpp
index f6fa260..a3ef474 100644
--- a/lib/plugins/Kerneloops.cpp
+++ b/lib/plugins/Kerneloops.cpp
@@ -134,7 +134,7 @@ std::string CAnalyzerKerneloops::GetLocalUUID(const char *pDebugDumpDir)
return std::string("");
}
- char *oops = dd_loadtxt(dd, FILENAME_BACKTRACE);
+ char *oops = dd_load_text(dd, FILENAME_BACKTRACE);
unsigned hash = hash_oops_str(oops);
free(oops);
diff --git a/lib/plugins/KerneloopsScanner.cpp b/lib/plugins/KerneloopsScanner.cpp
index 1621b04..2a1bc47 100644
--- a/lib/plugins/KerneloopsScanner.cpp
+++ b/lib/plugins/KerneloopsScanner.cpp
@@ -136,14 +136,14 @@ int save_oops_to_debug_dump(const vector_string_t& oopsList)
dump_dir_t *dd = dd_init();
if (dd_create(dd, path, /*uid:*/ 0))
{
- dd_savetxt(dd, FILENAME_ANALYZER, "Kerneloops");
- dd_savetxt(dd, FILENAME_EXECUTABLE, "kernel");
- dd_savetxt(dd, FILENAME_KERNEL, first_line);
- dd_savetxt(dd, FILENAME_CMDLINE, "not_applicable");
- dd_savetxt(dd, FILENAME_BACKTRACE, second_line);
+ dd_save_text(dd, FILENAME_ANALYZER, "Kerneloops");
+ dd_save_text(dd, FILENAME_EXECUTABLE, "kernel");
+ dd_save_text(dd, FILENAME_KERNEL, first_line);
+ dd_save_text(dd, FILENAME_CMDLINE, "not_applicable");
+ dd_save_text(dd, FILENAME_BACKTRACE, second_line);
/* Optional, makes generated bz more informative */
strchrnul(second_line, '\n')[0] = '\0';
- dd_savetxt(dd, FILENAME_REASON, second_line);
+ dd_save_text(dd, FILENAME_REASON, second_line);
dd_close(dd);
}
else
diff --git a/lib/plugins/Python.cpp b/lib/plugins/Python.cpp
index d634e0c..96ba03e 100644
--- a/lib/plugins/Python.cpp
+++ b/lib/plugins/Python.cpp
@@ -34,7 +34,7 @@ string CAnalyzerPython::GetLocalUUID(const char *pDebugDumpDir)
return string("");
}
- char *bt = dd_loadtxt(dd, FILENAME_BACKTRACE);
+ char *bt = dd_load_text(dd, FILENAME_BACKTRACE);
dd_close(dd);
const char *bt_end = strchrnul(bt, '\n');
diff --git a/lib/plugins/RunApp.cpp b/lib/plugins/RunApp.cpp
index f583356..2f9d128 100644
--- a/lib/plugins/RunApp.cpp
+++ b/lib/plugins/RunApp.cpp
@@ -66,7 +66,7 @@ void CActionRunApp::Run(const char *pActionDir, const char *pArgs, int force)
return;
}
- dd_savebin(dd, args[FILENAME].c_str(), cmd_out, cmd_out_size);
+ dd_save_binary(dd, args[FILENAME].c_str(), cmd_out, cmd_out_size);
dd_close(dd);
}
diff --git a/lib/utils/DebugDump.cpp b/lib/utils/DebugDump.cpp
index 8987b43..cda1f98 100644
--- a/lib/utils/DebugDump.cpp
+++ b/lib/utils/DebugDump.cpp
@@ -34,7 +34,7 @@ static bool isdigit_str(const char *str)
return true;
}
-static char* RemoveBackSlashes(const char *pDir)
+static char* rm_trailing_slashes(const char *pDir)
{
unsigned len = strlen(pDir);
while (len != 0 && pDir[len-1] == '/')
@@ -42,7 +42,7 @@ static char* RemoveBackSlashes(const char *pDir)
return xstrndup(pDir, len);
}
-static bool ExistFileDir(const char *pPath)
+static bool exist_file_dir(const char *pPath)
{
struct stat buf;
if (stat(pPath, &buf) == 0)
@@ -55,7 +55,7 @@ static bool ExistFileDir(const char *pPath)
return false;
}
-static char *LoadTextFile(const char *path);
+static char *load_text_file(const char *path);
static void dd_lock(dump_dir_t *dd);
static void dd_unlock(dump_dir_t *dd);
@@ -85,8 +85,8 @@ int dd_opendir(dump_dir_t *dd, const char *dir)
if (dd->opened)
error_msg_and_die("CDebugDump is already opened");
- dd->dd_dir = RemoveBackSlashes(dir);
- if (!dd->dd_dir || !ExistFileDir(dd->dd_dir))
+ dd->dd_dir = rm_trailing_slashes(dir);
+ if (!dd->dd_dir || !exist_file_dir(dd->dd_dir))
{
error_msg("'%s' does not exist", dd->dd_dir);
return 0;
@@ -109,12 +109,12 @@ int dd_opendir(dump_dir_t *dd, const char *dir)
int dd_exist(dump_dir_t *dd, const char *path)
{
char *full_path = concat_path_file(dd->dd_dir, path);
- int ret = ExistFileDir(full_path);
+ int ret = exist_file_dir(full_path);
free(full_path);
return ret;
}
-static bool GetAndSetLock(const char* pLockFile, const char* pPID)
+static bool get_and_set_lock(const char* pLockFile, const char* pPID)
{
while (symlink(pPID, pLockFile) != 0)
{
@@ -232,7 +232,7 @@ static void dd_lock(dump_dir_t *dd)
char pid_buf[sizeof(long)*3 + 2];
sprintf(pid_buf, "%lu", (long)getpid());
- while ((dd->locked = GetAndSetLock(lock_buf, pid_buf)) != true)
+ while ((dd->locked = get_and_set_lock(lock_buf, pid_buf)) != true)
{
sleep(1); /* was 0.5 seconds */
}
@@ -273,8 +273,8 @@ int dd_create(dump_dir_t *dd, const char *dir, uid_t uid)
if (dd->opened)
error_msg_and_die("DebugDump is already opened");
- dd->dd_dir = RemoveBackSlashes(dir);
- if (ExistFileDir(dd->dd_dir))
+ dd->dd_dir = rm_trailing_slashes(dir);
+ if (exist_file_dir(dd->dd_dir))
{
error_msg("'%s' already exists", dd->dd_dir);
return 0;
@@ -328,7 +328,7 @@ int dd_create(dump_dir_t *dd, const char *dir, uid_t uid)
char uid_str[sizeof(long) * 3 + 2];
sprintf(uid_str, "%lu", (long)uid);
- dd_savetxt(dd, CD_UID, uid_str);
+ dd_save_text(dd, CD_UID, uid_str);
{
struct utsname buf;
@@ -336,25 +336,25 @@ int dd_create(dump_dir_t *dd, const char *dir, uid_t uid)
{
perror_msg_and_die("uname");
}
- dd_savetxt(dd, FILENAME_KERNEL, buf.release);
- dd_savetxt(dd, FILENAME_ARCHITECTURE, buf.machine);
- char *release = LoadTextFile("/etc/redhat-release");
+ dd_save_text(dd, FILENAME_KERNEL, buf.release);
+ dd_save_text(dd, FILENAME_ARCHITECTURE, buf.machine);
+ char *release = load_text_file("/etc/redhat-release");
strchrnul(release, '\n')[0] = '\0';
- dd_savetxt(dd, FILENAME_RELEASE, release);
+ dd_save_text(dd, FILENAME_RELEASE, release);
free(release);
}
time_t t = time(NULL);
char t_str[sizeof(time_t) * 3 + 2];
sprintf(t_str, "%lu", (time_t)t);
- dd_savetxt(dd, FILENAME_TIME, t_str);
+ dd_save_text(dd, FILENAME_TIME, t_str);
return 1;
}
-static bool DeleteFileDir(const char *pDir)
+static bool delete_file_dir(const char *pDir)
{
- if (!ExistFileDir(pDir))
+ if (!exist_file_dir(pDir))
return true;
DIR *d = opendir(pDir);
@@ -379,7 +379,7 @@ static bool DeleteFileDir(const char *pDir)
free(full_path);
return false;
}
- DeleteFileDir(full_path);
+ delete_file_dir(full_path);
}
free(full_path);
}
@@ -395,15 +395,15 @@ static bool DeleteFileDir(const char *pDir)
void dd_delete(dump_dir_t *dd)
{
- if (!ExistFileDir(dd->dd_dir))
+ if (!exist_file_dir(dd->dd_dir))
{
return;
}
- DeleteFileDir(dd->dd_dir);
+ delete_file_dir(dd->dd_dir);
}
-static char *LoadTextFile(const char *pPath)
+static char *load_text_file(const char *pPath)
{
FILE *fp = fopen(pPath, "r");
if (!fp)
@@ -426,7 +426,7 @@ static char *LoadTextFile(const char *pPath)
return strbuf_free_nobuf(buf_content);
}
-static bool SaveBinaryFile(const char *pPath, const char* pData, unsigned size, uid_t uid, gid_t gid)
+static bool save_binary_file(const char *pPath, const char* pData, unsigned size, uid_t uid, gid_t gid)
{
/* "Why 0640?!" See ::Create() for security analysis */
unlink(pPath);
@@ -451,35 +451,35 @@ static bool SaveBinaryFile(const char *pPath, const char* pData, unsigned size,
return true;
}
-char* dd_loadtxt(const dump_dir_t *dd, const char *name)
+char* dd_load_text(const dump_dir_t *dd, const char *name)
{
if (!dd->opened)
error_msg_and_die("DebugDump is not opened");
char *full_path = concat_path_file(dd->dd_dir, name);
- char *ret = LoadTextFile(full_path);
+ char *ret = load_text_file(full_path);
free(full_path);
return ret;
}
-void dd_savetxt(dump_dir_t *dd, const char *name, const char *data)
+void dd_save_text(dump_dir_t *dd, const char *name, const char *data)
{
if (!dd->opened)
error_msg_and_die("DebugDump is not opened");
char *full_path = concat_path_file(dd->dd_dir, name);
- SaveBinaryFile(full_path, data, strlen(data), dd->uid, dd->gid);
+ save_binary_file(full_path, data, strlen(data), dd->uid, dd->gid);
free(full_path);
}
-void dd_savebin(dump_dir_t* dd, const char* name, const char* data, unsigned size)
+void dd_save_binary(dump_dir_t* dd, const char* name, const char* data, unsigned size)
{
if (dd->opened)
error_msg_and_die("DebugDump is not opened");
char *full_path = concat_path_file(dd->dd_dir, name);
- SaveBinaryFile(full_path, data, size, dd->uid, dd->gid);
+ save_binary_file(full_path, data, size, dd->uid, dd->gid);
free(full_path);
}
diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp
index e8c7d85..65d4a4b 100644
--- a/src/daemon/MiddleWare.cpp
+++ b/src/daemon/MiddleWare.cpp
@@ -164,7 +164,7 @@ static void load_crash_data_from_debug_dump(dump_dir_t *dd, map_crash_data_t& da
if (sz < 4*1024) /* is_text_file did read entire file */
content = xstrndup(text, sz); //TODO: can avoid this copying if is_text_file() adds NUL
else /* no, need to read it all */
- content = dd_loadtxt(dd, short_name);
+ content = dd_load_text(dd, short_name);
free(text);
add_to_crash_data_ext(data,
@@ -459,17 +459,17 @@ report_status_t Report(const map_crash_data_t& client_report,
{
if (comment)
{
- dd_savetxt(dd, FILENAME_COMMENT, comment);
+ dd_save_text(dd, FILENAME_COMMENT, comment);
add_to_crash_data_ext(stored_report, FILENAME_COMMENT, CD_TXT, CD_ISEDITABLE, comment);
}
if (reproduce)
{
- dd_savetxt(dd, FILENAME_REPRODUCE, reproduce);
+ dd_save_text(dd, FILENAME_REPRODUCE, reproduce);
add_to_crash_data_ext(stored_report, FILENAME_REPRODUCE, CD_TXT, CD_ISEDITABLE, reproduce);
}
if (backtrace)
{
- dd_savetxt(dd, FILENAME_BACKTRACE, backtrace);
+ dd_save_text(dd, FILENAME_BACKTRACE, backtrace);
add_to_crash_data_ext(stored_report, FILENAME_BACKTRACE, CD_TXT, CD_ISEDITABLE, backtrace);
}
}
@@ -735,9 +735,9 @@ static mw_result_t SavePackageDescriptionToDebugDump(
return MW_ERROR;
}
- dd_savetxt(dd, FILENAME_PACKAGE, "");
- dd_savetxt(dd, FILENAME_COMPONENT, "");
- dd_savetxt(dd, FILENAME_DESCRIPTION, "Crashed executable does not belong to any installed package");
+ dd_save_text(dd, FILENAME_PACKAGE, "");
+ dd_save_text(dd, FILENAME_COMPONENT, "");
+ dd_save_text(dd, FILENAME_DESCRIPTION, "Crashed executable does not belong to any installed package");
dd_close(dd);
return MW_OK;
@@ -858,24 +858,24 @@ static mw_result_t SavePackageDescriptionToDebugDump(
{
if (rpm_pkg)
{
- dd_savetxt(dd, FILENAME_PACKAGE, rpm_pkg);
+ dd_save_text(dd, FILENAME_PACKAGE, rpm_pkg);
free(rpm_pkg);
}
if (dsc)
{
- dd_savetxt(dd, FILENAME_DESCRIPTION, dsc);
+ dd_save_text(dd, FILENAME_DESCRIPTION, dsc);
free(dsc);
}
if (component)
{
- dd_savetxt(dd, FILENAME_COMPONENT, component);
+ dd_save_text(dd, FILENAME_COMPONENT, component);
free(component);
}
if (!remote)
- dd_savetxt(dd, FILENAME_HOSTNAME, host);
+ dd_save_text(dd, FILENAME_HOSTNAME, host);
dd_close(dd);
return MW_OK;
@@ -1047,15 +1047,15 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir,
return MW_ERROR;
}
- char *time = dd_loadtxt(dd, FILENAME_TIME);
- char *uid = dd_loadtxt(dd, CD_UID);
- char *analyzer = dd_loadtxt(dd, FILENAME_ANALYZER);
- char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE);
- char *cmdline = dd_loadtxt(dd, FILENAME_CMDLINE);
+ char *time = dd_load_text(dd, FILENAME_TIME);
+ char *uid = dd_load_text(dd, CD_UID);
+ char *analyzer = dd_load_text(dd, FILENAME_ANALYZER);
+ char *executable = dd_load_text(dd, FILENAME_EXECUTABLE);
+ char *cmdline = dd_load_text(dd, FILENAME_CMDLINE);
char *remote_str = xstrdup("");
if (dd_exist(dd, FILENAME_REMOTE))
- remote_str = dd_loadtxt(dd, FILENAME_REMOTE);
+ remote_str = dd_load_text(dd, FILENAME_REMOTE);
dd_close(dd);
diff --git a/src/daemon/dumpsocket.cpp b/src/daemon/dumpsocket.cpp
index 999df00..c72e366 100644
--- a/src/daemon/dumpsocket.cpp
+++ b/src/daemon/dumpsocket.cpp
@@ -181,20 +181,20 @@ static void create_debug_dump(struct client *client)
error_msg_and_die("dumpsocket: Error while creating crash dump %s", path);
}
- dd_savetxt(dd, FILENAME_ANALYZER, client->analyzer);
- dd_savetxt(dd, FILENAME_EXECUTABLE, client->executable);
- dd_savetxt(dd, FILENAME_BACKTRACE, client->backtrace);
- dd_savetxt(dd, FILENAME_REASON, client->reason);
+ dd_save_text(dd, FILENAME_ANALYZER, client->analyzer);
+ dd_save_text(dd, FILENAME_EXECUTABLE, client->executable);
+ dd_save_text(dd, FILENAME_BACKTRACE, client->backtrace);
+ dd_save_text(dd, FILENAME_REASON, client->reason);
/* Obtain and save the command line. */
char *cmdline = get_cmdline(client->pid); // never NULL
- dd_savetxt(dd, FILENAME_CMDLINE, cmdline);
+ dd_save_text(dd, FILENAME_CMDLINE, cmdline);
free(cmdline);
/* Store id of the user whose application crashed. */
char uid_str[sizeof(long) * 3 + 2];
sprintf(uid_str, "%lu", (long)client->uid);
- dd_savetxt(dd, CD_UID, uid_str);
+ dd_save_text(dd, CD_UID, uid_str);
dd_close(dd);
diff --git a/src/hooks/abrt-hook-ccpp.cpp b/src/hooks/abrt-hook-ccpp.cpp
index 4862c6c..9a7500b 100644
--- a/src/hooks/abrt-hook-ccpp.cpp
+++ b/src/hooks/abrt-hook-ccpp.cpp
@@ -420,10 +420,10 @@ int main(int argc, char** argv)
{
char *cmdline = get_cmdline(pid); /* never NULL */
char *reason = xasprintf("Process %s was killed by signal %s (SIG%s)", executable, signal_str, signame ? signame : signal_str);
- dd_savetxt(dd, FILENAME_ANALYZER, "CCpp");
- dd_savetxt(dd, FILENAME_EXECUTABLE, executable);
- dd_savetxt(dd, FILENAME_CMDLINE, cmdline);
- dd_savetxt(dd, FILENAME_REASON, reason);
+ dd_save_text(dd, FILENAME_ANALYZER, "CCpp");
+ dd_save_text(dd, FILENAME_EXECUTABLE, executable);
+ dd_save_text(dd, FILENAME_CMDLINE, cmdline);
+ dd_save_text(dd, FILENAME_REASON, reason);
free(cmdline);
free(reason);
--
1.7.1
13 years, 8 months