From 3f45f563bec622356ea805d30036268648282444 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 6 Dec 2011 13:02:49 +0100 Subject: [PATCH] xbps-bin: syslog support, enabled by default. --- NEWS | 5 +++++ bin/xbps-bin/state_cb.c | 24 ++++++++++++++++++++++++ etc/conf.plist | 4 ++++ include/xbps_api.h | 10 +++++++++- lib/initend.c | 3 +++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 879404ba..e26c0165 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ xbps-0.11.0 (???): + * Support for syslog logging common operations, such as install, update, + remove and purge via LOG_NOTICE, and errors with LOG_ERR. + By default we enable this in configuration file `conf.plist', set the + boolean `syslog-enabled' key to false to disable. + * xbps-repo(8): new target: pkg-list [index]. This target will list all packages from repository with index [index]. If optional argument [index] (decimal) not set, all repositories will be used. diff --git a/bin/xbps-bin/state_cb.c b/bin/xbps-bin/state_cb.c index e4738575..5e673df3 100644 --- a/bin/xbps-bin/state_cb.c +++ b/bin/xbps-bin/state_cb.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "defs.h" @@ -38,6 +39,9 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata) (void)cbdata; + if (xhp->syslog_enabled) + openlog("xbps-bin", LOG_CONS, LOG_USER); + switch (xscd->state) { /* notifications */ case XBPS_STATE_TRANS_DOWNLOAD: @@ -100,18 +104,34 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata) case XBPS_STATE_INSTALL_DONE: printf("Installed `%s-%s' successfully.\n", xscd->pkgname, xscd->version); + if (xhp->syslog_enabled) + syslog(LOG_NOTICE, "Installed `%s-%s' successfully " + "(rootdir: %s).", xscd->pkgname, xscd->version, + prop_string_cstring_nocopy(xhp->rootdir)); break; case XBPS_STATE_UPDATE_DONE: printf("Updated `%s' to `%s' successfully.\n", xscd->pkgname, xscd->version); + if (xhp->syslog_enabled) + syslog(LOG_NOTICE, "Updated `%s' to `%s' successfully " + "(rootdir: %s).", xscd->pkgname, xscd->version, + prop_string_cstring_nocopy(xhp->rootdir)); break; case XBPS_STATE_REMOVE_DONE: printf("Removed `%s-%s' successfully.\n", xscd->pkgname, xscd->version); + if (xhp->syslog_enabled) + syslog(LOG_NOTICE, "Removed `%s-%s' successfully " + "(rootdir: %s).", xscd->pkgname, xscd->version, + prop_string_cstring_nocopy(xhp->rootdir)); break; case XBPS_STATE_PURGE_DONE: printf("Purged `%s-%s' successfully.\n", xscd->pkgname, xscd->version); + if (xhp->syslog_enabled) + syslog(LOG_NOTICE, "Purged `%s-%s' successfully " + "(rootdir: %s).", xscd->pkgname, xscd->version, + prop_string_cstring_nocopy(xhp->rootdir)); break; /* errors */ case XBPS_STATE_UNPACK_FAIL: @@ -126,6 +146,8 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata) case XBPS_STATE_REPOSYNC_FAIL: case XBPS_STATE_CONFIG_FILE_FAIL: xbps_error_printf("%s\n", xscd->desc); + if (xhp->syslog_enabled) + syslog(LOG_ERR, "%s", xscd->desc); break; case XBPS_STATE_REMOVE_FILE_FAIL: case XBPS_STATE_REMOVE_FILE_HASH_FAIL: @@ -135,6 +157,8 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata) return; xbps_error_printf("%s\n", xscd->desc); + if (xhp->syslog_enabled) + syslog(LOG_ERR, "%s", xscd->desc); break; default: xbps_dbg_printf("unknown state %d\n", xscd->state); diff --git a/etc/conf.plist b/etc/conf.plist index cd55fcd1..996c8b72 100644 --- a/etc/conf.plist +++ b/etc/conf.plist @@ -23,5 +23,9 @@ fetch-timeout-connection 30 + + + syslog-enabled + diff --git a/include/xbps_api.h b/include/xbps_api.h index 48463bea..49ddcba8 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -55,7 +55,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.3" -#define XBPS_API_VERSION "20111203" +#define XBPS_API_VERSION "20111206" #define XBPS_VERSION "0.11.0" /** @@ -528,6 +528,14 @@ struct xbps_handle { * it will never will be found as orphan. */ bool install_reason_manual; + /** + * @var syslog_enabled + * + * Set to true to make the client aware that some operations + * shall be sent to the syslog daemon if the option has been + * enabled in configuration file. + */ + bool syslog_enabled; }; /** diff --git a/lib/initend.c b/lib/initend.c index 075ce283..828096bb 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -162,6 +162,9 @@ xbps_init(struct xbps_handle *xh) xbps_dbg_printf("fetch_timeout: %zu\n", xhp->fetch_timeout); + prop_dictionary_get_bool(confd, "syslog-enabled", &xhp->syslog_enabled); + xbps_dbg_printf("syslog logging: %d\n", xhp->syslog_enabled); + /* * Initialize regpkgdb dictionary. */