Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
- Add support for logging to syslog. - Including fixing pkg add logging.
Brad Davis committed 14 years ago
commit c45d973175769b8175d8f7dc5596ee1425572cb8
parent 10d2951
5 files changed +46 -3
modified libpkg/pkg.h
@@ -202,7 +202,8 @@ typedef enum _pkg_config_key {
	PKG_CONFIG_HANDLE_RC_SCRIPTS = 6,
	PKG_CONFIG_ASSUME_ALWAYS_YES = 7,
	PKG_CONFIG_REPOS = 8,
-
	PKG_CONFIG_PLIST_KEYWORDS_DIR = 9
+
	PKG_CONFIG_PLIST_KEYWORDS_DIR = 9,
+
	PKG_CONFIG_SYSLOG = 10
} pkg_config_key;

typedef enum {
modified libpkg/pkg_config.c
@@ -92,6 +92,12 @@ static struct config_entry c[] = {
		"PLIST_KEYWORDS_DIR",
		NULL,
		{ NULL }
+
	},
+
	[PKG_CONFIG_SYSLOG] = {
+
		BOOL,
+
		"SYSLOG",
+
		"YES",
+
		{ NULL }
	}
};

@@ -201,8 +207,15 @@ pkg_config_bool(pkg_config_key key, bool *val)
	if (c[key].val != NULL && (
	    strcasecmp(c[key].val, "yes") == 0 ||
	    strcasecmp(c[key].val, "true" ) == 0 ||
-
	    strcasecmp(c[key].val, "on" ) == 0))
+
	    strcasecmp(c[key].val, "on" ) == 0)) {
		*val = true;
+
	}
+
	else if (c[key].val == NULL && c[key].def != NULL && (
+
	    strcasecmp(c[key].def, "yes") == 0 ||
+
	    strcasecmp(c[key].def, "true" ) == 0 ||
+
	    strcasecmp(c[key].def, "on" ) == 0)) {
+
			*val = true;
+
	}

	return (EPKG_OK);
}
modified pkg/add.c
@@ -12,6 +12,7 @@
#include <pkg.h>

#include "add.h"
+
#include "pkg_event.h"

static int
is_url(const char * const pattern)
@@ -40,6 +41,7 @@ exec_add(int argc, char **argv)
	char *file;
	int retcode = EPKG_OK;
	int i;
+
	struct pkg *p = NULL;

	if (argc < 2) {
		usage_add();
@@ -64,9 +66,16 @@ exec_add(int argc, char **argv)
			file = path;
		} else
			file = argv[i];
+
			
+
		pkg_open(&p, file, NULL);
+
		pkg_emit_install_begin(p);

		if ((retcode = pkg_add(db, file, 0)) != EPKG_OK)
			break;
+
		
+
		if (retcode == EPKG_OK)
+
			pkg_emit_install_finished(p);
+

	}

	pkgdb_close(db);
modified pkg/event.c
@@ -1,6 +1,8 @@
#include <sys/param.h>
#include <string.h>
#include <err.h>
+
#include <syslog.h>
+
#include <stdarg.h>

#include "pkg.h"
#include "progressmeter.h"
@@ -18,6 +20,9 @@ event_callback(void *data, struct pkg_event *ev)
	int *debug = data;
	(void)debug;
	const char *name, *version, *newversion;
+
	bool syslog_enabled;
+

+
	pkg_config_bool(PKG_CONFIG_SYSLOG, &syslog_enabled);

	switch(ev->type) {
	case PKG_EVENT_ERRNO:
@@ -44,9 +49,12 @@ event_callback(void *data, struct pkg_event *ev)
		break;
	case PKG_EVENT_INSTALL_FINISHED:
		printf(" done\n");
-
		pkg_get(ev->e_install_finished.pkg, PKG_MESSAGE, &message);
+
		pkg_get(ev->e_install_finished.pkg, PKG_MESSAGE, &message,
+
			PKG_NAME, &name, PKG_VERSION, &version);
		if (message != NULL && message[0] != '\0')
			printf("%s\n", message);
+
		if (syslog_enabled)
+
			syslog(LOG_NOTICE, "Installed: %s-%s", name, version);
		break;
	case PKG_EVENT_INTEGRITYCHECK_BEGIN:
		printf("Checking integrity...");
@@ -62,6 +70,11 @@ event_callback(void *data, struct pkg_event *ev)
		break;
	case PKG_EVENT_DEINSTALL_FINISHED:
		printf(" done\n");
+
		if (syslog_enabled) {
+
			pkg_get(ev->e_deinstall_finished.pkg, PKG_NAME, &name,
+
				PKG_VERSION, &version);
+
			syslog(LOG_NOTICE, "Deinstalled: %s-%s", name, version);
+
		}
		break;
	case PKG_EVENT_UPGRADE_BEGIN:
		pkg_get(ev->e_upgrade_finished.pkg, PKG_NAME, &name, PKG_VERSION, &version,
@@ -71,6 +84,12 @@ event_callback(void *data, struct pkg_event *ev)
		break;
	case PKG_EVENT_UPGRADE_FINISHED:
		printf(" done\n");
+
		if (syslog_enabled) {
+
			pkg_get(ev->e_upgrade_finished.pkg, PKG_NAME, &name,
+
				PKG_VERSION, &version, PKG_NEWVERSION, &newversion);
+
			syslog(LOG_NOTICE, "Upgrading: %s-%s to %s-%s",
+
				name, version, name, newversion);
+
		}
		break;
	case PKG_EVENT_REQUIRED:
		pkg = ev->e_required.pkg;
modified pkg/pkg.conf.sample
@@ -11,6 +11,7 @@ PUBKEY : /etc/ssl/pkg.conf
HANDLE_RC_SCRIPTS   : NO
PKG_MULTIREPOS	    : NO
ASSUME_ALWAYS_YES   : NO
+
SYSLOG          : YES

# Repository definitions
repos: