This patch doesn't fix any bugs, it just makes dd_create API
easier to use.
Analogous patch for dd_opendir. Now dd_init is not needed outside of
dump_dir.c,
and thus made static.
Please review.
--
vda
diff -x '*.po' -d -urpN abrt.5/inc/dump_dir.h abrt.6/inc/dump_dir.h
--- abrt.5/inc/dump_dir.h 2010-10-14 12:09:11.364115294 +0200
+++ abrt.6/inc/dump_dir.h 2010-10-14 12:12:37.731115352 +0200
@@ -27,8 +27,7 @@ extern "C" {
#endif
enum {
- DD_CLOSE_ON_OPEN_ERR = (1 << 0),
- DD_FAIL_QUIETLY = (1 << 1),
+ DD_FAIL_QUIETLY = (1 << 0),
};
struct dump_dir {
@@ -39,10 +38,9 @@ struct dump_dir {
gid_t dd_gid;
};
-struct dump_dir *dd_init(void);
void dd_close(struct dump_dir *dd);
-int dd_opendir(struct dump_dir *dd, const char *dir, int flags);
+struct dump_dir *dd_opendir(const char *dir, int flags);
struct dump_dir *dd_create(const char *dir, uid_t uid);
int dd_exist(struct dump_dir *dd, const char *path);
DIR *dd_init_next_file(struct dump_dir *dd);
diff -x '*.po' -d -urpN abrt.5/lib/plugins/CCpp.cpp abrt.6/lib/plugins/CCpp.cpp
--- abrt.5/lib/plugins/CCpp.cpp 2010-10-14 01:14:52.950399497 +0200
+++ abrt.6/lib/plugins/CCpp.cpp 2010-10-14 12:12:37.732115122 +0200
@@ -277,8 +277,8 @@ string CAnalyzerCCpp::GetLocalUUID(const
{
string ret;
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, pDebugDumpDir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0);
+ if (!dd)
return ret; /* "" */
if (!dd_exist(dd, CD_UUID))
@@ -306,8 +306,8 @@ string CAnalyzerCCpp::GetLocalUUID(const
/* parent */
waitpid(pid, NULL, 0);
- dd = dd_init();
- if (!dd_opendir(dd, pDebugDumpDir, DD_CLOSE_ON_OPEN_ERR))
+ dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0);
+ if (!dd)
return ret; /* "" */
}
@@ -320,8 +320,8 @@ string CAnalyzerCCpp::GetLocalUUID(const
string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir)
{
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, pDebugDumpDir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0);
+ if (!dd)
return string("");
if (dd_exist(dd, FILENAME_DUPHASH))
@@ -492,8 +492,8 @@ void CAnalyzerCCpp::CreateReport(const c
return;
}
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, pDebugDumpDir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0);
+ if (!dd)
return;
if (!force)
@@ -536,8 +536,8 @@ void CAnalyzerCCpp::CreateReport(const c
/* Create and store backtrace and its hash. */
gen_backtrace(pDebugDumpDir, m_sDebugInfoDirs.c_str(), m_nGdbTimeoutSec);
- dd = dd_init();
- if (!dd_opendir(dd, pDebugDumpDir, DD_CLOSE_ON_OPEN_ERR))
+ dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0);
+ if (!dd)
{
free(build_ids);
return;
diff -x '*.po' -d -urpN abrt.5/lib/plugins/Kerneloops.cpp abrt.6/lib/plugins/Kerneloops.cpp
--- abrt.5/lib/plugins/Kerneloops.cpp 2010-09-23 16:48:44.000000000 +0200
+++ abrt.6/lib/plugins/Kerneloops.cpp 2010-10-14 12:12:37.733115591 +0200
@@ -125,8 +125,8 @@ std::string CAnalyzerKerneloops::GetLoca
{
VERB3 log("Getting local universal unique identification");
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, pDebugDumpDir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0);
+ if (!dd)
return std::string("");
char *oops = dd_load_text(dd, FILENAME_BACKTRACE);
diff -x '*.po' -d -urpN abrt.5/lib/plugins/Python.cpp abrt.6/lib/plugins/Python.cpp
--- abrt.5/lib/plugins/Python.cpp 2010-09-23 16:48:44.000000000 +0200
+++ abrt.6/lib/plugins/Python.cpp 2010-10-14 12:12:37.733115591 +0200
@@ -25,8 +25,8 @@ using namespace std;
string CAnalyzerPython::GetLocalUUID(const char *pDebugDumpDir)
{
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, pDebugDumpDir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0);
+ if (!dd)
return string("");
char *bt = dd_load_text(dd, FILENAME_BACKTRACE);
diff -x '*.po' -d -urpN abrt.5/lib/plugins/RunApp.cpp abrt.6/lib/plugins/RunApp.cpp
--- abrt.5/lib/plugins/RunApp.cpp 2010-09-23 16:48:44.000000000 +0200
+++ abrt.6/lib/plugins/RunApp.cpp 2010-10-14 12:12:37.734115152 +0200
@@ -57,8 +57,8 @@ void CActionRunApp::Run(const char *pAct
if (args.size() > FILENAME)
{
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, pActionDir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(pActionDir, /*flags:*/ 0);
+ if (!dd)
return;
dd_save_binary(dd, args[FILENAME].c_str(), cmd_out, cmd_out_size);
diff -x '*.po' -d -urpN abrt.5/lib/plugins/SOSreport.cpp abrt.6/lib/plugins/SOSreport.cpp
--- abrt.5/lib/plugins/SOSreport.cpp 2010-09-23 16:48:44.000000000 +0200
+++ abrt.6/lib/plugins/SOSreport.cpp 2010-10-14 12:12:37.735115271 +0200
@@ -50,8 +50,8 @@ void CActionSOSreport::Run(const char *p
{
if (!force)
{
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, pActionDir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(pActionDir, /*flags:*/ 0);
+ if (!dd)
return;
bool bt_exists = dd_exist(dd, "sosreport.tar.bz2") || dd_exist(dd, "sosreport.tar.xz");
diff -x '*.po' -d -urpN abrt.5/lib/utils/dump_dir.c abrt.6/lib/utils/dump_dir.c
--- abrt.5/lib/utils/dump_dir.c 2010-10-14 16:13:52.098733321 +0200
+++ abrt.6/lib/utils/dump_dir.c 2010-10-14 16:13:57.666733593 +0200
@@ -130,7 +130,7 @@ static void dd_unlock(struct dump_dir *d
}
}
-struct dump_dir *dd_init(void)
+static inline struct dump_dir *dd_init(void)
{
return (struct dump_dir*)xzalloc(sizeof(struct dump_dir));
}
@@ -167,10 +167,9 @@ static char* rm_trailing_slashes(const c
return xstrndup(dir, len);
}
-int dd_opendir(struct dump_dir *dd, const char *dir, int flags)
+struct dump_dir *dd_opendir(const char *dir, int flags)
{
- if (dd->locked)
- error_msg_and_die("dump_dir is already opened"); /* bug */
+ struct dump_dir *dd = dd_init();
/* Used to use rm_trailing_slashes(dir) here, but with dir = "."
* or "..", or if the last component is a symlink,
@@ -190,16 +189,15 @@ int dd_opendir(struct dump_dir *dd, cons
err:
if (!(flags & DD_FAIL_QUIETLY))
error_msg("'%s' does not exist", dd->dd_dir);
- if (flags & DD_CLOSE_ON_OPEN_ERR)
- dd_close(dd);
- return 0;
+ dd_close(dd);
+ return NULL;
}
/* In case caller would want to create more files, he'll need uid:gid */
dd->dd_uid = stat_buf.st_uid;
dd->dd_gid = stat_buf.st_gid;
- return 1;
+ return dd;
}
/* Create a fresh empty debug dump dir.
@@ -470,9 +468,10 @@ int dd_get_next_file(struct dump_dir *dd
/* Utility function */
void delete_debug_dump_dir(const char *dd_dir)
{
- struct dump_dir *dd = dd_init();
- if (dd_opendir(dd, dd_dir, 0))
+ struct dump_dir *dd = dd_opendir(dd_dir, /*flags:*/ 0);
+ if (dd)
+ {
dd_delete(dd);
-
- dd_close(dd);
+ dd_close(dd);
+ }
}
diff -x '*.po' -d -urpN abrt.5/src/daemon/abrt-action-analyze-c.c abrt.6/src/daemon/abrt-action-analyze-c.c
--- abrt.5/src/daemon/abrt-action-analyze-c.c 2010-10-14 01:38:35.959559038 +0200
+++ abrt.6/src/daemon/abrt-action-analyze-c.c 2010-10-14 12:12:37.736124889 +0200
@@ -47,8 +47,8 @@ static void create_hash(char hash_str[SH
static char *run_unstrip_n(const char *dump_dir_name, unsigned timeout_sec)
{
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, dump_dir_name, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
return NULL;
char *uid_str = dd_load_text(dd, CD_UID);
dd_close(dd);
@@ -189,8 +189,8 @@ int main(int argc, char **argv)
/* Hash package + executable + unstrip_n_output and save it as UUID */
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, dump_dir_name, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
return 1;
char *executable = dd_load_text(dd, FILENAME_EXECUTABLE);
diff -x '*.po' -d -urpN abrt.5/src/daemon/abrt-action-bugzilla.cpp abrt.6/src/daemon/abrt-action-bugzilla.cpp
--- abrt.5/src/daemon/abrt-action-bugzilla.cpp 2010-10-11 19:32:47.000000000 +0200
+++ abrt.6/src/daemon/abrt-action-bugzilla.cpp 2010-10-14 12:12:37.738114370 +0200
@@ -569,8 +569,8 @@ static void report_to_bugzilla(
const char *dump_dir_name,
/*const*/ map_plugin_settings_t& settings)
{
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, dump_dir_name, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
{
throw CABRTException(EXCEP_PLUGIN, _("Can't open '%s'"), dump_dir_name);
}
diff -x '*.po' -d -urpN abrt.5/src/daemon/abrt-action-generate-backtrace.c abrt.6/src/daemon/abrt-action-generate-backtrace.c
--- abrt.5/src/daemon/abrt-action-generate-backtrace.c 2010-10-13 12:07:41.000000000 +0200
+++ abrt.6/src/daemon/abrt-action-generate-backtrace.c 2010-10-14 12:12:37.738114370 +0200
@@ -283,8 +283,8 @@ int main(int argc, char **argv)
logmode = LOGMODE_SYSLOG;
}
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, dump_dir_name, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
return 1;
char *package = dd_load_text(dd, FILENAME_PACKAGE);
@@ -299,8 +299,8 @@ int main(int argc, char **argv)
VERB3 log("get_backtrace() returns NULL, broken core/gdb?");
}
- dd = dd_init();
- if (!dd_opendir(dd, dump_dir_name, DD_CLOSE_ON_OPEN_ERR))
+ dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
return 1;
dd_save_text(dd, FILENAME_BACKTRACE, backtrace_str);
diff -x '*.po' -d -urpN abrt.5/src/daemon/abrt-action-save-package-data.cpp abrt.6/src/daemon/abrt-action-save-package-data.cpp
--- abrt.5/src/daemon/abrt-action-save-package-data.cpp 2010-10-13 12:20:19.000000000 +0200
+++ abrt.6/src/daemon/abrt-action-save-package-data.cpp 2010-10-14 12:12:37.739122871 +0200
@@ -78,8 +78,8 @@ static bool is_path_blacklisted(const ch
static int SavePackageDescriptionToDebugDump(const char *dump_dir_name)
{
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, dump_dir_name, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
return 1;
char *remote_str = dd_load_text(dd, FILENAME_REMOTE);
@@ -122,8 +122,8 @@ static int SavePackageDescriptionToDebug
if (g_settings_bProcessUnpackaged || remote)
{
VERB2 log("Crash in unpackaged executable '%s', proceeding without packaging information", executable);
- dd = dd_init();
- if (!dd_opendir(dd, dump_dir_name, DD_CLOSE_ON_OPEN_ERR))
+ dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
goto ret; /* return 1 (failure) */
dd_save_text(dd, FILENAME_PACKAGE, "");
dd_save_text(dd, FILENAME_DESCRIPTION, "Crashed executable does not belong to any installed package");
@@ -224,8 +224,8 @@ static int SavePackageDescriptionToDebug
component = rpm_get_component(executable);
dsc = rpm_get_description(package_short_name);
- dd = dd_init();
- if (!dd_opendir(dd, dump_dir_name, DD_CLOSE_ON_OPEN_ERR))
+ dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
goto ret; /* return 1 (failure) */
}
diff -x '*.po' -d -urpN abrt.5/src/daemon/MiddleWare.cpp abrt.6/src/daemon/MiddleWare.cpp
--- abrt.5/src/daemon/MiddleWare.cpp 2010-10-11 19:31:22.000000000 +0200
+++ abrt.6/src/daemon/MiddleWare.cpp 2010-10-14 12:14:35.026373988 +0200
@@ -64,8 +64,8 @@ static bool DebugDumpToCrashReport(const
{
VERB3 log(" DebugDumpToCrashReport('%s')", pDebugDumpDir);
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, pDebugDumpDir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0);
+ if (!dd)
return false;
const char *const *v = must_have_files;
@@ -177,8 +177,8 @@ mw_result_t CreateCrashReport(const char
mw_result_t r = MW_OK;
try
{
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, row->db_dump_dir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(row->db_dump_dir, /*flags:*/ 0);
+ if (!dd)
{
db_row_free(row);
return MW_ERROR;
@@ -333,8 +333,8 @@ report_status_t Report(const map_crash_d
const char *backtrace = get_crash_data_item_content_or_NULL(client_report, FILENAME_BACKTRACE);
if (comment || reproduce || backtrace)
{
- struct dump_dir *dd = dd_init();
- if (dd_opendir(dd, pDumpDir.c_str(), 0))
+ struct dump_dir *dd = dd_opendir(pDumpDir.c_str(), /*flags:*/ 0);
+ if (dd)
{
if (comment)
{
@@ -351,8 +351,8 @@ report_status_t Report(const map_crash_d
dd_save_text(dd, FILENAME_BACKTRACE, backtrace);
add_to_crash_data_ext(stored_report, FILENAME_BACKTRACE, CD_TXT, CD_ISEDITABLE, backtrace);
}
+ dd_close(dd);
}
- dd_close(dd);
}
/* Remove BIN filenames from stored_report if they are not present in client's data */
@@ -700,8 +700,8 @@ mw_result_t SaveDebugDump(const char *pD
{
mw_result_t res;
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, pDebugDumpDir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(pDebugDumpDir, /*flags:*/ 0);
+ if (!dd)
return MW_ERROR;
char *time = dd_load_text(dd, FILENAME_TIME);
@@ -770,8 +770,8 @@ mw_result_t FillCrashInfo(const char *cr
if (!row)
return MW_ERROR;
- struct dump_dir *dd = dd_init();
- if (!dd_opendir(dd, row->db_dump_dir, DD_CLOSE_ON_OPEN_ERR))
+ struct dump_dir *dd = dd_opendir(row->db_dump_dir, /*flags:*/ 0);
+ if (!dd)
{
db_row_free(row);
return MW_ERROR;