Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libalpm/alpm.h36
-rw-r--r--lib/libalpm/handle.c13
-rw-r--r--lib/libalpm/handle.h1
-rw-r--r--lib/libalpm/log.c14
-rw-r--r--src/pacman/callback.c36
-rw-r--r--src/pacman/callback.h4
-rw-r--r--src/pacman/conf.c1
-rw-r--r--src/util/cleanupdelta.c14
-rw-r--r--src/util/testdb.c14
-rw-r--r--src/util/testpkg.c14
10 files changed, 75 insertions, 72 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 751fa633..1cfd4f5b 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -343,6 +343,16 @@ typedef struct _alpm_siglist_t {
* Logging facilities
*/
+/** Logging Levels */
+typedef enum _alpm_loglevel_t {
+ ALPM_LOG_ERROR = 1,
+ ALPM_LOG_WARNING = (1 << 1),
+ ALPM_LOG_DEBUG = (1 << 2),
+ ALPM_LOG_FUNCTION = (1 << 3)
+} alpm_loglevel_t;
+
+typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list);
+
int alpm_logaction(alpm_handle_t *handle, const char *prefix,
const char *fmt, ...) __attribute__((format(printf, 3, 4)));
@@ -431,8 +441,6 @@ typedef enum _alpm_event_type_t {
ALPM_EVENT_KEY_DOWNLOAD_START,
/** Key downloading is finished. */
ALPM_EVENT_KEY_DOWNLOAD_DONE,
- /** A log message was emitted; See alpm_event_log_t for arguments. */
- ALPM_EVENT_LOG,
/** A .pacnew file was created; See alpm_event_pacnew_created_t for arguments. */
ALPM_EVENT_PACNEW_CREATED,
/** A .pacsave file was created; See alpm_event_pacsave_created_t for
@@ -502,24 +510,6 @@ typedef struct _alpm_event_database_missing_t {
const char *dbname;
} alpm_event_database_missing_t;
-/** Log levels. */
-typedef enum _alpm_loglevel_t {
- ALPM_LOG_ERROR = 1,
- ALPM_LOG_WARNING = (1 << 1),
- ALPM_LOG_DEBUG = (1 << 2),
- ALPM_LOG_FUNCTION = (1 << 3)
-} alpm_loglevel_t;
-
-typedef struct _alpm_event_log_t {
- /** Type of event. */
- alpm_event_type_t type;
- /** Log level. */
- alpm_loglevel_t level;
- /** Message. */
- const char *fmt;
- va_list args;
-} alpm_event_log_t;
-
typedef struct _alpm_event_pkgdownload_t {
/** Type of event. */
alpm_event_type_t type;
@@ -571,7 +561,6 @@ typedef union _alpm_event_t {
alpm_event_delta_patch_t delta_patch;
alpm_event_scriptlet_info_t scriptlet_info;
alpm_event_database_missing_t database_missing;
- alpm_event_log_t log;
alpm_event_pkgdownload_t pkgdownload;
alpm_event_pacnew_created_t pacnew_created;
alpm_event_pacsave_created_t pacsave_created;
@@ -749,6 +738,11 @@ char *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url);
* @{
*/
+/** Returns the callback used for logging. */
+alpm_cb_log alpm_option_get_logcb(alpm_handle_t *handle);
+/** Sets the callback used for logging. */
+int alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb);
+
/** Returns the callback used to report download progress. */
alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle);
/** Sets the callback used to report download progress. */
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 7652d1f7..0d8ea34a 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -143,6 +143,12 @@ int _alpm_handle_unlock(alpm_handle_t *handle)
}
+alpm_cb_log SYMEXPORT alpm_option_get_logcb(alpm_handle_t *handle)
+{
+ CHECK_HANDLE(handle, return NULL);
+ return handle->logcb;
+}
+
alpm_cb_download SYMEXPORT alpm_option_get_dlcb(alpm_handle_t *handle)
{
CHECK_HANDLE(handle, return NULL);
@@ -263,6 +269,13 @@ int SYMEXPORT alpm_option_get_checkspace(alpm_handle_t *handle)
return handle->checkspace;
}
+int SYMEXPORT alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb)
+{
+ CHECK_HANDLE(handle, return -1);
+ handle->logcb = cb;
+ return 0;
+}
+
int SYMEXPORT alpm_option_set_dlcb(alpm_handle_t *handle, alpm_cb_download cb)
{
CHECK_HANDLE(handle, return -1);
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 85c64f6f..9cd3a210 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -63,6 +63,7 @@ struct __alpm_handle_t {
#endif
/* callback functions */
+ alpm_cb_log logcb; /* Log callback function */
alpm_cb_download dlcb; /* Download callback function */
alpm_cb_totaldl totaldlcb; /* Total download callback function */
alpm_cb_fetch fetchcb; /* Download file callback function */
diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c
index aac55e70..d232bcc3 100644
--- a/lib/libalpm/log.c
+++ b/lib/libalpm/log.c
@@ -81,19 +81,15 @@ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix,
void _alpm_log(alpm_handle_t *handle, alpm_loglevel_t flag, const char *fmt, ...)
{
- alpm_event_log_t event = {
- .type = ALPM_EVENT_LOG,
- .level = flag,
- .fmt = fmt
- };
+ va_list args;
- if(handle == NULL || handle->eventcb == NULL) {
+ if(handle == NULL || handle->logcb == NULL) {
return;
}
- va_start(event.args, fmt);
- EVENT(handle, &event);
- va_end(event.args);
+ va_start(args, fmt);
+ handle->logcb(flag, fmt, args);
+ va_end(args);
}
/* vim: set noet: */
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 1d68db4c..4993382d 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -281,24 +281,6 @@ void cb_event(alpm_event_t *event)
event->database_missing.dbname);
}
break;
- case ALPM_EVENT_LOG:
- {
- alpm_event_log_t *e = &event->log;
- if(!e->fmt || strlen(e->fmt) == 0) {
- break;
- }
-
- if(on_progress) {
- char *string = NULL;
- pm_vasprintf(&string, e->level, e->fmt, e->args);
- if(string != NULL) {
- output = alpm_list_add(output, string);
- }
- } else {
- pm_vfprintf(stderr, e->level, e->fmt, e->args);
- }
- }
- break;
case ALPM_EVENT_PACNEW_CREATED:
{
alpm_event_pacnew_created_t *e = &event->pacnew_created;
@@ -862,4 +844,22 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
return;
}
+/* Callback to handle notifications from the library */
+void cb_log(alpm_loglevel_t level, const char *fmt, va_list args)
+{
+ if(!fmt || strlen(fmt) == 0) {
+ return;
+ }
+
+ if(on_progress) {
+ char *string = NULL;
+ pm_vasprintf(&string, level, fmt, args);
+ if(string != NULL) {
+ output = alpm_list_add(output, string);
+ }
+ } else {
+ pm_vfprintf(stderr, level, fmt, args);
+ }
+}
+
/* vim: set noet: */
diff --git a/src/pacman/callback.h b/src/pacman/callback.h
index e4941fc7..5480c73d 100644
--- a/src/pacman/callback.h
+++ b/src/pacman/callback.h
@@ -39,6 +39,10 @@ void cb_dl_total(off_t total);
/* callback to handle display of download progress */
void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total);
+/* callback to handle messages/notifications from pacman library */
+__attribute__((format(printf, 2, 0)))
+void cb_log(alpm_loglevel_t level, const char *fmt, va_list args);
+
#endif /* _PM_CALLBACK_H */
/* vim: set noet: */
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 0e483f77..8b298ccf 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -684,6 +684,7 @@ static int setup_libalpm(void)
}
config->handle = handle;
+ alpm_option_set_logcb(handle, cb_log);
alpm_option_set_dlcb(handle, cb_dl_progress);
alpm_option_set_eventcb(handle, cb_event);
alpm_option_set_questioncb(handle, cb_question);
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
index 190e2c70..4a67fc38 100644
--- a/src/util/cleanupdelta.c
+++ b/src/util/cleanupdelta.c
@@ -35,19 +35,17 @@ static void cleanup(int signum)
exit(signum);
}
-static void output_cb(alpm_event_log_t *event)
+__attribute__((format(printf, 2, 0)))
+static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
{
- if(event->type != ALPM_EVENT_LOG) {
- return;
- }
- if(strlen(event->fmt)) {
- switch(event->level) {
+ if(strlen(fmt)) {
+ switch(level) {
case ALPM_LOG_ERROR: printf("error: "); break;
case ALPM_LOG_WARNING: printf("warning: "); break;
/* case ALPM_LOG_DEBUG: printf("debug: "); break; */
default: return;
}
- vprintf(event->fmt, event->args);
+ vprintf(fmt, args);
}
}
@@ -128,7 +126,7 @@ int main(int argc, char *argv[])
}
/* let us get log messages from libalpm */
- alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb);
+ alpm_option_set_logcb(handle, output_cb);
checkdbs(dbnames);
alpm_list_free(dbnames);
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 4d1fd4c8..e3b331ab 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -39,18 +39,16 @@ static void cleanup(int signum)
exit(signum);
}
-static void output_cb(alpm_event_log_t *event)
+__attribute__((format(printf, 2, 0)))
+static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
{
- if(event->type != ALPM_EVENT_LOG) {
- return;
- }
- if(strlen(event->fmt)) {
- switch(event->level) {
+ if(strlen(fmt)) {
+ switch(level) {
case ALPM_LOG_ERROR: printf("error: "); break;
case ALPM_LOG_WARNING: printf("warning: "); break;
default: return;
}
- vprintf(event->fmt, event->args);
+ vprintf(fmt, args);
}
}
@@ -284,7 +282,7 @@ int main(int argc, char *argv[])
}
/* let us get log messages from libalpm */
- alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb);
+ alpm_option_set_logcb(handle, output_cb);
if(!dbnames) {
errors = check_localdb();
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index 39807feb..cc7d9c2b 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -23,20 +23,18 @@
#include <alpm.h>
-static void output_cb(alpm_event_log_t *event)
+__attribute__((format(printf, 2, 0)))
+static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
{
- if(event->type != ALPM_EVENT_LOG) {
+ if(fmt[0] == '\0') {
return;
}
- if(event->fmt[0] == '\0') {
- return;
- }
- switch(event->level) {
+ switch(level) {
case ALPM_LOG_ERROR: printf("error: "); break;
case ALPM_LOG_WARNING: printf("warning: "); break;
default: return; /* skip other messages */
}
- vprintf(event->fmt, event->args);
+ vprintf(fmt, args);
}
int main(int argc, char *argv[])
@@ -61,7 +59,7 @@ int main(int argc, char *argv[])
}
/* let us get log messages from libalpm */
- alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb);
+ alpm_option_set_logcb(handle, output_cb);
/* set gpgdir to default */
alpm_option_set_gpgdir(handle, GPGDIR);