diff options
-rw-r--r-- | inc/dump_dir.h | 6 | ||||
-rw-r--r-- | lib/plugins/CCpp.cpp | 20 | ||||
-rw-r--r-- | lib/plugins/Kerneloops.cpp | 4 | ||||
-rw-r--r-- | lib/plugins/Python.cpp | 4 | ||||
-rw-r--r-- | lib/plugins/RunApp.cpp | 4 | ||||
-rw-r--r-- | lib/plugins/SOSreport.cpp | 4 | ||||
-rw-r--r-- | lib/utils/dump_dir.c | 55 | ||||
-rw-r--r-- | src/daemon/MiddleWare.cpp | 22 | ||||
-rw-r--r-- | src/daemon/abrt-action-analyze-c.c | 8 | ||||
-rw-r--r-- | src/daemon/abrt-action-bugzilla.cpp | 4 | ||||
-rw-r--r-- | src/daemon/abrt-action-generate-backtrace.c | 8 | ||||
-rw-r--r-- | src/daemon/abrt-action-save-package-data.cpp | 12 |
12 files changed, 74 insertions, 77 deletions
diff --git a/inc/dump_dir.h b/inc/dump_dir.h index c5218a3b..10818029 100644 --- a/inc/dump_dir.h +++ b/inc/dump_dir.h @@ -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 --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp index e5b50c34..642d97e9 100644 --- a/lib/plugins/CCpp.cpp +++ b/lib/plugins/CCpp.cpp @@ -276,8 +276,8 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) { 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)) @@ -305,8 +305,8 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) /* 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; /* "" */ } @@ -319,8 +319,8 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) 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)) @@ -491,8 +491,8 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) 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) @@ -535,8 +535,8 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) /* 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 --git a/lib/plugins/Kerneloops.cpp b/lib/plugins/Kerneloops.cpp index d3ce2e8b..a847bfbf 100644 --- a/lib/plugins/Kerneloops.cpp +++ b/lib/plugins/Kerneloops.cpp @@ -125,8 +125,8 @@ std::string CAnalyzerKerneloops::GetLocalUUID(const char *pDebugDumpDir) { 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 --git a/lib/plugins/Python.cpp b/lib/plugins/Python.cpp index 77839570..ea3e1ade 100644 --- a/lib/plugins/Python.cpp +++ b/lib/plugins/Python.cpp @@ -24,8 +24,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 --git a/lib/plugins/RunApp.cpp b/lib/plugins/RunApp.cpp index 3ae6638b..b606537a 100644 --- a/lib/plugins/RunApp.cpp +++ b/lib/plugins/RunApp.cpp @@ -57,8 +57,8 @@ void CActionRunApp::Run(const char *pActionDir, const char *pArgs, int force) 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 --git a/lib/plugins/SOSreport.cpp b/lib/plugins/SOSreport.cpp index 5c1b658a..36a768fd 100644 --- a/lib/plugins/SOSreport.cpp +++ b/lib/plugins/SOSreport.cpp @@ -50,8 +50,8 @@ void CActionSOSreport::Run(const char *pActionDir, const char *pArgs, int force) { 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 --git a/lib/utils/dump_dir.c b/lib/utils/dump_dir.c index 4cba8eb1..555800c3 100644 --- a/lib/utils/dump_dir.c +++ b/lib/utils/dump_dir.c @@ -130,7 +130,7 @@ static void dd_unlock(struct dump_dir *dd) } } -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 char *dir) 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, @@ -181,30 +180,29 @@ int dd_opendir(struct dump_dir *dd, const char *dir, int flags) if (!dd->dd_dir) { if (!(flags & DD_FAIL_QUIETLY)) - error_msg("'%s' does not exist", dd_dir); - if (flags & DD_CLOSE_ON_OPEN_ERR) - dd_close(dd); - return 0; + error_msg("'%s' does not exist", dir); + dd_close(dd); + return NULL; } + dir = dd->dd_dir; dd_lock(dd); struct stat stat_buf; - if (stat(dd->dd_dir, &stat_buf) != 0 + if (stat(dir, &stat_buf) != 0 || !S_ISDIR(stat_buf.st_mode) ) { 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; + error_msg("'%s' does not exist", dir); + 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. @@ -234,19 +232,19 @@ struct dump_dir *dd_create(const char *dir, uid_t uid) * realpath will always return NULL. We don't really have to: * dd_opendir(".") makes sense, dd_create(".") does not. */ - dd->dd_dir = rm_trailing_slashes(dir); + dir = dd->dd_dir = rm_trailing_slashes(dir); - char *last_component = strrchr(dd->dd_dir, '/'); + const char *last_component = strrchr(dir, '/'); if (last_component) last_component++; else - last_component = dd->dd_dir; + last_component = dir; if (dot_or_dotdot(last_component)) { /* dd_create("."), dd_create(".."), dd_create("dir/."), * dd_create("dir/..") and similar are madness, refuse them. */ - error_msg("Bad dir name '%s'", dd->dd_dir); + error_msg("Bad dir name '%s'", dir); dd_close(dd); return NULL; } @@ -257,17 +255,17 @@ struct dump_dir *dd_create(const char *dir, uid_t uid) * 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) + if (mkdir(dir, 0750) == -1) { - perror_msg("Can't create dir '%s'", dd->dd_dir); + perror_msg("Can't create dir '%s'", dir); dd_close(dd); return NULL; } /* mkdir's mode (above) can be affected by umask, fix it */ - if (chmod(dd->dd_dir, 0750) == -1) + if (chmod(dir, 0750) == -1) { - perror_msg("Can't change mode of '%s'", dd->dd_dir); + perror_msg("Can't change mode of '%s'", dir); dd_close(dd); return NULL; } @@ -288,9 +286,9 @@ struct dump_dir *dd_create(const char *dir, uid_t uid) else error_msg("User %lu does not exist, using gid 0", (long)uid); - if (chown(dd->dd_dir, dd->dd_uid, dd->dd_gid) == -1) + if (chown(dir, dd->dd_uid, dd->dd_gid) == -1) { - perror_msg("Can't change '%s' ownership to %lu:%lu", dd->dd_dir, + perror_msg("Can't change '%s' ownership to %lu:%lu", dir, (long)dd->dd_uid, (long)dd->dd_gid); } @@ -475,9 +473,10 @@ int dd_get_next_file(struct dump_dir *dd, char **short_name, char **full_name) /* 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 --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp index f499f3b7..9e7f96ab 100644 --- a/src/daemon/MiddleWare.cpp +++ b/src/daemon/MiddleWare.cpp @@ -64,8 +64,8 @@ static bool DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_data_t& { 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 *crash_id, 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_data_t& client_report, 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_data_t& client_report, 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 *pDebugDumpDir, { 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 *crash_id, 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; diff --git a/src/daemon/abrt-action-analyze-c.c b/src/daemon/abrt-action-analyze-c.c index 08d6facc..de454daf 100644 --- a/src/daemon/abrt-action-analyze-c.c +++ b/src/daemon/abrt-action-analyze-c.c @@ -47,8 +47,8 @@ static void create_hash(char hash_str[SHA1_RESULT_LEN*2 + 1], const char *pInput 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 --git a/src/daemon/abrt-action-bugzilla.cpp b/src/daemon/abrt-action-bugzilla.cpp index c7768556..6c989ea0 100644 --- a/src/daemon/abrt-action-bugzilla.cpp +++ b/src/daemon/abrt-action-bugzilla.cpp @@ -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 --git a/src/daemon/abrt-action-generate-backtrace.c b/src/daemon/abrt-action-generate-backtrace.c index ac432a8e..9e4fc078 100644 --- a/src/daemon/abrt-action-generate-backtrace.c +++ b/src/daemon/abrt-action-generate-backtrace.c @@ -285,8 +285,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); @@ -301,8 +301,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 --git a/src/daemon/abrt-action-save-package-data.cpp b/src/daemon/abrt-action-save-package-data.cpp index b0e08fe8..4d397071 100644 --- a/src/daemon/abrt-action-save-package-data.cpp +++ b/src/daemon/abrt-action-save-package-data.cpp @@ -78,8 +78,8 @@ static bool is_path_blacklisted(const char *path) 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 SavePackageDescriptionToDebugDump(const char *dump_dir_name) 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 SavePackageDescriptionToDebugDump(const char *dump_dir_name) 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) */ } |