Works fine now, pushed. Thanks!
On 05/17/2013 02:56 PM, Jakub Filak wrote:
Only in case where libreport is configured to set dumpdir's owner
to
user. Users own dump directories but they cannot modify the dump
location. (Due to #583 : /var/tmp/abrt)
Closes #654
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/lib/abrt_sock.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 67 insertions(+), 2 deletions(-)
diff --git a/src/lib/abrt_sock.c b/src/lib/abrt_sock.c
index 4d197bf..b5a4e59 100644
--- a/src/lib/abrt_sock.c
+++ b/src/lib/abrt_sock.c
@@ -48,7 +48,7 @@ static int connect_to_abrtd_socket()
static int connect_to_abrtd_and_call_DeleteDebugDump(const char *dump_dir_name)
{
- int result = 1; /* error so far */
+ int result = -1; /* error so far */
int socketfd = connect_to_abrtd_socket();
if (socketfd != -1)
{
@@ -66,7 +66,14 @@ static int connect_to_abrtd_and_call_DeleteDebugDump(const char
*dump_dir_name)
/* "HTTP/1.1 200 " */
response[5] = '1';
response[7] = '1';
- result = strncmp(response, "HTTP/1.1 200 ", strlen("HTTP/1.1
200 "));
+ if (strncmp(response, "HTTP/1.1 ", strlen("HTTP/1.1 "))
== 0
+ && isdigit(response[9])
+ && isdigit(response[10])
+ && isdigit(response[11])
+ && response[12] == ' ')
+ {
+ result = (response[9] - '0') * 100 + (response[10] -
'0') * 10 + (response[11] - '0');
+ }
}
}
@@ -129,6 +136,7 @@ int problem_data_send_to_abrt(problem_data_t* problem_data)
int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name)
{
+#if DUMP_DIR_OWNED_BY_USER == 0
/* Try to delete it ourselves */
struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY);
if (dd)
@@ -150,4 +158,61 @@ int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name)
error_msg(_("Can't delete: '%s'"), dump_dir_name);
return res;
+#else
+ VERB1 log("Deleting '%s' via abrtd", dump_dir_name);
+ const int res = connect_to_abrtd_and_call_DeleteDebugDump(dump_dir_name);
+ if (res == 200)
+ {
+ /*
+ * Deleted
+ */
+ return 0;
+ }
+
+ /*
+ * An error occurred but we can still try to delete it directly
+ */
+
+ /* Using NULL in order to easily detect a buggy error message */
+ const char *error_reason = NULL;
+ /* Used only for error messages */
+ char num_buf[sizeof(int)*3 + 1];
+
+ if (res < 0 || res == 400)
+ {
+ /* -1 : an error in communication
+ * 400 : bad request or abrtd refused to delete the directory outside of the
dump location
+ *
+ * Try to delete it ourselves
+ */
+ struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY);
+ if (dd)
+ {
+ if (dd->locked) /* it is not readonly */
+ return dd_delete(dd);
+
+ error_reason = _("locked by another process");
+ dd_close(dd);
+ }
+ }
+ else
+ {
+ switch (res)
+ {
+ case 403:
+ error_reason = _("permission denied");
+ break;
+ case 404:
+ error_reason = _("not a problem directory");
+ break;
+ default:
+ snprintf(num_buf, sizeof(num_buf), "%d", res);
+ error_reason = num_buf;
+ break;
+ }
+ }
+
+ error_msg(_("Can't delete '%s': %s"), dump_dir_name,
error_reason);
+ return 1;
+#endif
}
--
Richard Marko