X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fopkg_message.c;h=4cc49c3cfd7cdeaceb385836405168d203389715;hp=33a9c90e3b3eaacbb459955e804fd2afe34dc4ba;hb=19070b6c1a9718bf7ceaa61c48f328cabf1d5ca7;hpb=609411c43f5da9bc507aa04f47f9b3ba12a7f510 diff --git a/libopkg/opkg_message.c b/libopkg/opkg_message.c index 33a9c90..4cc49c3 100644 --- a/libopkg/opkg_message.c +++ b/libopkg/opkg_message.c @@ -1,5 +1,6 @@ /* opkg_message.c - the opkg package management system + Copyright (C) 2009 Ubiq Technologies Copyright (C) 2003 Daniele Nicolodi This program is free software; you can redistribute it and/or @@ -13,29 +14,102 @@ General Public License for more details. */ +#include -#include "includes.h" #include "opkg_conf.h" #include "opkg_message.h" -#include "opkg_error.h" -#include "opkg_utils.h" +#include "libbb/libbb.h" -void -opkg_message (opkg_conf_t * conf, message_level_t level, char *fmt, ...) +struct errlist { + char *errmsg; + struct errlist *next; +}; + +static struct errlist *error_list_head, *error_list_tail; + +static void push_error_list(char *msg) +{ + struct errlist *e; + + e = xcalloc(1, sizeof(struct errlist)); + e->errmsg = xstrdup(msg); + e->next = NULL; + + if (error_list_head) { + error_list_tail->next = e; + error_list_tail = e; + } else { + error_list_head = error_list_tail = e; + } +} + +void free_error_list(void) +{ + struct errlist *err, *err_tmp; + + err = error_list_head; + while (err != NULL) { + free(err->errmsg); + err_tmp = err; + err = err->next; + free(err_tmp); + } +} + +void print_error_list(void) +{ + struct errlist *err = error_list_head; + + if (err) { + fprintf(stderr, "Collected errors:\n"); + /* Here we print the errors collected and free the list */ + while (err != NULL) { + fprintf(stderr, " * %s", err->errmsg); + err = err->next; + } + } +} + +void opkg_message(message_level_t level, const char *fmt, ...) { va_list ap; - if (conf && (conf->verbosity < level)) + if (conf->verbosity < level) + return; + + if (conf->opkg_vmessage) { + /* Pass the message to libopkg users. */ + va_start(ap, fmt); + conf->opkg_vmessage(level, fmt, ap); + va_end(ap); return; + } - va_start (ap, fmt); + va_start(ap, fmt); - if (level == OPKG_ERROR) { - char msg[256]; - vsnprintf(msg, 256, fmt, ap); + if (level == ERROR) { +#define MSG_LEN 4096 + char msg[MSG_LEN]; + int ret; + ret = vsnprintf(msg, MSG_LEN, fmt, ap); + if (ret < 0) { + fprintf(stderr, "%s: encountered an output or encoding" + " error during vsnprintf.\n", __FUNCTION__); + va_end(ap); + exit(EXIT_FAILURE); + } + if (ret >= MSG_LEN) { + fprintf(stderr, "%s: Message truncated.\n", + __FUNCTION__); + } push_error_list(msg); - } else - vprintf(fmt, ap); + } else { + if (vprintf(fmt, ap) < 0) { + fprintf(stderr, "%s: encountered an output or encoding" + " error during vprintf.\n", __FUNCTION__); + exit(EXIT_FAILURE); + } + } - va_end (ap); + va_end(ap); }