From 164e97f6bca3d601c78b9585bd8e734a9ebbc9a2 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Tue, 22 Jan 2008 22:24:33 +0100 Subject: [PATCH] Added API to set the abort severity. --- demo/iso.c | 1 + src/libisofs.h | 13 +++++++++++++ src/messages.c | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/demo/iso.c b/demo/iso.c index 52b7e8b..509008b 100644 --- a/demo/iso.c +++ b/demo/iso.c @@ -143,6 +143,7 @@ int main(int argc, char **argv) iso_tree_set_ignore_hidden(image, 0); iso_tree_set_ignore_special(image, 0); iso_tree_set_stop_on_error(image, 0); + iso_set_abort_severity("SORRY"); result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[optind]); if (result < 0) { diff --git a/src/libisofs.h b/src/libisofs.h index e52db70..efaf0c4 100644 --- a/src/libisofs.h +++ b/src/libisofs.h @@ -1694,6 +1694,19 @@ int iso_obtain_msgs(char *minimum_severity, int *error_code, */ const char *iso_error_to_msg(int errcode); +/** + * Set the minimum error severity that causes a libisofs operation to + * be aborted as soon as possible. + * + * @param severity + * one of "FAILURE", "SORRY", "WARNING", "HINT", "NOTE". Severities + * greater than SORRY always cause program to abort. Severities under + * NOTE won't never cause function abort. + * @return + * Previous abort priority on success, < 0 on error. + */ +int iso_set_abort_severity(char *severity); + /** * Return the messenger object handle used by libisofs. This handle * may be used by related libraries to their own compatible diff --git a/src/messages.c b/src/messages.c index f1e0917..db25a26 100644 --- a/src/messages.c +++ b/src/messages.c @@ -19,7 +19,7 @@ int iso_message_id = LIBISO_MSGS_ORIGIN_IMAGE_BASE; /** * Threshold for aborting. */ -int abort_threshold = LIBISO_MSGS_SEV_HINT; +int abort_threshold = LIBISO_MSGS_SEV_ERROR; #define MAX_MSG_LEN 4096 @@ -41,6 +41,20 @@ void iso_finish() libiso_msgs_destroy(&libiso_msgr, 0); } +int iso_set_abort_severity(char *severity) +{ + int ret, sevno; + + ret = libiso_msgs__text_to_sev(severity, &sevno, 0); + if (ret <= 0) + return ISO_WRONG_ARG_VALUE; + if (sevno > LIBISO_MSGS_SEV_ERROR || sevno < LIBISO_MSGS_SEV_NOTE) + return ISO_WRONG_ARG_VALUE; + ret = abort_threshold; + abort_threshold = sevno; + return ret; +} + void iso_msg_debug(int imgid, const char *fmt, ...) { char msg[MAX_MSG_LEN];