WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [PATCH] libxenlight: correct broken osdeps.[ch]

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] Re: [PATCH] libxenlight: correct broken osdeps.[ch]
From: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Date: Tue, 17 Nov 2009 18:11:41 +0000
Delivery-date: Tue, 17 Nov 2009 10:12:07 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <19202.58259.909019.355806@xxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <19202.58259.909019.355806@xxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
I wrote:
> libxenlight: Clean up logging arrangements

Here is a follow-on patch, which may not apply cleanly without the
logging arrangements patch applied first.


libxenlight: correct broken osdeps.[ch] and make #includes consistent
    
osdep.[hc] previously mistakenly declared and defined [v]asprintf.
These functions are available in the libc on most platforms.

So now, instead:

 * _GNU_SOURCE is #defined in osdep.h so that we get the system
   [v]asprintf (and various other functions)

 * osdep.h is included first in every libxl*.c file (it needs to
   be before any system headers so that _GNU_SOURCE) takes effect.

 * osdep.[hc] only provide their own reimplementation of [v]asprintf
   if NEED_OWN_ASPRINTF is defined.  Currently it is not ever defined
   but this is provided for any platform which needs it.

 * While I was editing the #includes in each .c file, I put them all
   into the same order: "osdep.h", then system headers, then local headers.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>


diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 492d6d9..0358cea 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -23,8 +23,7 @@ LIBCONFIG_URL ?= http://www.hyperrealm.com/libconfig
 LIBCONFIG_SOURCE = libconfig-1.3.2
 LIBCONFIG_OUTPUT = $(LIBCONFIG_SOURCE)/.libs
 
-LIBXL_OBJS-y =
-LIBXL_OBJS-$(CONFIG_Linux) += osdeps.o
+LIBXL_OBJS-y = osdeps.o
 LIBXL_OBJS = flexarray.o libxl.o libxl_dom.o libxl_exec.o libxl_xshelp.o 
libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y)
 
 CLIENTS = xl
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 5e2f23b..6009dc1 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -14,6 +14,8 @@
  * GNU Lesser General Public License for more details.
  */
 
+#include "osdep.h"
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -25,6 +27,7 @@
 #include <unistd.h> /* for write, unlink and close */
 #include <stdint.h>
 #include <inttypes.h>
+
 #include "libxl.h"
 #include "libxl_utils.h"
 #include "libxl_internal.h"
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 82a2a30..585e676 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -14,15 +14,18 @@
  * GNU Lesser General Public License for more details.
  */
 
+#include "osdep.h"
+
 #include <string.h>
 #include <stdio.h>
-#include "libxl.h"
-#include "libxl_internal.h"
 #include <sys/time.h> /* for struct timeval */
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "libxl.h"
+#include "libxl_internal.h"
+
 char *string_of_kinds[] = {
     [DEVICE_VIF] = "vif",
     [DEVICE_VBD] = "vbd",
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index eaea6f3..2437a51 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -13,8 +13,8 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
-#include "libxl_internal.h"
+#include "osdep.h"
+
 #include <stdio.h>
 #include <inttypes.h>
 #include <xenguest.h>
@@ -24,6 +24,9 @@
 #include <sys/time.h> /* for struct timeval */
 #include <unistd.h> /* for sleep(2) */
 
+#include "libxl.h"
+#include "libxl_internal.h"
+
 int is_hvm(struct libxl_ctx *ctx, uint32_t domid)
 {
     xc_domaininfo_t info;
diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c
index 8a589b6..7061a1b 100644
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -15,9 +15,12 @@
  * GNU Lesser General Public License for more details.
  */
 
+#include "osdep.h"
+
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+
 #include "libxl.h"
 #include "libxl_internal.h"
 
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index 7ba0c97..966ac3b 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -12,13 +12,17 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  */
-#include "libxl.h"
-#include "libxl_internal.h"
-#include "libxl_utils.h"
+
+#include "osdep.h"
+
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
 
+#include "libxl.h"
+#include "libxl_internal.h"
+#include "libxl_utils.h"
+
 int libxl_error_set(struct libxl_ctx *ctx, int code)
 {
     return 0;
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 5048fd0..50e1b18 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -13,8 +13,8 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl_utils.h"
-#include "libxl_internal.h"
+#include "osdep.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -24,6 +24,8 @@
 #include <ctype.h>
 #include <errno.h>
 
+#include "libxl_utils.h"
+#include "libxl_internal.h"
 
 
 unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, 
unsigned int smp_cpus)
diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c
index f59eee7..b280d69 100644
--- a/tools/libxl/libxl_xshelp.c
+++ b/tools/libxl/libxl_xshelp.c
@@ -13,13 +13,16 @@
  * GNU Lesser General Public License for more details.
  */
 
+#include "osdep.h"
+
 #include <string.h>
 #include <stddef.h>
-#include "libxl.h"
-#include "libxl_internal.h"
 #include <stdio.h>
 #include <stdarg.h>
 
+#include "libxl.h"
+#include "libxl_internal.h"
+
 char **libxl_xs_kvs_of_flexarray(struct libxl_ctx *ctx, flexarray_t *array, 
int length)
 {
     char **kvs;
diff --git a/tools/libxl/osdeps.c b/tools/libxl/osdeps.c
index 81175aa..ad96480 100644
--- a/tools/libxl/osdeps.c
+++ b/tools/libxl/osdeps.c
@@ -19,6 +19,8 @@
 #include <sys/time.h>
 #include <stdlib.h>
 
+#ifdef NEED_OWN_ASPRINTF
+
 int vasprintf(char **buffer, const char *fmt, va_list ap)
 {
     int size = 0;
@@ -60,3 +62,5 @@ int asprintf(char **buffer, char *fmt, ...)
     va_end (ap);
     return status;
 }
+
+#endif
diff --git a/tools/libxl/osdeps.h b/tools/libxl/osdeps.h
index 5391727..984b6f1 100644
--- a/tools/libxl/osdeps.h
+++ b/tools/libxl/osdeps.h
@@ -13,12 +13,19 @@
  * GNU Lesser General Public License for more details.
  */
 
+/*
+ * This header must be included first, before any system headers,
+ * so that _GNU_SOURCE takes effect properly.
+ */
+
 #ifndef LIBXL_OSDEP
 #define LIBXL_OSDEP
 
+#define _GNU_SOURCE
+
+#ifdef NEED_OWN_ASPRINTF
 #include <stdarg.h>
 
-#if defined(__linux__)
 int asprintf(char **buffer, char *fmt, ...);
 int vasprintf(char **buffer, const char *fmt, va_list ap);
 #endif
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
index 3b735ec..444d9a1 100644
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -14,8 +14,6 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
-#include "libxl_utils.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -29,6 +27,9 @@
 #include <arpa/inet.h>
 #include <xenctrl.h>
 
+#include "libxl.h"
+#include "libxl_utils.h"
+
 void log_callback(void *userdata, int loglevel, const char *file, int line, 
const char *func, char *s)
 {
     fprintf(stderr, "[%d] %s:%d:%s: %s\n", loglevel, file, line, func, s);

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel