Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add errno to the plugin errno, directly uses the errno from the event in the frontend
Baptiste Daroussin committed 13 years ago
commit 34701dc63f0d45d880d353074b40e401301d43cb
parent 0ed55be
3 files changed +10 -4
modified libpkg/pkg.h.in
@@ -1190,6 +1190,7 @@ struct pkg_event {
			struct pkg_plugin *plugin;
			const char *func;
			const char *arg;
+
			int no;
		} e_plugin_errno;
		struct {
			struct pkg_plugin *plugin;
modified libpkg/pkg_event.c
@@ -273,10 +273,12 @@ pipeevent(struct pkg_event *ev)
		sbuf_printf(msg, "{ \"type\": \"ERROR_PLUGIN\", "
		    "\"data\": {"
		    "\"plugin\": \"%s\", "
-
		    "\"msg\": \"%s(%s)\""
+
		    "\"msg\": \"%s(%s): %s\","
+
		    "\"errno\": %d"
		    "}}",
		    pkg_plugin_get(ev->e_plugin_errno.plugin, PKG_PLUGIN_NAME),
-
		    ev->e_plugin_errno.func, ev->e_plugin_errno.arg);
+
		    ev->e_plugin_errno.func, ev->e_plugin_errno.arg,
+
		    strerror(ev->e_plugin_errno.no), ev->e_plugin_errno.no);
		break;
	case PKG_EVENT_PLUGIN_ERROR:
		sbuf_printf(msg, "{ \"type\": \"ERROR_PLUGIN\", "
@@ -592,6 +594,7 @@ pkg_plugin_errno(struct pkg_plugin *p, const char *func, const char *arg)
	ev.e_plugin_errno.plugin = p;
	ev.e_plugin_errno.func = func;
	ev.e_plugin_errno.arg = arg;
+
	ev.e_plugin_errno.no = errno;

	pkg_emit_event(&ev);
}
modified pkg/event.c
@@ -54,7 +54,8 @@ event_callback(void *data, struct pkg_event *ev)

	switch(ev->type) {
	case PKG_EVENT_ERRNO:
-
		warn("%s(%s)", ev->e_errno.func, ev->e_errno.arg);
+
		warnx("%s(%s): %s", ev->e_errno.func, ev->e_errno.arg,
+
		    strerror(ev->e_errno.no));
		break;
	case PKG_EVENT_ERROR:
		warnx("%s", ev->e_pkg_error.msg);
@@ -226,7 +227,8 @@ event_callback(void *data, struct pkg_event *ev)
		fprintf(stderr, "%s-%s: checksum mismatch for %s\n", name,
		    version, pkg_file_path(ev->e_file_mismatch.file));
	case PKG_EVENT_PLUGIN_ERRNO:
-
		warn("%s: %s(%s)", pkg_plugin_get(ev->e_plugin_errno.plugin, PKG_PLUGIN_NAME),ev->e_plugin_errno.func, ev->e_plugin_errno.arg);
+
		warnx("%s: %s(%s): %s", pkg_plugin_get(ev->e_plugin_errno.plugin, PKG_PLUGIN_NAME),
+
		    ev->e_plugin_errno.func, ev->e_plugin_errno.arg, strerror(ev->e_plugin_errno.no));
		break;
	case PKG_EVENT_PLUGIN_ERROR:
		warnx("%s: %s", pkg_plugin_get(ev->e_plugin_error.plugin, PKG_PLUGIN_NAME), ev->e_plugin_error.msg);