This adds support for new APIs to enable XKCD mode in
other libvirt subsystems. It works by looking for the
LIBVIRT_XKCD environment variable which contains a
list of comic IDs, optionally followed by a data blob.
eg
LIBVIRT_XKCD=224:/path/to/some/script
enables support for XKCD comic 224, using /path/to/some/script
as the data item associated with it.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/Makefile.am | 2 ++
src/libvirt_private.syms | 4 +++
src/util/virxkcd.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++
src/util/virxkcd.h | 31 +++++++++++++++++
4 files changed, 123 insertions(+)
create mode 100644 src/util/virxkcd.c
create mode 100644 src/util/virxkcd.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 1726d06..d6617d5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -176,6 +176,7 @@ UTIL_SOURCES = \
util/viruuid.c util/viruuid.h \
util/virxdrdefs.h \
util/virxml.c util/virxml.h \
+ util/virxkcd.c util/virxkcd.h \
$(NULL)
EXTRA_DIST += $(srcdir)/util/keymaps.csv $(srcdir)/util/virkeycode-mapgen.py
@@ -2323,6 +2324,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
util/viruri.c \
util/virutil.c \
util/viruuid.c \
+ util/virxkcd.c \
conf/domain_event.c \
conf/network_event.c \
conf/object_event.c \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 684f06c..95f10bb 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2516,6 +2516,10 @@ virXPathULongHex;
virXPathULongLong;
+# util/virxkcd.h
+virXKCDIsEnabled;
+virXKCDGetData;
+
# Let emacs know we want case-insensitive sorting
# Local Variables:
# sort-fold-case: t
diff --git a/src/util/virxkcd.c b/src/util/virxkcd.c
new file mode 100644
index 0000000..0318b34
--- /dev/null
+++ b/src/util/virxkcd.c
@@ -0,0 +1,86 @@
+/*
+ * virxkcd.c: helpers for enabling XKCD mode features
+ *
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+
+#include "virxkcd.h"
+#include "virthread.h"
+#include "virutil.h"
+#include "virstring.h"
+
+/* Enough for a little while longer */
+static bool comics[2048];
+static char *comicData[2048];
+
+static int virXKCDOnceInit(void)
+{
+ const char *str = virGetEnvAllowSUID("LIBVIRT_XKCD");
+ char **ids, **tmp;
+ int id;
+
+ if (!str)
+ return 0;
+
+ tmp = ids = virStringSplit(str, ",", 0);
+ while (tmp && *tmp) {
+ char *sep = strchr(*tmp, ':');
+ if (sep) {
+ *sep = '\0';
+ sep++;
+ }
+ if (virStrToLong_i(*tmp, NULL, 10, &id) < 0) {
+ tmp++;
+ continue;
+ }
+ if (id >= 0 && id < ARRAY_CARDINALITY(comics)) {
+ comics[id] = true;
+ if (sep) {
+ ignore_value(VIR_STRDUP_QUIET(comicData[id],
+ sep));
+ }
+ }
+ tmp++;
+ }
+
+ virStringFreeList(ids);
+ return 0;
+}
+
+
+VIR_ONCE_GLOBAL_INIT(virXKCD);
+
+
+bool virXKCDIsEnabled(int comic)
+{
+ if (virXKCDInitialize() < 0)
+ return false;
+
+ return comics[comic];
+}
+
+
+const char *virXKCDGetData(int comic)
+{
+ if (virXKCDInitialize() < 0)
+ return false;
+
+ return comicData[comic];
+}
diff --git a/src/util/virxkcd.h b/src/util/virxkcd.h
new file mode 100644
index 0000000..a22b48d
--- /dev/null
+++ b/src/util/virxkcd.h
@@ -0,0 +1,31 @@
+/*
+ * virxkcd.h: helpers for enabling XKCD mode features
+ *
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __VIR_XKCD_H__
+#define __VIR_XKCD_H__
+
+#include "internal.h"
+
+bool virXKCDIsEnabled(int comic);
+
+const char *virXKCDGetData(int comic);
+
+#endif /* __VIR_XKCD_H__ */
--
2.5.5