]> xenbits.xensource.com Git - people/julieng/xen-unstable.git/commitdiff
tools: Refactor "xentoollog" into its own library
authorIan Campbell <ian.campbell@citrix.com>
Thu, 3 Dec 2015 11:22:02 +0000 (11:22 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 9 Dec 2015 12:37:00 +0000 (12:37 +0000)
In attempting to disaggregate libxenctrl I found that many of the
pieces were going to want access to this library, so split it out (as
it probably should always have been).

Various build adjustments are needed. In particular things which use
xtl_* themselves now need to explicity link against the library.

This has a nice side effect which is that users of libxl no longer
need to link against libxenctrl just to create a logger, which was
counter to the principal that applications using libxl shouldn't be
required to look behind the curtain. This means that xl no longer
links against libxenctrl.

The new library uses a version script to ensure that only expected
symbols are exported and to version them such that ABI guarantees can
be kept in the future.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
[ ijc -- Update QEMU_TRADITIONAL_REVISION and MINIOS_UPSTREAM_REVISION ]

21 files changed:
.gitignore
Config.mk
stubdom/Makefile
stubdom/grub/Makefile
tools/Makefile
tools/Rules.mk
tools/libs/Makefile [new file with mode: 0644]
tools/libs/toollog/Makefile [new file with mode: 0644]
tools/libs/toollog/include/xentoollog.h [new file with mode: 0644]
tools/libs/toollog/libxentoollog.map [new file with mode: 0644]
tools/libs/toollog/xtl_core.c [new file with mode: 0644]
tools/libs/toollog/xtl_logger_stdio.c [new file with mode: 0644]
tools/libxc/Makefile
tools/libxc/include/xentoollog.h [deleted file]
tools/libxc/xtl_core.c [deleted file]
tools/libxc/xtl_logger_stdio.c [deleted file]
tools/libxl/Makefile
tools/ocaml/libs/xentoollog/Makefile
tools/ocaml/libs/xentoollog/genlevels.py
tools/python/setup.py
tools/xenpaging/Makefile

index 91e1430d37cb95262ba0d02b98ea495671c248ea..a2c85e1f48b534ee3f6ec70c9581d6548bcd8bf6 100644 (file)
@@ -58,6 +58,7 @@ stubdom/gcc-*
 stubdom/include
 stubdom/ioemu
 stubdom/xenstore
+stubdom/libxentoollog-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
index 216a6422146e7537d6b30a8598b429571f189002..8fc776724b535f8316d0eb7ca4afbad65c0ade2a 100644 (file)
--- a/Config.mk
+++ b/Config.mk
@@ -255,9 +255,9 @@ MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/mini-os.git
 endif
 OVMF_UPSTREAM_REVISION ?= 52a99493cce88a9d4ec8a02d7f1bd1a1001ce60d
 QEMU_UPSTREAM_REVISION ?= master
-MINIOS_UPSTREAM_REVISION ?= bccd90071e863ec22216a000f1a07035e2f226ff
-# Mon Nov 23 16:34:31 2015 +0000
-# Add a .gitignore
+MINIOS_UPSTREAM_REVISION ?= d25773c8afa2f4dbbb466116daeb60159ddd22bd
+# Thu Dec 3 11:23:25 2015 +0000
+# mini-os: Include libxentoollog with libxc
 
 SEABIOS_UPSTREAM_REVISION ?= rel-1.9.0
 # Tue Nov 17 09:18:44 2015 -0500
@@ -266,9 +266,9 @@ SEABIOS_UPSTREAM_REVISION ?= rel-1.9.0
 ETHERBOOT_NICS ?= rtl8139 8086100e
 
 
-QEMU_TRADITIONAL_REVISION ?= 91c15bfaec1764ce2896a393eabee1183afe1130
-# Wed Dec 9 11:47:35 2015 +0000
-# net: pcnet: add check to validate receive data size(CVE-2015-7504)
+QEMU_TRADITIONAL_REVISION ?= 9fad9ed285835caef64bb8dab352e287ad8538c2
+# Thu Dec 3 11:23:16 2015 +0000
+# qemu-xen-traditional: Use xentoollog as a separate library
 
 # Specify which qemu-dm to use. This may be `ioemu' to use the old
 # Mercurial in-tree version, or a local directory, or a git URL.
index e1359cfaf7e52fd9ba62acc639289ec5acced230..9c923dd20dcf88b51b27ba2c506ec980ecea7eeb 100644 (file)
@@ -313,6 +313,11 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
          ln -sf $(wildcard $(XEN_ROOT)/tools/include/xen-foreign/*) include/xen-foreign/ && \
          $(MAKE) DESTDIR= -C include/xen-foreign/ && \
          ( [ -h include/xen/foreign ] || ln -sf ../xen-foreign include/xen/foreign )
+       mkdir -p libs-$(XEN_TARGET_ARCH)/toollog
+       [ -h libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/toollog && \
+         ln -sf $(XEN_ROOT)/tools/libs/toollog/include/*.h . && \
+         ln -sf $(XEN_ROOT)/tools/libs/toollog/*.c . && \
+         ln -sf $(XEN_ROOT)/tools/libs/toollog/Makefile . )
        mkdir -p libxc-$(XEN_TARGET_ARCH)
        [ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
          ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -335,13 +340,24 @@ $(TARGETS_MINIOS): mini-os-%:
                 mkdir -p $@/$$i ; \
        done
 
+#######
+# libxentoollog
+#######
+
+.PHONY: libxentoollog
+libxentoollog: libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a
+libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: $(NEWLIB_STAMPFILE)
+       $(MAKE) -C $(XEN_ROOT)/tools/include
+       $(MAKE) DESTDIR= -C $(MINI_OS) links
+       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog
+
 #######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog cross-zlib
        $(MAKE) -C $(XEN_ROOT)/tools/include
        $(MAKE) DESTDIR= -C $(MINI_OS) links
        CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
@@ -515,6 +531,11 @@ clean:
        $(MAKE) -C vtpmmgr clean
        rm -fr grub-$(XEN_TARGET_ARCH)
        rm -f $(STUBDOMPATH)
+       [ ! -e libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog clean
+       [ ! -e libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn clean
+       [ ! -e libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab clean
+       [ ! -e libs-$(XEN_TARGET_ARCH)/call/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call clean
+       [ ! -e libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory clean
        [ ! -e libxc-$(XEN_TARGET_ARCH)/Makefile ] || $(MAKE) DESTDIR= -C libxc-$(XEN_TARGET_ARCH) clean
        -[ ! -d ioemu ] || $(MAKE) DESTDIR= -C ioemu clean
        -[ ! -d xenstore ] || $(MAKE) DESTDIR= -C xenstore clean
@@ -525,6 +546,7 @@ crossclean: clean
        rm -fr $(CROSS_ROOT)
        rm -fr newlib-$(XEN_TARGET_ARCH)
        rm -fr zlib-$(XEN_TARGET_ARCH) pciutils-$(XEN_TARGET_ARCH)
+       rm -fr libs-$(XEN_TARGET_ARCH)
        rm -fr libxc-$(XEN_TARGET_ARCH) ioemu xenstore
        rm -fr gmp-$(XEN_TARGET_ARCH)
        rm -fr polarssl-$(XEN_TARGET_ARCH)
index 934cc4c73c81e51097a73aed66403bed41bfb3ab..26dff45a8fb95fcb762984b6dc0d1d2fb46862fb 100644 (file)
@@ -5,6 +5,7 @@ vpath %.c ../grub-upstream
 
 BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
 
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/toollog/include
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc/include -I$(XEN_ROOT)/tools/include -I.
 DEF_CPPFLAGS += -I../grub-upstream/stage1
 DEF_CPPFLAGS += -I../grub-upstream/stage2
index 820ca4044256095805267d92c2dc0a40b7499782..9f74ac7b98c17ff5b8745e0dcea77fbda1df569e 100644 (file)
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS-y :=
 SUBDIRS-y += include
+SUBDIRS-y += libs
 SUBDIRS-y += libxc
 SUBDIRS-$(FLASK_ENABLE) += flask
 SUBDIRS-y += xenstore
@@ -248,12 +249,14 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
                --includedir=$(LIBEXEC_INC) \
                --source-path=$$source \
                --extra-cflags="-I$(XEN_ROOT)/tools/include \
+               -I$(XEN_ROOT)/tools/libs/toollog/include \
                -I$(XEN_ROOT)/tools/libxc/include \
                -I$(XEN_ROOT)/tools/xenstore/include \
                -I$(XEN_ROOT)/tools/xenstore/compat/include \
                $(EXTRA_CFLAGS_QEMU_XEN)" \
                --extra-ldflags="-L$(XEN_ROOT)/tools/libxc \
                -L$(XEN_ROOT)/tools/xenstore \
+               -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
                $(QEMU_UPSTREAM_RPATH)" \
                --bindir=$(LIBEXEC_BIN) \
                --datadir=$(SHAREDIR)/qemu-xen \
index 37b0aaf78968526d6fe4f77213d2ad3edcc47362..0652e4b19f084d8391f86bf202e6c0ac7cb4a3e0 100644 (file)
@@ -10,6 +10,7 @@ export _INSTALL := $(INSTALL)
 INSTALL = $(XEN_ROOT)/tools/cross-install
 
 XEN_INCLUDE        = $(XEN_ROOT)/tools/include
+XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libs/toollog
 XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
 XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
 XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
@@ -76,10 +77,15 @@ endif
 # Consumers of libfoo should not directly use $(SHDEPS_libfoo) or
 # $(SHLIB_libfoo)
 
-CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenctrl =
-LDLIBS_libxenctrl = $(XEN_LIBXC)/libxenctrl$(libextension)
-SHLIB_libxenctrl  = -Wl,-rpath-link=$(XEN_LIBXC)
+CFLAGS_libxentoollog = -I$(XEN_LIBXENTOOLLOG)/include $(CFLAGS_xeninclude)
+SHDEPS_libxentoollog =
+LDLIBS_libxentoollog = $(XEN_LIBXENTOOLLOG)/libxentoollog$(libextension)
+SHLIB_libxentoollog  = -Wl,-rpath-link=$(XEN_LIBXENTOOLLOG)
+
+CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude)
+SHDEPS_libxenctrl = $(SHLIB_libxentoollog)
+LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension)
+SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
 
 CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_xeninclude)
 SHDEPS_libxenguest =
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
new file mode 100644 (file)
index 0000000..73be500
--- /dev/null
@@ -0,0 +1,7 @@
+XEN_ROOT = $(CURDIR)/../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SUBDIRS-y :=
+SUBDIRS-y += toollog
+
+all clean install distclean: %: subdirs-%
diff --git a/tools/libs/toollog/Makefile b/tools/libs/toollog/Makefile
new file mode 100644 (file)
index 0000000..bd12403
--- /dev/null
@@ -0,0 +1,59 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+MAJOR  = 1
+MINOR  = 0
+SHLIB_LDFLAGS += -Wl,--version-script=libxentoollog.map
+
+CFLAGS += -Werror -Wmissing-prototypes
+CFLAGS += -I./include
+
+SRCS-y += xtl_core.c
+SRCS-y += xtl_logger_stdio.c
+
+LIB_OBJS := $(patsubst %.c,%.o,$(SRCS-y))
+PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS-y))
+
+LIB := libxentoollog.a
+ifneq ($(nosharedlibs),y)
+LIB += libxentoollog.so
+endif
+
+.PHONY: all
+all: build
+
+.PHONY: build
+build:
+       $(MAKE) libs
+
+.PHONY: libs
+libs: $(LIB)
+
+libxentoollog.a: $(LIB_OBJS)
+       $(AR) rc $@ $^
+
+libxentoollog.so: libxentoollog.so.$(MAJOR)
+       $(SYMLINK_SHLIB) $< $@
+libxentoollog.so.$(MAJOR): libxentoollog.so.$(MAJOR).$(MINOR)
+       $(SYMLINK_SHLIB) $< $@
+
+libxentoollog.so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxentoollog.map
+       $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxentoollog.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(APPEND_LDFLAGS)
+
+.PHONY: install
+install: build
+       $(INSTALL_DIR) $(DESTDIR)$(libdir)
+       $(INSTALL_DIR) $(DESTDIR)$(includedir)
+       $(INSTALL_SHLIB) libxentoollog.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
+       $(INSTALL_DATA) libxentoollog.a $(DESTDIR)$(libdir)
+       $(SYMLINK_SHLIB) libxentoollog.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxentoollog.so.$(MAJOR)
+       $(SYMLINK_SHLIB) libxentoollog.so.$(MAJOR) $(DESTDIR)$(libdir)/libxentoollog.so
+       $(INSTALL_DATA) include/xentoollog.h $(DESTDIR)$(includedir)
+
+.PHONY: TAGS
+TAGS:
+       etags -t *.c *.h
+
+.PHONY: clean
+clean:
+       rm -rf *.rpm $(LIB) *~ $(DEPS) $(LIB_OBJS) $(PIC_OBJS)
diff --git a/tools/libs/toollog/include/xentoollog.h b/tools/libs/toollog/include/xentoollog.h
new file mode 100644 (file)
index 0000000..853e9c7
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * xentoollog.h
+ *
+ * Copyright (c) 2010 Citrix
+ * Part of a generic logging interface used by various dom0 userland libraries.
+ *
+ * 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;
+ * version 2.1 of the License.
+ *
+ * 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 XENTOOLLOG_H
+#define XENTOOLLOG_H
+
+#include <stdio.h>
+#include <stdarg.h>
+
+
+/*---------- common declarations and types ----------*/
+
+typedef enum xentoollog_level {
+    XTL_NONE, /* sentinel etc, never used for logging */
+    XTL_DEBUG,
+    XTL_VERBOSE,
+    XTL_DETAIL,
+    XTL_PROGRESS, /* also used for "progress" messages */
+    XTL_INFO,
+    XTL_NOTICE,
+    XTL_WARN,
+    XTL_ERROR,
+    XTL_CRITICAL,
+    XTL_NUM_LEVELS
+} xentoollog_level;
+
+typedef struct xentoollog_logger xentoollog_logger;
+struct xentoollog_logger {
+    void (*vmessage)(struct xentoollog_logger *logger,
+                     xentoollog_level level,
+                     int errnoval /* or -1 */,
+                     const char *context /* eg "xc", "xl", may be 0 */,
+                     const char *format /* without level, context, \n */,
+                     va_list al)
+         __attribute__((format(printf,5,0)));
+    void (*progress)(struct xentoollog_logger *logger,
+                     const char *context /* see above */,
+                     const char *doing_what /* no \r,\n */,
+                     int percent, unsigned long done, unsigned long total)
+         /* null function pointer is ok.
+          * will always be called with done==0 for each new
+          * context/doing_what */;
+    void (*destroy)(struct xentoollog_logger *logger);
+    /* each logger can put its necessary data here */
+};
+
+
+/*---------- facilities for consuming log messages ----------*/
+
+#define XTL_STDIOSTREAM_SHOW_PID            001u
+#define XTL_STDIOSTREAM_SHOW_DATE           002u
+#define XTL_STDIOSTREAM_HIDE_PROGRESS       004u
+#define XTL_STDIOSTREAM_PROGRESS_USE_CR     010u /* default is to */
+#define XTL_STDIOSTREAM_PROGRESS_NO_CR      020u /* use \r to ttys */
+
+typedef struct xentoollog_logger_stdiostream  xentoollog_logger_stdiostream;
+
+xentoollog_logger_stdiostream *xtl_createlogger_stdiostream
+        (FILE *f, xentoollog_level min_level, unsigned flags);
+    /* may return 0 if malloc fails, in which case error was logged */
+    /* destroy on this logger does not close the file */
+
+void xtl_stdiostream_set_minlevel(xentoollog_logger_stdiostream*,
+                                  xentoollog_level min_level);
+void xtl_stdiostream_adjust_flags(xentoollog_logger_stdiostream*,
+                                  unsigned set_flags, unsigned clear_flags);
+  /* if set_flags and clear_flags overlap, set_flags takes precedence */
+
+void xtl_logger_destroy(struct xentoollog_logger *logger /* 0 is ok */);
+
+
+/*---------- facilities for generating log messages ----------*/
+
+void xtl_logv(struct xentoollog_logger *logger,
+              xentoollog_level level,
+              int errnoval /* or -1 */,
+              const char *context /* eg "xc", "xenstore", "xl", may be 0 */,
+              const char *format /* does not contain \n */,
+              va_list) __attribute__((format(printf,5,0)));
+
+void xtl_log(struct xentoollog_logger *logger,
+             xentoollog_level level,
+             int errnoval /* or -1 */,
+             const char *context /* eg "xc", "xenstore", "xl" */,
+             const char *format /* does not contain \n */,
+             ...) __attribute__((format(printf,5,6)));
+
+void xtl_progress(struct xentoollog_logger *logger,
+                  const char *context /* see above, may be 0 */,
+                  const char *doing_what,
+                  unsigned long done, unsigned long total);
+
+
+/*---------- facilities for defining log message consumers ----------*/
+
+const char *xtl_level_to_string(xentoollog_level); /* never fails */
+
+
+#define XTL_NEW_LOGGER(LOGGER,buffer) ({                                \
+    xentoollog_logger_##LOGGER *new_consumer;                           \
+                                                                        \
+    (buffer).vtable.vmessage = LOGGER##_vmessage;                       \
+    (buffer).vtable.progress = LOGGER##_progress;                       \
+    (buffer).vtable.destroy  = LOGGER##_destroy;                        \
+                                                                        \
+    new_consumer = malloc(sizeof(*new_consumer));                       \
+    if (!new_consumer) {                                                \
+        xtl_log((xentoollog_logger*)&buffer,                            \
+                XTL_CRITICAL, errno, "xtl",                             \
+                "failed to allocate memory for new message logger");    \
+    } else {                                                            \
+        *new_consumer = buffer;                                         \
+    }                                                                   \
+                                                                        \
+    new_consumer;                                                       \
+});
+
+
+#endif /* XENTOOLLOG_H */
diff --git a/tools/libs/toollog/libxentoollog.map b/tools/libs/toollog/libxentoollog.map
new file mode 100644 (file)
index 0000000..c183cf5
--- /dev/null
@@ -0,0 +1,12 @@
+VERS_1.0 {
+       global:
+               xtl_createlogger_stdiostream;
+               xtl_level_to_string;
+               xtl_log;
+               xtl_logger_destroy;
+               xtl_logv;
+               xtl_progress;
+               xtl_stdiostream_adjust_flags;
+               xtl_stdiostream_set_minlevel;
+       local: *; /* Do not expose anything by default */
+};
diff --git a/tools/libs/toollog/xtl_core.c b/tools/libs/toollog/xtl_core.c
new file mode 100644 (file)
index 0000000..c4724a0
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * xtl_core.c
+ *
+ * core code including functions for generating log messages
+ *
+ * Copyright (c) 2010 Citrix
+ * Part of a generic logging interface used by various dom0 userland libraries.
+ *
+ * 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;
+ * version 2.1 of the License.
+ *
+ * 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 "xentoollog.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+
+static const char *level_strings[XTL_NUM_LEVELS]= {
+    "[BUG:XTL_NONE]",
+    "debug", "verbose", "detail",  /* normally off by default */
+    "progress", "info", "notice",  /* not a problem */
+    "warning", "error", "critical" /* problems and errors */
+};
+
+const char *xtl_level_to_string(xentoollog_level level) {
+    assert(level >= 0 && level < XTL_NUM_LEVELS);
+    return level_strings[level];
+}
+
+void xtl_logv(struct xentoollog_logger *logger,
+              xentoollog_level level,
+              int errnoval /* or -1 */,
+              const char *context /* eg "xc", "xenstore", "xl" */,
+              const char *format /* does not contain \n */,
+              va_list al) {
+    int errno_save = errno;
+    assert(level > XTL_NONE && level < XTL_NUM_LEVELS);
+    logger->vmessage(logger,level,errnoval,context,format,al);
+    errno = errno_save;
+}
+
+void xtl_log(struct xentoollog_logger *logger,
+             xentoollog_level level,
+             int errnoval /* or -1 */,
+             const char *context /* eg "xc", "xenstore", "xl" */,
+             const char *format /* does not contain \n */,
+             ...) {
+    va_list al;
+    va_start(al,format);
+    xtl_logv(logger,level,errnoval,context,format,al);
+    va_end(al);
+}
+
+void xtl_progress(struct xentoollog_logger *logger,
+                  const char *context, const char *doing_what,
+                  unsigned long done, unsigned long total) {
+    int percent = 0;
+
+    if (!logger->progress) return;
+
+    if ( total )
+        percent = (total < LONG_MAX/100)
+            ? (done * 100) / total
+            : done / ((total + 99) / 100);
+
+    logger->progress(logger, context, doing_what, percent, done, total);
+}
+
+void xtl_logger_destroy(struct xentoollog_logger *logger) {
+    if (!logger) return;
+    logger->destroy(logger);
+}
diff --git a/tools/libs/toollog/xtl_logger_stdio.c b/tools/libs/toollog/xtl_logger_stdio.c
new file mode 100644 (file)
index 0000000..0cd9206
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * xtl_logger_stdio.c
+ *
+ * log message consumer that writes to stdio
+ *
+ * Copyright (c) 2010 Citrix
+ * Part of a generic logging interface used by various dom0 userland libraries.
+ *
+ * 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;
+ * version 2.1 of the License.
+ *
+ * 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 "xentoollog.h"
+
+#include <time.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdbool.h>
+
+struct xentoollog_logger_stdiostream {
+    xentoollog_logger vtable;
+    FILE *f;
+    xentoollog_level min_level;
+    unsigned flags;
+    int progress_erase_len, progress_last_percent;
+    bool progress_use_cr;
+};
+
+static void progress_erase(xentoollog_logger_stdiostream *lg) {
+    if (lg->progress_erase_len)
+        fprintf(lg->f, "\r%*s\r", lg->progress_erase_len, "");
+}
+
+static void stdiostream_vmessage(xentoollog_logger *logger_in,
+                                 xentoollog_level level,
+                                 int errnoval,
+                                 const char *context,
+                                 const char *format,
+                                 va_list al) {
+    xentoollog_logger_stdiostream *lg = (void*)logger_in;
+
+    if (level < lg->min_level)
+        return;
+
+    progress_erase(lg);
+
+    if (lg->flags & XTL_STDIOSTREAM_SHOW_DATE) {
+        struct tm lt_buf;
+        time_t now = time(0);
+        struct tm *lt= localtime_r(&now, &lt_buf);
+        if (lt != NULL)
+            fprintf(lg->f, "%04d-%02d-%02d %02d:%02d:%02d %s ",
+                    lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday,
+                    lt->tm_hour, lt->tm_min, lt->tm_sec,
+                    tzname[!!lt->tm_isdst]);
+        else
+            fprintf(lg->f, "[localtime_r failed: %d] ", errno);
+    }
+    if (lg->flags & XTL_STDIOSTREAM_SHOW_PID)
+        fprintf(lg->f, "[%lu] ", (unsigned long)getpid());
+
+    if (context)
+        fprintf(lg->f, "%s: ", context);
+
+    fprintf(lg->f, "%s: ", xtl_level_to_string(level));
+
+    vfprintf(lg->f, format, al);
+
+    if (errnoval >= 0)
+        fprintf(lg->f, ": %s", strerror(errnoval));
+
+    putc('\n', lg->f);
+    fflush(lg->f);
+}
+
+static void stdiostream_message(struct xentoollog_logger *logger_in,
+                                xentoollog_level level,
+                                const char *context,
+                                const char *format, ...)
+{
+    va_list al;
+    va_start(al,format);
+    stdiostream_vmessage(logger_in, level, -1, context, format, al);
+    va_end(al);
+}
+
+static void stdiostream_progress(struct xentoollog_logger *logger_in,
+                                 const char *context,
+                                 const char *doing_what, int percent,
+                                 unsigned long done, unsigned long total) {
+    xentoollog_logger_stdiostream *lg = (void*)logger_in;
+    int newpel, extra_erase;
+    xentoollog_level this_level;
+
+    if (lg->flags & XTL_STDIOSTREAM_HIDE_PROGRESS)
+        return;
+
+    if (percent < lg->progress_last_percent) {
+        this_level = XTL_PROGRESS;
+    } else if (percent == lg->progress_last_percent) {
+        return;
+    } else if (percent < lg->progress_last_percent + 5) {
+        this_level = XTL_DETAIL;
+    } else {
+        this_level = XTL_PROGRESS;
+    }
+
+    if (this_level < lg->min_level)
+        return;
+
+    lg->progress_last_percent = percent;
+
+    if (!lg->progress_use_cr) {
+        stdiostream_message(logger_in, this_level, context,
+                            "%s: %lu/%lu  %3d%%",
+                            doing_what, done, total, percent);
+        return;
+    }
+
+    if (lg->progress_erase_len)
+        putc('\r', lg->f);
+
+    newpel = fprintf(lg->f, "%s%s" "%s: %lu/%lu  %3d%%%s",
+                     context?context:"", context?": ":"",
+                     doing_what, done, total, percent,
+                    done == total ? "\n" : "");
+
+    extra_erase = lg->progress_erase_len - newpel;
+    if (extra_erase > 0)
+        fprintf(lg->f, "%*s\r", extra_erase, "");
+
+    lg->progress_erase_len = newpel;
+}
+
+static void stdiostream_destroy(struct xentoollog_logger *logger_in) {
+    xentoollog_logger_stdiostream *lg = (void*)logger_in;
+    progress_erase(lg);
+    free(lg);
+}
+
+void xtl_stdiostream_set_minlevel(xentoollog_logger_stdiostream *lg,
+                                  xentoollog_level min_level) {
+    lg->min_level = min_level;
+}
+
+void xtl_stdiostream_adjust_flags(xentoollog_logger_stdiostream *lg,
+                                  unsigned set_flags, unsigned clear_flags) {
+    unsigned new_flags = (lg->flags & ~clear_flags) | set_flags;
+    if (new_flags & XTL_STDIOSTREAM_HIDE_PROGRESS)
+        progress_erase(lg);
+    lg->flags = new_flags;
+}
+
+xentoollog_logger_stdiostream *xtl_createlogger_stdiostream
+        (FILE *f, xentoollog_level min_level, unsigned flags) {
+    xentoollog_logger_stdiostream newlogger;
+
+    newlogger.f = f;
+    newlogger.min_level = min_level;
+    newlogger.flags = flags;
+
+    switch (flags & (XTL_STDIOSTREAM_PROGRESS_USE_CR |
+                     XTL_STDIOSTREAM_PROGRESS_NO_CR)) {
+    case XTL_STDIOSTREAM_PROGRESS_USE_CR: newlogger.progress_use_cr = 1; break;
+    case XTL_STDIOSTREAM_PROGRESS_NO_CR:  newlogger.progress_use_cr = 0; break;
+    case 0:
+        newlogger.progress_use_cr = isatty(fileno(newlogger.f)) > 0;
+        break;
+    default:
+        errno = EINVAL;
+        return 0;
+    }
+
+    if (newlogger.flags & XTL_STDIOSTREAM_SHOW_DATE) tzset();
+
+    newlogger.progress_erase_len = 0;
+    newlogger.progress_last_percent = 0;
+
+    return XTL_NEW_LOGGER(stdiostream, newlogger);
+}
index 818f2e4474264de2c66d509cb2106f6e08614d55..940708ff01d45c3fdedeb400d48e83ab543f0af2 100644 (file)
@@ -39,8 +39,6 @@ CTRL_SRCS-y       += xc_memshr.c
 CTRL_SRCS-y       += xc_hcall_buf.c
 CTRL_SRCS-y       += xc_foreign_memory.c
 CTRL_SRCS-y       += xc_kexec.c
