summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-10-21 17:43:38 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-21 17:45:02 +0200
commit4ef2c83a026bc4fcc933698e1fdc0632c8d41f28 (patch)
treea009d9d97ef5b189d7cf5a16e3038dfa2635fa76
parentff49f16f9cb9b6d75d16228fb40963eee9d562ec (diff)
downloadabrt-4ef2c83a026bc4fcc933698e1fdc0632c8d41f28.tar.gz
abrt-4ef2c83a026bc4fcc933698e1fdc0632c8d41f28.tar.xz
abrt-4ef2c83a026bc4fcc933698e1fdc0632c8d41f28.zip
dump_dir: make open fail if there is no "analyzer" file.
Also adjusts abrt-action-print to return better error message: '/tmp' is not a crash dump directory 1 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--lib/utils/dump_dir.c23
-rw-r--r--src/daemon/abrt-action-print.cpp30
2 files changed, 32 insertions, 21 deletions
diff --git a/lib/utils/dump_dir.c b/lib/utils/dump_dir.c
index 555800c3..19a6c875 100644
--- a/lib/utils/dump_dir.c
+++ b/lib/utils/dump_dir.c
@@ -189,9 +189,8 @@ struct dump_dir *dd_opendir(const char *dir, int flags)
dd_lock(dd);
struct stat stat_buf;
- if (stat(dir, &stat_buf) != 0
- || !S_ISDIR(stat_buf.st_mode)
- ) {
+ if (stat(dir, &stat_buf) != 0 || !S_ISDIR(stat_buf.st_mode))
+ {
if (!(flags & DD_FAIL_QUIETLY))
error_msg("'%s' does not exist", dir);
dd_close(dd);
@@ -202,6 +201,24 @@ struct dump_dir *dd_opendir(const char *dir, int flags)
dd->dd_uid = stat_buf.st_uid;
dd->dd_gid = stat_buf.st_gid;
+ /* Without this check, e.g. abrt-action-print happily prints any current
+ * directory when run without arguments, because its option -d DIR
+ * defaults to "."! Let's require that at least some crash dump dir
+ * specific files exist before we declare open successful:
+ */
+ char *name = concat_path_file(dir, FILENAME_ANALYZER);
+ int bad = (lstat(name, &stat_buf) != 0 || !S_ISREG(stat_buf.st_mode));
+ free(name);
+ if (bad)
+ {
+ /*if (!(flags & DD_FAIL_QUIETLY))... - no, DD_FAIL_QUIETLY only means
+ * "it's ok if it doesn exist", not "ok if contents is bogus"!
+ */
+ error_msg("'%s' is not a crash dump directory", dir);
+ dd_close(dd);
+ return NULL;
+ }
+
return dd;
}
diff --git a/src/daemon/abrt-action-print.cpp b/src/daemon/abrt-action-print.cpp
index f4d5db1d..c6988921 100644
--- a/src/daemon/abrt-action-print.cpp
+++ b/src/daemon/abrt-action-print.cpp
@@ -26,22 +26,6 @@
#define PROGNAME "abrt-action-print"
-static void report_to_stdout(const char *dump_dir_name)
-{
- struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
- if (!dd)
- {
- throw CABRTException(EXCEP_PLUGIN, _("Can't open '%s'"), dump_dir_name);
- }
- map_crash_data_t pCrashData;
- load_crash_data_from_debug_dump(dd, pCrashData);
- dd_close(dd);
-
- char *dsc = make_description_logger(pCrashData);
- fputs(dsc, stdout);
- free(dsc);
-}
-
static const char *dump_dir_name = ".";
int main(int argc, char **argv)
@@ -51,7 +35,7 @@ int main(int argc, char **argv)
g_verbose = atoi(env_verbose);
const char *program_usage = _(
- PROGNAME" [v] -d DIR\n"
+ PROGNAME" [-v] -d DIR\n"
"\n"
"Print information about the crash to standard output");
enum {
@@ -71,7 +55,17 @@ int main(int argc, char **argv)
try
{
- report_to_stdout(dump_dir_name);
+ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
+ return 1; /* error message is already logged */
+
+ map_crash_data_t pCrashData;
+ load_crash_data_from_debug_dump(dd, pCrashData);
+ dd_close(dd);
+
+ char *dsc = make_description_logger(pCrashData);
+ fputs(dsc, stdout);
+ free(dsc);
}
catch (CABRTException& e)
{