* a config option DeleteUploaded was added to abrt.conf * an old behaviour of abrt-handle-upload was preserved
* /var/spool/abrt-upload is not writable by default * for more details see rhbz#836988 Signed-off-by: Jakub Filak <[email protected]> --- src/daemon/abrt-handle-upload | 32 +++++++++++++++++++++++++------- src/daemon/abrt.conf | 5 +++++ src/daemon/abrtd.c | 2 +- src/include/libabrt.h | 3 +++ src/lib/abrt_conf.c | 8 ++++++++ 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/daemon/abrt-handle-upload b/src/daemon/abrt-handle-upload index a6ab3ae..ecdae34 100755 --- a/src/daemon/abrt-handle-upload +++ b/src/daemon/abrt-handle-upload @@ -3,7 +3,15 @@ # The task of this script is to unpack the file and move # problem data found in it to abrtd spool directory. # -# Usage: abrt-handle-upload ABRT_SPOOL_DIR UPLOAD_DIR FILENAME +# Usage: abrt-handle-upload ABRT_SPOOL_DIR UPLOAD_DIR FILENAME DELETE_ARCHIVE +# +# ABRT_SPOOL_DIR - a directory where valid uploaded archives are unpacked to +# UPLOAD_DIR - a directory where uploaded archives are stored in +# FILENAME - an uploaded archive file name +# DELETE_ARCHIVE - if set to "no" an original archive is not deleted +# all other strings (an empty string is string) +# are considered as "yes" and the original archive +# is to be deleted on the end of this script #echo "Started: $0 $*" @@ -21,6 +29,7 @@ delete_on_exit="" abrt_dir="$1" upload_dir="$2" archive="$3" +delete_archive="$4" test -d "$abrt_dir" || print_clean_and_die "Not a directory: '$abrt_dir'" test -d "$upload_dir" || print_clean_and_die "Not a directory: '$upload_dir'" @@ -41,17 +50,26 @@ test x"${archive%.tar.xz}" != x"$archive" && unpacker="unxz" test "$unpacker" || print_clean_and_die "Unknown file type: '$archive'" -tempdir="remote.`date +%Y-%m-%d-%H:%M:%S.%N`.$$" +workingdir=`mktemp -d "abrt_handle_upload.XXXXXXXXXX" --tmpdir=/tmp` +[ "$?" -ne 0 ] && print_clean_and_die "Can't create '$workingdir' directory" + +delete_on_exit="$workingdir" + +tempdir="$workingdir/remote.`date +%Y-%m-%d-%H:%M:%S.%N`.$$" +archive_working="$workingdir/$archive" + +lock_cmd="mv" +if [ "$delete_archive" == "no" ]; then + lock_cmd="cp" +fi -mv -- "$archive" "$archive.working" || print_clean_and_die "Can't lock '$archive'" +$lock_cmd -- "$archive" "$archive_working" || print_clean_and_die "Can't lock '$archive'" -delete_on_exit="$archive.working" -$unpacker -t -- "$archive.working" || print_clean_and_die "Verification error on '$archive'" +$unpacker -t -- "$archive_working" || print_clean_and_die "Verification error on '$archive'" echo "Unpacking '$archive'" mkdir "$tempdir" || print_clean_and_die "Can't create '$tempdir' directory" -delete_on_exit="$archive.working $tempdir" -$unpacker <"$archive.working" | tar xf - -C "$tempdir" || print_clean_and_die "Can't unpack '$archive'" +$unpacker <"$archive_working" | tar xf - -C "$tempdir" || print_clean_and_die "Can't unpack '$archive'" # The archive can contain either plain dump files # or one or more complete problem data directories. diff --git a/src/daemon/abrt.conf b/src/daemon/abrt.conf index 9a35f0c..c7ad417 100644 --- a/src/daemon/abrt.conf +++ b/src/daemon/abrt.conf @@ -15,3 +15,8 @@ MaxCrashReportsSize = 1000 # Changing dump location could cause problems with SELinux. See man abrt_selinux(8). # #DumpLocation = /var/spool/abrt + +# If you want to automatically clean the upload directory you have to tweak the +# selinux policy. +# +DeleteUploaded = no diff --git a/src/daemon/abrtd.c b/src/daemon/abrtd.c index d4efec4..d8d1cbf 100644 --- a/src/daemon/abrtd.c +++ b/src/daemon/abrtd.c @@ -502,7 +502,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin { xchdir(dir); execlp("abrt-handle-upload", "abrt-handle-upload", - g_settings_dump_location, dir, name, (char*)NULL); + g_settings_dump_location, dir, name, g_settings_delete_uploaded ? "yes" : "no", (char*)NULL); error_msg_and_die("Can't execute '%s'", "abrt-handle-upload"); } if (pid > 0) diff --git a/src/include/libabrt.h b/src/include/libabrt.h index fff80ef..48d2ac3 100644 --- a/src/include/libabrt.h +++ b/src/include/libabrt.h @@ -56,6 +56,9 @@ extern unsigned int g_settings_nMaxCrashReportsSize; extern char * g_settings_sWatchCrashdumpArchiveDir; #define g_settings_dump_location abrt_g_settings_dump_location extern char * g_settings_dump_location; +#define g_settings_delete_uploaded abrt_g_settings_delete_uploaded +extern bool g_settings_delete_uploaded; + #define load_abrt_conf abrt_load_abrt_conf int load_abrt_conf(); diff --git a/src/lib/abrt_conf.c b/src/lib/abrt_conf.c index fc8a04f..0b53c21 100644 --- a/src/lib/abrt_conf.c +++ b/src/lib/abrt_conf.c @@ -21,6 +21,7 @@ char * g_settings_sWatchCrashdumpArchiveDir = NULL; unsigned int g_settings_nMaxCrashReportsSize = 1000; char * g_settings_dump_location = NULL; +bool g_settings_delete_uploaded = 0; void free_abrt_conf_data() { @@ -64,6 +65,13 @@ static void ParseCommon(map_string_h *settings, const char *conf_filename) else g_settings_dump_location = xstrdup("/var/spool/abrt"); + value = g_hash_table_lookup(settings, "DeleteUploaded"); + if (value) + { + g_settings_delete_uploaded = string_to_bool(value); + g_hash_table_remove(settings, "DeleteUploaded"); + } + GHashTableIter iter; char *name; /*char *value; - already declared */ -- 1.7.10.4
