summaryrefslogtreecommitdiffstats
path: root/src/CLI/CLI.cpp
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-03-04 16:19:31 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-04 16:19:31 +0100
commitafb30fe1502e9c45b722da3b5c09e292d589aa7f (patch)
tree8f0429ccc50987a34e73899c0a724ff6e0205c93 /src/CLI/CLI.cpp
parent892b7fde75cafca50a18dcb8620ddc22b2e74688 (diff)
downloadabrt-afb30fe1502e9c45b722da3b5c09e292d589aa7f.tar.gz
abrt-afb30fe1502e9c45b722da3b5c09e292d589aa7f.tar.xz
abrt-afb30fe1502e9c45b722da3b5c09e292d589aa7f.zip
*: UID:UUID -> crash_id conversion
This fixes at least three instances where we did not check whether user is even allowed to report or delete a crash. Also fixes a few cases when root might inadvertently act on (e.g. delete) mote than one crash. Renamed FILENAME_UID to CD_UID - makes more sense this way. Added COL_INFORMALL and CD_INFORMALL. Nuked UID == -1 hacks. Renamed getReport() to start_job on Python side. Dropped a few unused parameters from server -> client dbus signals. Fixed CLI's way of reverencing crashes (see updated help text). Run-tested (GUI and CLI). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> Acked-by: Nikola Pajkovsky <npajkovs@redhat.com>
Diffstat (limited to 'src/CLI/CLI.cpp')
-rw-r--r--src/CLI/CLI.cpp99
1 files changed, 61 insertions, 38 deletions
diff --git a/src/CLI/CLI.cpp b/src/CLI/CLI.cpp
index ef88732f..fcf1f0cd 100644
--- a/src/CLI/CLI.cpp
+++ b/src/CLI/CLI.cpp
@@ -73,7 +73,7 @@ static void print_crash_infos(vector_map_crash_data_t& pCrashInfos, int pMode)
"\tCrash Time : %s\n"
"\tCrash Count: %s\n"),
ii,
- get_crash_data_item_content(info, FILENAME_UID).c_str(),
+ get_crash_data_item_content(info, CD_UID).c_str(),
get_crash_data_item_content(info, CD_UUID).c_str(),
get_crash_data_item_content(info, FILENAME_PACKAGE).c_str(),
get_crash_data_item_content(info, FILENAME_EXECUTABLE).c_str(),
@@ -84,6 +84,39 @@ static void print_crash_infos(vector_map_crash_data_t& pCrashInfos, int pMode)
}
}
+static char *guess_crash_id(const char *str)
+{
+ vector_map_crash_data_t ci = call_GetCrashInfos();
+ unsigned num_crashinfos = ci.size();
+ if (str[0] == '@') /* "--report @N" syntax */
+ {
+ unsigned position = xatoi_u(str + 1);
+ if (position >= num_crashinfos)
+ error_msg_and_die("There are only %u crash infos", num_crashinfos);
+ map_crash_data_t& info = ci[position];
+ return xasprintf("%s:%s",
+ get_crash_data_item_content(info, CD_UID).c_str(),
+ get_crash_data_item_content(info, CD_UUID).c_str()
+ );
+ }
+
+ unsigned len = strlen(str);
+ unsigned ii;
+ for (ii = 0; ii < num_crashinfos; ii++)
+ {
+ map_crash_data_t& info = ci[ii];
+ const char *this_uuid = get_crash_data_item_content(info, CD_UUID).c_str();
+ if (strncmp(str, this_uuid, len) == 0)
+ {
+ return xasprintf("%s:%s",
+ get_crash_data_item_content(info, CD_UID).c_str(),
+ this_uuid
+ );
+ }
+ }
+ error_msg_and_die("Crash '%s' not found", str);
+}
+
static const struct option longopts[] =
{
/* name, has_arg, flag, val */
@@ -120,15 +153,20 @@ static void usage(char *argv0)
"Actions:\n"
" --get-list print list of crashes which are not reported yet\n"
" --get-list-full print list of all crashes\n"
- " --report UUID create and send a report\n"
- " --report-always UUID create and send a report without asking\n"
- " --delete UUID remove crash\n"),
+ " --report CRASH_ID create and send a report\n"
+ " --report-always CRASH_ID create and send a report without asking\n"
+ " --delete CRASH_ID remove crash\n"
+ "CRASH_ID may be:\n"
+ " an UID:UUID pair,\n"
+ " an UUID prefix - the first crash with matching UUID will be acted upon\n"
+ " @N - N'th crash (as displayed by --get-list-full) will be acted upon\n"
+ ),
name, name);
}
int main(int argc, char** argv)
{
- const char* uuid = NULL;
+ const char* crash_id = NULL;
int op = -1;
setlocale(LC_ALL, "");
@@ -146,7 +184,7 @@ int main(int argc, char** argv)
case OPT_REPORT:
case OPT_REPORT_ALWAYS:
case OPT_DELETE:
- uuid = optarg;
+ crash_id = optarg;
/* fall through */
case OPT_GET_LIST:
case OPT_GET_LIST_FULL:
@@ -195,45 +233,30 @@ int main(int argc, char** argv)
}
case OPT_REPORT:
case OPT_REPORT_ALWAYS:
- exitcode = report(uuid, op == OPT_REPORT_ALWAYS);
- if (exitcode == -1) /* no such UUID */
+ exitcode = report(crash_id, op == OPT_REPORT_ALWAYS);
+ if (exitcode == -1) /* no such crash_id */
{
- vector_map_crash_data_t ci = call_GetCrashInfos();
- unsigned num_crashinfos = ci.size();
- if (uuid[0] == '@') /* "--report @N" syntax */
- {
- unsigned position = xatoi_u(uuid + 1);
- if (position >= num_crashinfos)
- error_msg_and_die("There are only %u crash infos", num_crashinfos);
- map_crash_data_t& info = ci[position];
- uuid = get_crash_data_item_content(info, CD_UUID).c_str();
- } else {
- unsigned uuid_len = strlen(uuid);
- unsigned ii;
- for (ii = 0; ii < num_crashinfos; ii++)
- {
- map_crash_data_t& info = ci[ii];
- const char *this_uuid = get_crash_data_item_content(info, CD_UUID).c_str();
- if (strncmp(uuid, this_uuid, uuid_len) == 0)
- {
- uuid = this_uuid;
- goto do_report;
- }
- }
- error_msg_and_die("Crash '%s' not found", uuid);
- }
- do_report:
- exitcode = report(uuid, op == OPT_REPORT_ALWAYS);
+ crash_id = guess_crash_id(crash_id);
+ exitcode = report(crash_id, op == OPT_REPORT_ALWAYS);
if (exitcode == -1)
- error_msg_and_die("Crash '%s' not found", uuid);
+ error_msg_and_die("Crash '%s' not found", crash_id);
}
break;
case OPT_DELETE:
{
- if (call_DeleteDebugDump(uuid) != 0)
+ exitcode = call_DeleteDebugDump(crash_id);
+ if (exitcode == ENOENT)
+ {
+ crash_id = guess_crash_id(crash_id);
+ exitcode = call_DeleteDebugDump(crash_id);
+ if (exitcode == ENOENT)
+ {
+ error_msg_and_die("Crash '%s' not found", crash_id);
+ }
+ }
+ if (exitcode != 0)
{
- log("Can't delete debug dump with UUID '%s'", uuid);
- exitcode = 1;
+ error_msg_and_die("Can't delete debug dump '%s'", crash_id);
}
break;
}