-CTRL_SRCS-y       += xtl_core.c
-CTRL_SRCS-y       += xtl_logger_stdio.c
 CTRL_SRCS-y       += xc_resource.c
 CTRL_SRCS-$(CONFIG_X86) += xc_psr.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
@@ -112,6 +110,7 @@ CFLAGS   += -I. -I./include $(CFLAGS_xeninclude)
 CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
 
 CFLAGS += $(PTHREAD_CFLAGS)
+CFLAGS += $(CFLAGS_libxentoollog)
 
 CTRL_LIB_OBJS := $(patsubst %.c,%.o,$(CTRL_SRCS-y))
 CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y))
@@ -165,7 +164,7 @@ install: build
        $(INSTALL_DATA) libxenctrl.a $(DESTDIR)$(libdir)
        $(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR)
        $(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenctrl.so
-       $(INSTALL_DATA) include/xenctrl.h include/xenctrlosdep.h include/xentoollog.h $(DESTDIR)$(includedir)
+       $(INSTALL_DATA) include/xenctrl.h include/xenctrlosdep.h $(DESTDIR)$(includedir)
        $(INSTALL_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
        $(INSTALL_DATA) libxenguest.a $(DESTDIR)$(libdir)
        $(SYMLINK_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenguest.so.$(MAJOR)
@@ -208,7 +207,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
        $(SYMLINK_SHLIB) $< $@
 
 libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
-       $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+       $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 # libxenguest
 
diff --git a/tools/libxc/include/xentoollog.h b/tools/libxc/include/xentoollog.h
deleted file mode 100644 (file)
index 853e9c7..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * xentoollog.h
- *
- * Copyright (c) 2010 Citrix
- * Part of a generic logging interface used by various dom0 userland libraries.
- *
- * 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;
- * version 2.1 of the License.
- *
- * 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 XENTOOLLOG_H
-#define XENTOOLLOG_H
-
-#include <stdio.h>
-#include <stdarg.h>
-
-
-/*---------- common declarations and types ----------*/
-
-typedef enum xentoollog_level {
-    XTL_NONE, /* sentinel etc, never used for logging */
-    XTL_DEBUG,
-    XTL_VERBOSE,
-    XTL_DETAIL,
-    XTL_PROGRESS, /* also used for "progress" messages */
-    XTL_INFO,
-    XTL_NOTICE,
-    XTL_WARN,
-    XTL_ERROR,
-    XTL_CRITICAL,
-    XTL_NUM_LEVELS
-} xentoollog_level;
-
-typedef struct xentoollog_logger xentoollog_logger;
-struct xentoollog_logger {
-    void (*vmessage)(struct xentoollog_logger *logger,
-                     xentoollog_level level,
-                     int errnoval /* or -1 */,
-                     const char *context /* eg "xc", "xl", may be 0 */,
-                     const char *format /* without level, context, \n */,
-                     va_list al)
-         __attribute__((format(printf,5,0)));
-    void (*progress)(struct xentoollog_logger *logger,
-                     const char *context /* see above */,
-                     const char *doing_what /* no \r,\n */,
-                     int percent, unsigned long done, unsigned long total)
-         /* null function pointer is ok.
-          * will always be called with done==0 for each new
-          * context/doing_what */;
-    void (*destroy)(struct xentoollog_logger *logger);
-    /* each logger can put its necessary data here */
-};
-
-
-/*---------- facilities for consuming log messages ----------*/
-
-#define XTL_STDIOSTREAM_SHOW_PID            001u
-#define XTL_STDIOSTREAM_SHOW_DATE           002u
-#define XTL_STDIOSTREAM_HIDE_PROGRESS       004u
-#define XTL_STDIOSTREAM_PROGRESS_USE_CR     010u /* default is to */
-#define XTL_STDIOSTREAM_PROGRESS_NO_CR      020u /* use \r to ttys */
-
-typedef struct xentoollog_logger_stdiostream  xentoollog_logger_stdiostream;
-
-xentoollog_logger_stdiostream *xtl_createlogger_stdiostream
-        (FILE *f, xentoollog_level min_level, unsigned flags);
-    /* may return 0 if malloc fails, in which case error was logged */
-    /* destroy on this logger does not close the file */
-
-void xtl_stdiostream_set_minlevel(xentoollog_logger_stdiostream*,
-                                  xentoollog_level min_level);
-void xtl_stdiostream_adjust_flags(xentoollog_logger_stdiostream*,
-                                  unsigned set_flags, unsigned clear_flags);
-  /* if set_flags and clear_flags overlap, set_flags takes precedence */
-
-void xtl_logger_destroy(struct xentoollog_logger *logger /* 0 is ok */);
-
-
-/*---------- facilities for generating log messages ----------*/
-
-void xtl_logv(struct xentoollog_logger *logger,
-              xentoollog_level level,
-              int errnoval /* or -1 */,
-              const char *context /* eg "xc", "xenstore", "xl", may be 0 */,
-              const char *format /* does not contain \n */,
-              va_list) __attribute__((format(printf,5,0)));
-
-void xtl_log(struct xentoollog_logger *logger,
-             xentoollog_level level,
-             int errnoval /* or -1 */,
-             const char *context /* eg "xc", "xenstore", "xl" */,
-             const char *format /* does not contain \n */,
-             ...) __attribute__((format(printf,5,6)));
-
-void xtl_progress(struct xentoollog_logger *logger,
-                  const char *context /* see above, may be 0 */,
-                  const char *doing_what,
-                  unsigned long done, unsigned long total);
-
-
-/*---------- facilities for defining log message consumers ----------*/
-
-const char *xtl_level_to_string(xentoollog_level); /* never fails */
-
-
-#define XTL_NEW_LOGGER(LOGGER,buffer) ({                                \
-    xentoollog_logger_##LOGGER *new_consumer;                           \
-                                                                        \
-    (buffer).vtable.vmessage = LOGGER##_vmessage;                       \
-    (buffer).vtable.progress = LOGGER##_progress;                       \
-    (buffer).vtable.destroy  = LOGGER##_destroy;                        \
-                                                                        \
-    new_consumer = malloc(sizeof(*new_consumer));                       \
-    if (!new_consumer) {                                                \
-        xtl_log((xentoollog_logger*)&buffer,                            \
-                XTL_CRITICAL, errno, "xtl",                             \
-                "failed to allocate memory for new message logger");    \
-    } else {                                                            \
-        *new_consumer = buffer;                                         \
-    }                                                                   \
-                                                                        \
-    new_consumer;                                                       \
-});
-
-
-#endif /* XENTOOLLOG_H */
diff --git a/tools/libxc/xtl_core.c b/tools/libxc/xtl_core.c
deleted file mode 100644 (file)
index c4724a0..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * xtl_core.c
- *
- * core code including functions for generating log messages
- *
- * Copyright (c) 2010 Citrix
- * Part of a generic logging interface used by various dom0 userland libraries.
- *
- * 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;
- * version 2.1 of the License.
- *
- * 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 "xentoollog.h"
-
-#include <assert.h>
-#include <errno.h>
-#include <limits.h>
-
-static const char *level_strings[XTL_NUM_LEVELS]= {
-    "[BUG:XTL_NONE]",
-    "debug", "verbose", "detail",  /* normally off by default */
-    "progress", "info", "notice",  /* not a problem */
-    "warning", "error", "critical" /* problems and errors */
-};
-
-const char *xtl_level_to_string(xentoollog_level level) {
-    assert(level >= 0 && level < XTL_NUM_LEVELS);
-    return level_strings[level];
-}
-
-void xtl_logv(struct xentoollog_logger *logger,
-              xentoollog_level level,
-              int errnoval /* or -1 */,
-              const char *context /* eg "xc", "xenstore", "xl" */,
-              const char *format /* does not contain \n */,
-              va_list al) {
-    int errno_save = errno;
-    assert(level > XTL_NONE && level < XTL_NUM_LEVELS);
-    logger->vmessage(logger,level,errnoval,context,format,al);
-    errno = errno_save;
-}
-
-void xtl_log(struct xentoollog_logger *logger,
-             xentoollog_level level,
-             int errnoval /* or -1 */,
-             const char *context /* eg "xc", "xenstore", "xl" */,
-             const char *format /* does not contain \n */,
-             ...) {
-    va_list al;
-    va_start(al,format);
-    xtl_logv(logger,level,errnoval,context,format,al);
-    va_end(al);
-}
-
-void xtl_progress(struct xentoollog_logger *logger,
-                  const char *context, const char *doing_what,
-                  unsigned long done, unsigned long total) {
-    int percent = 0;
-
-    if (!logger->progress) return;
-
-    if ( total )
-        percent = (total < LONG_MAX/100)
-            ? (done * 100) / total
-            : done / ((total + 99) / 100);
-
-    logger->progress(logger, context, doing_what, percent, done, total);
-}
-
-void xtl_logger_destroy(struct xentoollog_logger *logger) {
-    if (!logger) return;
-    logger->destroy(logger);
-}
diff --git a/tools/libxc/xtl_logger_stdio.c b/tools/libxc/xtl_logger_stdio.c
deleted file mode 100644 (file)
index 0cd9206..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * xtl_logger_stdio.c
- *
- * log message consumer that writes to stdio
- *
- * Copyright (c) 2010 Citrix
- * Part of a generic logging interface used by various dom0 userland libraries.
- *
- * 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;
- * version 2.1 of the License.
- *
- * 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 "xentoollog.h"
-
-#include <time.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <stdbool.h>
-
-struct xentoollog_logger_stdiostream {
-    xentoollog_logger vtable;
-    FILE *f;
-    xentoollog_level min_level;
-    unsigned flags;
-    int progress_erase_len, progress_last_percent;
-    bool progress_use_cr;
-};
-
-static void progress_erase(xentoollog_logger_stdiostream *lg) {
-    if (lg->progress_erase_len)
-        fprintf(lg->f, "\r%*s\r", lg->progress_erase_len, "");
-}
-
-static void stdiostream_vmessage(xentoollog_logger *logger_in,
-                                 xentoollog_level level,
-                                 int errnoval,
-                                 const char *context,
-                                 const char *format,
-                                 va_list al) {
-    xentoollog_logger_stdiostream *lg = (void*)logger_in;
-
-    if (level < lg->min_level)
-        return;
-
-    progress_erase(lg);
-
-    if (lg->flags & XTL_STDIOSTREAM_SHOW_DATE) {
-        struct tm lt_buf;
-        time_t now = time(0);
-        struct tm *lt= localtime_r(&now, &lt_buf);
-        if (lt != NULL)
-            fprintf(lg->f, "%04d-%02d-%02d %02d:%02d:%02d %s ",
-                    lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday,
-                    lt->tm_hour, lt->tm_min, lt->tm_sec,
-                    tzname[!!lt->tm_isdst]);
-        else
-            fprintf(lg->f, "[localtime_r failed: %d] ", errno);
-    }
-    if (lg->flags & XTL_STDIOSTREAM_SHOW_PID)
-        fprintf(lg->f, "[%lu] ", (unsigned long)getpid());
-
-    if (context)
-        fprintf(lg->f, "%s: ", context);
-
-    fprintf(lg->f, "%s: ", xtl_level_to_string(level));
-
-    vfprintf(lg->f, format, al);
-
-    if (errnoval >= 0)
-        fprintf(lg->f, ": %s", strerror(errnoval));
-
-    putc('\n', lg->f);
-    fflush(lg->f);
-}
-
-static void stdiostream_message(struct xentoollog_logger *logger_in,
-                                xentoollog_level level,
-                                const char *context,
-                                const char *format, ...)
-{
-    va_list al;
-    va_start(al,format);
-    stdiostream_vmessage(logger_in, level, -1, context, format, al);
-    va_end(al);
-}
-
-static void stdiostream_progress(struct xentoollog_logger *logger_in,
-                                 const char *context,
-                                 const char *doing_what, int percent,
-                                 unsigned long done, unsigned long total) {
-    xentoollog_logger_stdiostream *lg = (void*)logger_in;
-    int newpel, extra_erase;
-    xentoollog_level this_level;
-
-    if (lg->flags & XTL_STDIOSTREAM_HIDE_PROGRESS)
-        return;
-
-    if (percent < lg->progress_last_percent) {
-        this_level = XTL_PROGRESS;
-    } else if (percent == lg->progress_last_percent) {
-        return;
-    } else if (percent < lg->progress_last_percent + 5) {
-        this_level = XTL_DETAIL;
-    } else {
-        this_level = XTL_PROGRESS;
-    }
-
-    if (this_level < lg->min_level)
-        return;
-
-    lg->progress_last_percent = percent;
-
-    if (!lg->progress_use_cr) {
-        stdiostream_message(logger_in, this_level, context,
-                            "%s: %lu/%lu  %3d%%",
-                            doing_what, done, total, percent);
-        return;
-    }
-
-    if (lg->progress_erase_len)
-        putc('\r', lg->f);
-
-    newpel = fprintf(lg->f, "%s%s" "%s: %lu/%lu  %3d%%%s",
-                     context?context:"", context?": ":"",
-                     doing_what, done, total, percent,
-                    done == total ? "\n" : "");
-
-    extra_erase = lg->progress_erase_len - newpel;
-    if (extra_erase > 0)
-        fprintf(lg->f, "%*s\r", extra_erase, "");
-
-    lg->progress_erase_len = newpel;
-}
-
-static void stdiostream_destroy(struct xentoollog_logger *logger_in) {
-    xentoollog_logger_stdiostream *lg = (void*)logger_in;
-    progress_erase(lg);
-    free(lg);
-}
-
-void xtl_stdiostream_set_minlevel(xentoollog_logger_stdiostream *lg,
-                                  xentoollog_level min_level) {
-    lg->min_level = min_level;
-}
-
-void xtl_stdiostream_adjust_flags(xentoollog_logger_stdiostream *lg,
-                                  unsigned set_flags, unsigned clear_flags) {
-    unsigned new_flags = (lg->flags & ~clear_flags) | set_flags;
-    if (new_flags & XTL_STDIOSTREAM_HIDE_PROGRESS)
-        progress_erase(lg);
-    lg->flags = new_flags;
-}
-
-xentoollog_logger_stdiostream *xtl_createlogger_stdiostream
-        (FILE *f, xentoollog_level min_level, unsigned flags) {
-    xentoollog_logger_stdiostream newlogger;
-
-    newlogger.f = f;
-    newlogger.min_level = min_level;
-    newlogger.flags = flags;
-
-    switch (flags & (XTL_STDIOSTREAM_PROGRESS_USE_CR |
-                     XTL_STDIOSTREAM_PROGRESS_NO_CR)) {
-    case XTL_STDIOSTREAM_PROGRESS_USE_CR: newlogger.progress_use_cr = 1; break;
-    case XTL_STDIOSTREAM_PROGRESS_NO_CR:  newlogger.progress_use_cr = 0; break;
-    case 0:
-        newlogger.progress_use_cr = isatty(fileno(newlogger.f)) > 0;
-        break;
-    default:
-        errno = EINVAL;
-        return 0;
-    }
-
-    if (newlogger.flags & XTL_STDIOSTREAM_SHOW_DATE) tzset();
-
-    newlogger.progress_erase_len = 0;
-    newlogger.progress_last_percent = 0;
-
-    return XTL_NEW_LOGGER(stdiostream, newlogger);
-}
index 6ff5beee8a35c80ef75bc0c7529cde93aabdf62f..2abae0c28f587ad8f795987628a6096ee7959b03 100644 (file)
@@ -20,11 +20,12 @@ LIBUUID_LIBS += -luuid
 endif
 
 LIBXL_LIBS =
-LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS)
+LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS)
 ifeq ($(CONFIG_REMUS_NETBUF),y)
 LIBXL_LIBS += $(LIBNL3_LIBS)
 endif
 
