xbps-bin: syslog support, enabled by default.

This commit is contained in:
Juan RP
2011-12-06 13:02:49 +01:00
parent afde2a6653
commit 3f45f563be
5 changed files with 45 additions and 1 deletions

5
NEWS
View File

@ -1,5 +1,10 @@
xbps-0.11.0 (???): 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 * xbps-repo(8): new target: pkg-list [index]. This target will list all
packages from repository with index [index]. If optional argument packages from repository with index [index]. If optional argument
[index] (decimal) not set, all repositories will be used. [index] (decimal) not set, all repositories will be used.

View File

@ -26,6 +26,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <syslog.h>
#include <xbps_api.h> #include <xbps_api.h>
#include "defs.h" #include "defs.h"
@ -38,6 +39,9 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
(void)cbdata; (void)cbdata;
if (xhp->syslog_enabled)
openlog("xbps-bin", LOG_CONS, LOG_USER);
switch (xscd->state) { switch (xscd->state) {
/* notifications */ /* notifications */
case XBPS_STATE_TRANS_DOWNLOAD: 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: case XBPS_STATE_INSTALL_DONE:
printf("Installed `%s-%s' successfully.\n", printf("Installed `%s-%s' successfully.\n",
xscd->pkgname, xscd->version); 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; break;
case XBPS_STATE_UPDATE_DONE: case XBPS_STATE_UPDATE_DONE:
printf("Updated `%s' to `%s' successfully.\n", printf("Updated `%s' to `%s' successfully.\n",
xscd->pkgname, xscd->version); 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; break;
case XBPS_STATE_REMOVE_DONE: case XBPS_STATE_REMOVE_DONE:
printf("Removed `%s-%s' successfully.\n", printf("Removed `%s-%s' successfully.\n",
xscd->pkgname, xscd->version); 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; break;
case XBPS_STATE_PURGE_DONE: case XBPS_STATE_PURGE_DONE:
printf("Purged `%s-%s' successfully.\n", printf("Purged `%s-%s' successfully.\n",
xscd->pkgname, xscd->version); 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; break;
/* errors */ /* errors */
case XBPS_STATE_UNPACK_FAIL: 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_REPOSYNC_FAIL:
case XBPS_STATE_CONFIG_FILE_FAIL: case XBPS_STATE_CONFIG_FILE_FAIL:
xbps_error_printf("%s\n", xscd->desc); xbps_error_printf("%s\n", xscd->desc);
if (xhp->syslog_enabled)
syslog(LOG_ERR, "%s", xscd->desc);
break; break;
case XBPS_STATE_REMOVE_FILE_FAIL: case XBPS_STATE_REMOVE_FILE_FAIL:
case XBPS_STATE_REMOVE_FILE_HASH_FAIL: case XBPS_STATE_REMOVE_FILE_HASH_FAIL:
@ -135,6 +157,8 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
return; return;
xbps_error_printf("%s\n", xscd->desc); xbps_error_printf("%s\n", xscd->desc);
if (xhp->syslog_enabled)
syslog(LOG_ERR, "%s", xscd->desc);
break; break;
default: default:
xbps_dbg_printf("unknown state %d\n", xscd->state); xbps_dbg_printf("unknown state %d\n", xscd->state);

View File

@ -23,5 +23,9 @@
<!-- Default timeout limit for connections, in seconds. --> <!-- Default timeout limit for connections, in seconds. -->
<key>fetch-timeout-connection</key> <key>fetch-timeout-connection</key>
<integer>30</integer> <integer>30</integer>
<!-- Enable syslog messages, set the value to false to disable. -->
<key>syslog-enabled</key>
<true/>
</dict> </dict>
</plist> </plist>

View File

@ -55,7 +55,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.3" #define XBPS_PKGINDEX_VERSION "1.3"
#define XBPS_API_VERSION "20111203" #define XBPS_API_VERSION "20111206"
#define XBPS_VERSION "0.11.0" #define XBPS_VERSION "0.11.0"
/** /**
@ -528,6 +528,14 @@ struct xbps_handle {
* it will never will be found as orphan. * it will never will be found as orphan.
*/ */
bool install_reason_manual; 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;
}; };
/** /**

View File

@ -162,6 +162,9 @@ xbps_init(struct xbps_handle *xh)
xbps_dbg_printf("fetch_timeout: %zu\n", xbps_dbg_printf("fetch_timeout: %zu\n",
xhp->fetch_timeout); 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. * Initialize regpkgdb dictionary.
*/ */