summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-01-27 15:59:28 +0100
committerDenys Vlasenko <dvlasenk@redhat.com>2011-01-27 15:59:28 +0100
commit5c71e00f814f679bd6ea652eda8552f746b5f725 (patch)
tree4ff1034b3133ea204081badb72df7da4fa540fef /src
parentb26f7420aca444c38677bf6275376c71ccfc39df (diff)
downloadabrt-5c71e00f814f679bd6ea652eda8552f746b5f725.tar.gz
abrt-5c71e00f814f679bd6ea652eda8552f746b5f725.tar.xz
abrt-5c71e00f814f679bd6ea652eda8552f746b5f725.zip
preparatory changes for abrt-cli local processing change
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/cli/CLI.cpp144
-rw-r--r--src/cli/Makefile.am4
-rw-r--r--src/cli/report.cpp54
-rw-r--r--src/cli/report.h5
-rw-r--r--src/daemon/MiddleWare.cpp4
-rw-r--r--src/daemon/MiddleWare.h8
-rw-r--r--src/include/report/run_event.h4
-rw-r--r--src/lib/abrt_dbus.h16
-rw-r--r--src/lib/run_event.c5
9 files changed, 76 insertions, 168 deletions
diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp
index aeb1d461..5f95c4f7 100644
--- a/src/cli/CLI.cpp
+++ b/src/cli/CLI.cpp
@@ -30,10 +30,10 @@ static char *localize_crash_time(const char *timestr)
{
long time = xatou(timestr);
char timeloc[256];
- int success = strftime(timeloc, 128, "%c", localtime(&time));
+ int success = strftime(timeloc, sizeof(timeloc), "%c", localtime(&time));
if (!success)
- error_msg_and_die("Error while converting time to string");
- return xasprintf("%s", timeloc);
+ error_msg_and_die("Error while converting time '%s' to string", timestr);
+ return xstrdup(timeloc);
}
/** Prints basic information about a crash to stdout. */
@@ -41,7 +41,7 @@ static void print_crash(crash_data_t *crash_data)
{
/* Create a localized string from crash time. */
const char *timestr = get_crash_item_content_or_die(crash_data, FILENAME_TIME);
- const char *timeloc = localize_crash_time(timestr);
+ char *timeloc = localize_crash_time(timestr);
printf(_("\tCrash dump : %s\n"
"\tUID : %s\n"
@@ -57,7 +57,7 @@ static void print_crash(crash_data_t *crash_data)
get_crash_item_content_or_NULL(crash_data, FILENAME_COUNT)
);
- free((void *)timeloc);
+ free(timeloc);
/* Print the hostname if it's available. */
const char *hostname = get_crash_item_content_or_NULL(crash_data, FILENAME_HOSTNAME);
@@ -93,7 +93,7 @@ static void print_crash_list(vector_of_crash_data_t *crash_list, bool include_re
static void print_crash_info(crash_data_t *crash_data, bool show_backtrace)
{
const char *timestr = get_crash_item_content_or_die(crash_data, FILENAME_TIME);
- const char *timeloc = localize_crash_time(timestr);
+ char *timeloc = localize_crash_time(timestr);
printf(_("Dump directory: %s\n"
"Last crash: %s\n"
@@ -116,7 +116,7 @@ static void print_crash_info(crash_data_t *crash_data, bool show_backtrace)
get_crash_item_content_or_die(crash_data, FILENAME_REASON)
);
- free((void *)timeloc);
+ free(timeloc);
/* Print optional fields only if they are available */
@@ -154,45 +154,6 @@ static void print_crash_info(crash_data_t *crash_data, bool show_backtrace)
}
}
-/**
- * Converts crash reference from user's input to crash dump dir name.
- * The returned string must be released by caller.
- */
-static char *guess_crash_id(const char *str)
-{
- vector_of_crash_data_t *ci = call_GetCrashInfos();
- unsigned num_crashinfos = ci->len;
- if (str[0] == '@') /* "--report @N" syntax */
- {
- unsigned position = xatoi_positive(str + 1);
- if (position >= num_crashinfos)
- error_msg_and_die("There are only %u crash infos", num_crashinfos);
- crash_data_t *info = get_crash_data(ci, position);
- char *res = xstrdup(get_crash_item_content_or_die(info, CD_DUMPDIR));
- free_vector_of_crash_data(ci);
- return res;
- }
-
- unsigned len = strlen(str);
- unsigned ii;
- char *result = NULL;
- for (ii = 0; ii < num_crashinfos; ii++)
- {
- crash_data_t *info = get_crash_data(ci, ii);
- const char *this_dir = get_crash_item_content_or_die(info, CD_DUMPDIR);
- if (strncmp(str, this_dir, len) == 0)
- {
- if (result)
- error_msg_and_die("Crash prefix '%s' is not unique", str);
- result = xstrdup(this_dir);
- }
- }
- free_vector_of_crash_data(ci);
- if (!result)
- error_msg_and_die("Crash dump directory '%s' not found", str);
- return result;
-}
-
/* Program options */
enum
{
@@ -247,9 +208,8 @@ static void usage(char *argv0)
/* Message has embedded tabs. */
printf(_("Usage: %s [OPTION]\n\n"
"Startup:\n"
- " -V, --version display the version of %s and exit\n"
+ " -V, --version display the version and exit\n"
" -v, --verbose increase verbosity\n"
- " -?, --help print this help\n\n"
"Actions:\n"
" -l, --list print a list of all crashes which are not yet reported\n"
" -f, --full print a list of all crashes, including the already reported ones\n"
@@ -262,14 +222,14 @@ static void usage(char *argv0)
" a name of dump directory, or\n"
" @N - N'th crash (as displayed by --list --full) will be acted upon\n"
),
- name, name);
+ name);
exit(1);
}
int main(int argc, char** argv)
{
- const char* crash_id = NULL;
+ char *dump_dir_name = NULL;
int op = -1;
bool full = false;
bool always = false;
@@ -286,16 +246,16 @@ int main(int argc, char** argv)
/* Do not use colons, arguments are handled after parsing all options. */
int c = getopt_long(argc, argv, "?Vvrdlfyib", longopts, NULL);
-#define SET_OP(newop) \
- if (op != -1 && op != newop) \
- { \
- error_msg(_("You must specify exactly one operation")); \
- return 1; \
- } \
- op = newop;
+#define SET_OP(newop) \
+ do { \
+ if (op != -1 && op != newop) \
+ error_msg_and_die(_("You must specify exactly one operation")); \
+ op = newop; \
+ } while (0)
switch (c)
{
+ case -1: goto end_of_arg_parsing;
case 'r': SET_OP(OPT_REPORT); break;
case 'd': SET_OP(OPT_DELETE); break;
case 'l': SET_OP(OPT_GET_LIST); break;
@@ -304,22 +264,20 @@ int main(int argc, char** argv)
case 'y': always = true; break;
case 'b': backtrace = true; break;
case 'v': g_verbose++; break;
- case -1: /* end of options */ break;
- default: /* some error */
- case '?':
- usage(argv[0]); /* exits app */
case 'V':
printf("%s "VERSION"\n", progname(argv[0]));
return 0;
+ case '?':
+ default: /* some error */
+ usage(argv[0]); /* exits app */
}
#undef SET_OP
- if (c == -1)
- break;
}
+ end_of_arg_parsing: ;
/* Handle option arguments. */
- int arg_count = argc - optind;
- switch (arg_count)
+ argc -= optind;
+ switch (argc)
{
case 0:
if (op == OPT_REPORT || op == OPT_DELETE || op == OPT_INFO)
@@ -328,7 +286,7 @@ int main(int argc, char** argv)
case 1:
if (op != OPT_REPORT && op != OPT_DELETE && op != OPT_INFO)
usage(argv[0]);
- crash_id = argv[optind];
+ dump_dir_name = argv[optind];
break;
default:
usage(argv[0]);
@@ -364,43 +322,18 @@ int main(int argc, char** argv)
}
case OPT_REPORT:
{
- int flags = CLI_REPORT_SILENT_IF_NOT_FOUND;
- if (always)
- flags |= CLI_REPORT_BATCH;
- exitcode = report(crash_id, flags);
- if (exitcode == -1) /* no such crash_id */
- {
- crash_id = guess_crash_id(crash_id);
- exitcode = report(crash_id, always ? CLI_REPORT_BATCH : 0);
- if (exitcode == -1)
- {
- error_msg("Crash '%s' not found", crash_id);
- free((void *)crash_id);
- xfunc_die();
- }
-
- free((void *)crash_id);
- }
+ exitcode = report(dump_dir_name, (always ? CLI_REPORT_BATCH : 0));
+ if (exitcode == -1)
+ error_msg_and_die("Crash '%s' not found", dump_dir_name);
break;
}
case OPT_DELETE:
{
- exitcode = call_DeleteDebugDump(crash_id);
+ exitcode = call_DeleteDebugDump(dump_dir_name);
if (exitcode == ENOENT)
- {
- crash_id = guess_crash_id(crash_id);
- exitcode = call_DeleteDebugDump(crash_id);
- if (exitcode == ENOENT)
- {
- error_msg("Crash '%s' not found", crash_id);
- free((void *)crash_id);
- xfunc_die();
- }
-
- free((void *)crash_id);
- }
+ error_msg_and_die("Crash '%s' not found", dump_dir_name);
if (exitcode != 0)
- error_msg_and_die("Can't delete debug dump '%s'", crash_id);
+ error_msg_and_die("Can't delete debug dump '%s'", dump_dir_name);
break;
}
case OPT_INFO:
@@ -408,20 +341,9 @@ int main(int argc, char** argv)
int old_logmode = logmode;
logmode = 0;
- crash_data_t *crash_data = call_CreateReport(crash_id);
- if (!crash_data) /* no such crash_id */
- {
- crash_id = guess_crash_id(crash_id);
- crash_data = call_CreateReport(crash_id);
- if (!crash_data)
- {
- error_msg("Crash '%s' not found", crash_id);
- free((void *)crash_id);
- xfunc_die();
- }
-
- free((void *)crash_id);
- }
+ crash_data_t *crash_data = call_CreateReport(dump_dir_name);
+ if (!crash_data)
+ error_msg_and_die("Crash '%s' not found", dump_dir_name);
logmode = old_logmode;
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index 5c1d7848..41a600c6 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -5,17 +5,17 @@ abrt_cli_SOURCES = \
run-command.h run-command.c \
report.h report.cpp \
dbus.h dbus.cpp
-
abrt_cli_CPPFLAGS = \
-I$(srcdir)/../include/report -I$(srcdir)/../include \
-I$(srcdir)/../lib \
-DVAR_RUN=\"$(VAR_RUN)\" \
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
+ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \
$(ENABLE_SOCKET_OR_DBUS) \
$(DBUS_CFLAGS) $(GLIB_CFLAGS) \
-D_GNU_SOURCE \
-Wall -Werror
# $(GTK_CFLAGS)
-
abrt_cli_LDADD = \
../lib/libreport.la \
../lib/libabrt_dbus.la \
diff --git a/src/cli/report.cpp b/src/cli/report.cpp
index d0a74955..38653e67 100644
--- a/src/cli/report.cpp
+++ b/src/cli/report.cpp
@@ -33,13 +33,10 @@ static char *trim(char *str)
return NULL;
// Remove leading spaces.
- char *ibuf;
- ibuf = skip_whitespace(str);
- int i = strlen(ibuf);
- if (str != ibuf)
- memmove(str, ibuf, i + 1);
+ overlapping_strcpy(str, skip_whitespace(str));
// Remove trailing spaces.
+ int i = strlen(str);
while (--i >= 0)
{
if (!isspace(str[i]))
@@ -450,28 +447,17 @@ static bool ask_yesno(const char *question)
}
/* Returns true if echo has been changed from another state. */
-static bool set_echo(bool enabled)
+static bool set_echo(bool enable)
{
- if (isatty(STDIN_FILENO) == 0)
- {
- /* Clean errno, which is set by isatty. */
- errno = 0;
- return false;
- }
-
struct termios t;
if (tcgetattr(STDIN_FILENO, &t) < 0)
return false;
- /* No change needed. */
- if ((bool)(t.c_lflag & ECHO) == enabled)
+ /* No change needed? */
+ if ((bool)(t.c_lflag & ECHO) == enable)
return false;
- if (enabled)
- t.c_lflag |= ECHO;
- else
- t.c_lflag &= ~ECHO;
-
+ t.c_lflag ^= ECHO;
if (tcsetattr(STDIN_FILENO, TCSANOW, &t) < 0)
perror_msg_and_die("tcsetattr");
@@ -510,7 +496,7 @@ static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters
}
/* Second, load user-specific settings, which override
- the system-wide settings. */
+ * the system-wide settings. */
struct passwd* pw = getpwuid(geteuid());
const char* homedir = pw ? pw->pw_dir : NULL;
if (homedir)
@@ -584,15 +570,11 @@ static void ask_for_missing_settings(const char *plugin_name, map_string_t &sing
}
}
-/* Reports the crash with corresponding crash_id over DBus. */
-int report(const char *crash_id, int flags)
+/* Reports the crash over DBus. */
+int report(const char *dump_dir_name, int flags)
{
- int old_logmode = logmode;
- if (flags & CLI_REPORT_SILENT_IF_NOT_FOUND)
- logmode = 0;
// Ask for an initial report.
- crash_data_t *crash_data = call_CreateReport(crash_id);
- logmode = old_logmode;
+ crash_data_t *crash_data = call_CreateReport(dump_dir_name);
if (!crash_data || g_hash_table_size(crash_data) == 0)
{
free_crash_data(crash_data);
@@ -616,7 +598,7 @@ int report(const char *crash_id, int flags)
/* Get possible reporters associated with this particular crash. */
const char *events = get_crash_item_content_or_NULL(crash_data, CD_EVENTS);
- vector_string_t reporters;
+ vector_string_t report_events;
if (events) while (*events)
{
const char *end = strchrnul(events, '\n');
@@ -624,7 +606,7 @@ int report(const char *crash_id, int flags)
&& (events[6] == '\0' || events[6] == '_')
) {
char *tmp = xstrndup(events, end - events);
- reporters.push_back(tmp);
+ report_events.push_back(tmp);
free(tmp);
}
events = end;
@@ -634,14 +616,14 @@ int report(const char *crash_id, int flags)
}
/* Get settings */
- GHashTable *reporters_settings = get_reporter_plugin_settings(reporters);
+ GHashTable *reporters_settings = get_reporter_plugin_settings(report_events);
int errors = 0;
int plugins = 0;
if (flags & CLI_REPORT_BATCH)
{
puts(_("Reporting..."));
- report_status_t r = call_Report(crash_data, reporters, reporters_settings);
+ report_status_t r = call_Report(crash_data, report_events, reporters_settings);
report_status_t::iterator it = r.begin();
while (it != r.end())
{
@@ -656,10 +638,10 @@ int report(const char *crash_id, int flags)
else
{
/* For every reporter, ask if user really wants to report using it. */
- for (vector_string_t::const_iterator it = reporters.begin(); it != reporters.end(); ++it)
+ for (vector_string_t::const_iterator it = report_events.begin(); it != report_events.end(); ++it)
{
char question[255];
- snprintf(question, 255, _("Report using %s?"), it->c_str());
+ snprintf(question, sizeof(question), _("Report using %s?"), it->c_str());
if (!ask_yesno(question))
{
puts(_("Skipping..."));
@@ -695,8 +677,8 @@ int report(const char *crash_id, int flags)
ask_for_missing_settings(it->c_str(), *settings);
- vector_string_t cur_reporter(1, *it);
- report_status_t r = call_Report(crash_data, cur_reporter, reporters_settings);
+ vector_string_t cur_event(1, *it);
+ report_status_t r = call_Report(crash_data, cur_event, reporters_settings);
assert(r.size() == 1); /* one reporter --> one report status */
vector_string_t &v = r.begin()->second;
printf("%s: %s\n", r.begin()->first.c_str(), v[REPORT_STATUS_IDX_MSG].c_str());
diff --git a/src/cli/report.h b/src/cli/report.h
index 8a851b8e..d947b6b2 100644
--- a/src/cli/report.h
+++ b/src/cli/report.h
@@ -18,11 +18,10 @@
#ifndef ABRT_CLI_REPORT_H
#define ABRT_CLI_REPORT_H
-/* Reports the crash with corresponding uuid over DBus. */
+/* Report the crash */
enum {
CLI_REPORT_BATCH = 1 << 0,
- CLI_REPORT_SILENT_IF_NOT_FOUND = 1 << 1,
};
-int report(const char *uuid, int flags);
+int report(const char *dump_dir_name, int flags);
#endif
diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp
index 2f15d50d..8b8795a2 100644
--- a/src/daemon/MiddleWare.cpp
+++ b/src/daemon/MiddleWare.cpp
@@ -781,11 +781,11 @@ void GetPluginsInfo(map_map_string_t &map_of_plugin_info)
struct dirent *dent;
while ((dent = readdir(dir)) != NULL)
{
- if (!is_regular_file(dent, PLUGINS_CONF_DIR))
- continue;
char *ext = strrchr(dent->d_name, '.');
if (!ext || strcmp(ext + 1, "conf") != 0)
continue;
+ if (!is_regular_file(dent, PLUGINS_CONF_DIR))
+ continue;
VERB3 log("Found %s", dent->d_name);
*ext = '\0';
diff --git a/src/daemon/MiddleWare.h b/src/daemon/MiddleWare.h
index 2cbf4eb5..fde29978 100644
--- a/src/daemon/MiddleWare.h
+++ b/src/daemon/MiddleWare.h
@@ -52,14 +52,12 @@ typedef enum {
* ...).
* @param crash_data
* A crash report.
- * @param reporters
- * List of allowed reporters. Which reporters will be used depends
- * on the analyzer of the crash_data. Reporters missing from this list
- * will not be used.
+ * @param events
+ * List of events to run.
* @param caller_uid
* An user uid.
* @return
- * A report status, which reporters ends successfuly with messages.
+ * A report status: which events finished successfully, with messages.
*/
report_status_t Report(crash_data_t *crash_data,
const vector_string_t& events,
diff --git a/src/include/report/run_event.h b/src/include/report/run_event.h
index b58ea66a..bab7cd2c 100644
--- a/src/include/report/run_event.h
+++ b/src/include/report/run_event.h
@@ -28,8 +28,12 @@ extern "C" {
struct dump_dir;
struct run_event_state {
+ /* Used only for post-create dup detection. TODO: document its API */
int (*post_run_callback)(const char *dump_dir_name, void *param);
void *post_run_param;
+ /* Can take ownership of log_line, which is malloced. In this case, return NULL.
+ * Otherwise should return log_line (it will be freed by caller)
+ */
char* (*logging_callback)(char *log_line, void *param);
void *logging_param;
};
diff --git a/src/lib/abrt_dbus.h b/src/lib/abrt_dbus.h
index 2723555c..24c2e9d9 100644
--- a/src/lib/abrt_dbus.h
+++ b/src/lib/abrt_dbus.h
@@ -166,7 +166,7 @@ struct abrt_dbus_type< std::map<K,V> > {
static std::string sig() { return ssprintf("a{%s%s}", ABRT_DBUS_SIG(K), ABRT_DBUS_SIG(V)); }
};
-template<typename E>
+template <typename E>
static void store_vector(DBusMessageIter* iter, const std::vector<E>& val)
{
DBusMessageIter sub_iter;
@@ -189,7 +189,7 @@ static void store_vector(DBus::MessageIter &iter, const std::vector<uint8_t>& va
if we use such vector, MUST add specialized code here (see in dbus-c++ source)
}
*/
-template<typename K, typename V>
+template <typename K, typename V>
static void store_map(DBusMessageIter* iter, const std::map<K,V>& val)
{
DBusMessageIter sub_iter;
@@ -214,9 +214,9 @@ static void store_map(DBusMessageIter* iter, const std::map<K,V>& val)
die_out_of_memory();
}
-template<typename E>
+template <typename E>
static inline void store_val(DBusMessageIter* iter, const std::vector<E>& val) { store_vector(iter, val); }
-template<typename K, typename V>
+template <typename K, typename V>
static inline void store_val(DBusMessageIter* iter, const std::map<K,V>& val) { store_map(iter, val); }
/* next patch will rewrite this into c */
@@ -267,7 +267,7 @@ static inline int load_val(DBusMessageIter* iter, std::string& val)
}
/* Templates for vector and map */
-template<typename E>
+template <typename E>
static int load_vector(DBusMessageIter* iter, std::vector<E>& val)
{
int type = dbus_message_iter_get_arg_type(iter);
@@ -306,7 +306,7 @@ static int load_vector(DBusMessageIter* iter, std::vector<uint8_t>& val)
if we use such vector, MUST add specialized code here (see in dbus-c++ source)
}
*/
-template<typename K, typename V>
+template <typename K, typename V>
static int load_map(DBusMessageIter* iter, std::map<K,V>& val)
{
int type = dbus_message_iter_get_arg_type(iter);
@@ -361,9 +361,9 @@ static int load_map(DBusMessageIter* iter, std::map<K,V>& val)
return dbus_message_iter_next(iter);
}
-template<typename E>
+template <typename E>
static inline int load_val(DBusMessageIter* iter, std::vector<E>& val) { return load_vector(iter, val); }
-template<typename K, typename V>
+template <typename K, typename V>
static inline int load_val(DBusMessageIter* iter, std::map<K,V>& val) { return load_map(iter, val); }
#endif /* __cplusplus */
diff --git a/src/lib/run_event.c b/src/lib/run_event.c
index 9d6ff161..22f61ce9 100644
--- a/src/lib/run_event.c
+++ b/src/lib/run_event.c
@@ -387,7 +387,10 @@ static void list_possible_events_helper(struct strbuf *result,
/* Does VAL match? */
if (strcmp(real_val, line_val) != 0)
{
- VERB3 log("var '%s': '%s'!='%s', skipping line", p, real_val, line_val);
+ VERB3 log("var '%s': '%.*s'!='%s', skipping line",
+ p,
+ (int)(strchrnul(real_val, '\n') - real_val), real_val,
+ line_val);
free(real_val);
goto next_line; /* no */
}