+CFLAGS_LIBXL += $(CFLAGS_libxentoollog)
 CFLAGS_LIBXL += $(CFLAGS_libxenctrl)
 CFLAGS_LIBXL += $(CFLAGS_libxenguest)
 CFLAGS_LIBXL += $(CFLAGS_libxenstore)
@@ -149,7 +150,7 @@ CFLAGS_XL += -Wshadow
 
 XL_OBJS = xl.o xl_cmdimpl.o xl_cmdtable.o xl_sxp.o
 $(XL_OBJS) $(TEST_PROG_OBJS) _libxl.api-for-check: \
-            CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
+            CFLAGS += $(CFLAGS_libxentoollog)
 $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
 $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs it.
 
@@ -253,19 +254,19 @@ libxlutil.a: $(LIBXLU_OBJS)
        $(AR) rcs libxlutil.a $^
 
 xl: $(XL_OBJS) libxlutil.so libxenlight.so
-       $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl) -lyajl $(APPEND_LDFLAGS)
+       $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS)
 
 xen-init-dom0: $(XEN_INIT_DOM0_OBJS) libxenlight.so
-       $(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+       $(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
 
 test_%: test_%.o test_common.o libxlutil.so libxenlight_test.so
-       $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxenctrl) -lyajl $(APPEND_LDFLAGS)
+       $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS)
 
 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so
