diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-15 18:33:14 +0200 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-15 18:33:14 +0200 |
| commit | 46585e67644ad8edf16ff8db5602cea325a975e5 (patch) | |
| tree | 5739256404e8193abb219c42f6e291b21f947881 /lib | |
| parent | 9d9a9dd41313ed5d2e544bb3bcdf08dab6f38a48 (diff) | |
| download | abrt-46585e67644ad8edf16ff8db5602cea325a975e5.tar.gz abrt-46585e67644ad8edf16ff8db5602cea325a975e5.tar.xz abrt-46585e67644ad8edf16ff8db5602cea325a975e5.zip | |
change dd_opendir API to return dd pointer (no need to dd_init it separately)
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'lib')
| -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 |
6 files changed, 45 insertions, 46 deletions
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); + } } |