-       $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
+       $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
 
 testidl: testidl.o libxlutil.so libxenlight.so
-       $(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+       $(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
 
 $(PKG_CONFIG): % : %.in Makefile
        @sed -e 's/@@version@@/$(MAJOR).$(MINOR)/g' < $< > $@.new
index 666eb660b7b2d92a3e57dc61e8412739667810bd..8ae0a784fda9cc96a0d79066c54350d2874903e4 100644 (file)
@@ -5,7 +5,7 @@ include $(TOPLEVEL)/common.make
 # allow mixed declarations and code
 CFLAGS += -Wno-declaration-after-statement
 
-CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
+CFLAGS += $(CFLAGS_libxentoollog)
 CFLAGS += $(APPEND_CFLAGS)
 OCAMLINCLUDE +=
 
@@ -13,7 +13,7 @@ OBJS = xentoollog
 INTF = xentoollog.cmi
 LIBS = xentoollog.cma xentoollog.cmxa
 
-LIBS_xentoollog = $(LDLIBS_libxenctrl)
+LIBS_xentoollog = $(LDLIBS_libxentoollog)
 
 xentoollog_OBJS = $(OBJS)
 xentoollog_C_OBJS = xentoollog_stubs
@@ -49,7 +49,7 @@ xentoollog.mli: xentoollog.mli.in _xtl_levels.mli.in
 
 libs: $(LIBS)
 
-_xtl_levels.ml.in _xtl_levels.mli.in _xtl_levels.inc: genlevels.py $(XEN_ROOT)/tools/libxc/include/xentoollog.h
+_xtl_levels.ml.in _xtl_levels.mli.in _xtl_levels.inc: genlevels.py $(XEN_ROOT)/tools/libs/toollog/include/xentoollog.h
        $(PYTHON) genlevels.py _xtl_levels.mli.in _xtl_levels.ml.in _xtl_levels.inc
 
 .PHONY: install
index 65d334f936ff6a7f4d87a05708483b4b9ffb03a4..8c233c59b13253a13af8e451c65ad73d983d0e91 100755 (executable)
@@ -3,7 +3,7 @@
 import sys
 
 def read_levels():
-       f = open('../../../libxc/include/xentoollog.h', 'r')
+       f = open('../../../libs/toollog/include/xentoollog.h', 'r')
 
        levels = []
        record = False
index fdba866a4d9020a1cfb8ba348f9ed68d2fc8f51c..9771cc4adbbdc7f3b6f04d86dd6877cedf2f9384 100644 (file)
@@ -7,16 +7,17 @@ XEN_ROOT = "../.."
 extra_compile_args  = [ "-fno-strict-aliasing", "-Werror" ]
 
 PATH_XEN      = XEN_ROOT + "/tools/include"
+PATH_LIBXENTOOLLOG = XEN_ROOT + "/tools/libs/toollog"
 PATH_LIBXC    = XEN_ROOT + "/tools/libxc"
 PATH_LIBXL    = XEN_ROOT + "/tools/libxl"
 PATH_XENSTORE = XEN_ROOT + "/tools/xenstore"
 
 xc = Extension("xc",
                extra_compile_args = extra_compile_args,
-               include_dirs       = [ PATH_XEN, PATH_LIBXC + "/include", "xen/lowlevel/xc" ],
+               include_dirs       = [ PATH_XEN, PATH_LIBXENTOOLLOG + "/include", PATH_LIBXC + "/include", "xen/lowlevel/xc" ],
                library_dirs       = [ PATH_LIBXC ],
                libraries          = [ "xenctrl", "xenguest" ],
-               depends            = [ PATH_LIBXC + "/libxenctrl.so", PATH_LIBXC + "/libxenguest.so" ],
+               depends            = [ PATH_LIBXC + "/libxenctrl.so", PATH_LIBXC + "/libxenguest.so",  "-Wl,-rpath-link="+PATH_LIBXENTOOLLOG ],
                sources            = [ "xen/lowlevel/xc/xc.c" ])
 
 xs = Extension("xs",
index 2407a30bf1c65536aae2bb757ceeb32846713762..e63d894fa0af2fb6405f0badfa019b67b05eadb8 100644 (file)
@@ -3,7 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 # xenpaging.c and file_ops.c incorrectly use libxc internals
 CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(PTHREAD_CFLAGS) -I$(XEN_ROOT)/tools/libxc
-LDLIBS += $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(PTHREAD_LIBS)
+LDLIBS += $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(PTHREAD_LIBS)
 LDFLAGS += $(PTHREAD_LDFLAGS)
 
 POLICY    = default