Skip to contentSkip to conversation

libxl: build fix

PATCH NAK Christoph Egger 3 participants 9 messages Nov 5, 2010 – Nov 9, 2010

lore
Share & tools
lore
#0 lore raw

Hi!

Attached patch fixes libxl build.
libgen.h is needed for basename().

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
tools/libxl/xl_cmdimpl.c +1 -0
diff -r be2550c2aa2a tools/libxl/xl_cmdimpl.c
@@ -35,6 +35,7 @@
 #include <xenctrl.h>
 #include <ctype.h>
 #include <inttypes.h>
+#include <libgen.h>
 
 #include "libxl.h"
 #include "libxl_utils.h"

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Nacked-by NAK
#1 lore raw

Christoph Egger writes ("[Xen-devel] libxl: build fix"):

Quoted 2 lines

Attached patch fixes libxl build.
libgen.h is needed for basename().

Did you test this change ?

Looking at the manpage I have here, and the xl code, the version of basename() expected by the libxl cpuid code is the GNU one, not the POSIX one, and they have different semantics. I think we will have to open code an implementation of basename.

I see that there is a lot of const-correctness misssing; if filename had been declared const char* as it should your compiler would have spotted the problem.

Ian.

#2 lore raw
Quoted 7 lines · On Monday 08 November 2010 17:38:18 Ian Jackson wrote:

Christoph Egger writes ("[Xen-devel] libxl: build fix"):

Quoted 2 lines

Attached patch fixes libxl build.
libgen.h is needed for basename().

Did you test this change ?

Sure. W/o that patch, compiling fails with
"implicit declaration" on NetBSD.

Quoted 1 line

Looking at the manpage I have here,

How does it differ to mine [1] ?

Quoted 4 lines

and the xl code, the version of
basename() expected by the libxl cpuid code is the GNU one,
not the POSIX one, and they have different semantics. I think we will have to open code an implementation of basename.

Can you imagine to make Xen tools prefer POSIX over GNU in general, please?

Quoted 3 lines

I see that there is a lot of const-correctness misssing; if filename had been declared const char* as it should your compiler would have spotted the problem.

The compiler is pretty quiet w/o -Wconst-char -Wwrite-strings in respect to const-correctness.

[1] http://netbsd.gw.com/cgi-bin/man-cgi?basename+3+NetBSD-current

Christoph

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#3 lore raw

Christoph Egger writes ("Re: [Xen-devel] libxl: build fix"):

Quoted 5 lines · On Monday 08 November 2010 17:38:18 Ian Jackson wrote:
Quoted 1 line

Did you test this change ?

Sure. W/o that patch, compiling fails with
"implicit declaration" on NetBSD.

No, I mean: did you execute the new code ? Never mind.

Quoted 4 lines
Quoted 1 line

Looking at the manpage I have here,

How does it differ to mine [1] ?
[1] http://netbsd.gw.com/cgi-bin/man-cgi?basename+3+NetBSD-current

Look at the code and you will see that it assumes that basename does not modify its argument. I'm about to push a const-correctness fix which will make this more obvious and cause your broken attempt at a fix not to compile :-).

Quoted 6 lines
Quoted 4 lines

and the xl code, the version of
basename() expected by the libxl cpuid code is the GNU one,
not the POSIX one, and they have different semantics. I think we will have to open code an implementation of basename.

Can you imagine to make Xen tools prefer POSIX over GNU in general, please?

I agree that the current code is a mistake. The POSIX basename is irritating and we shouldn't use it. Simply open coding a search for a '/' will be fine.

Ian.

#4 lore raw
Quoted 4 lines · On Monday 08 November 2010 18:01:54 Ian Jackson wrote:

Look at the code and you will see that it assumes that basename does not modify its argument. I'm about to push a const-correctness fix which will make this more obvious and cause your broken attempt at a fix not to compile :-).

I rebased my source tree and yes, it does not compile.

Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

and the xl code, the version of
basename() expected by the libxl cpuid code is the GNU one, not the POSIX one, and they have different semantics. I think we will have to open code an implementation of basename.

Can you imagine to make Xen tools prefer POSIX over GNU in general, please?

I agree that the current code is a mistake. The POSIX basename is irritating and we shouldn't use it. Simply open coding a search for a '/' will be fine.

Attached patch replaces basename with strrchr(3).

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
tools/libxl/xl_cmdimpl.c +2 -2
diff -r fcdab7bf732b -r 35070850561e tools/libxl/xl_cmdimpl.c
@@ -5323,7 +5323,7 @@ int main_tmem_freeable(int argc, char **
 
 int main_cpupoolcreate(int argc, char **argv)
 {
-    const const char *filename = NULL;
+    const char *filename = NULL;
     const char *p;
     char extra_config[1024];
     int dryrun = 0;
@@ -5430,7 +5430,7 @@ int main_cpupoolcreate(int argc, char **
     if (!xlu_cfg_get_string (config, "name", &buf))
         name = strdup(buf);
     else
-        name = basename(filename);
+        name = strrchr(filename, '/');
     if (!libxl_name_to_cpupoolid(&ctx, name, &poolid)) {
         fprintf(stderr, "Pool name \"%s\" already exists\n", name);
         return -ERROR_FAIL;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw

Christoph Egger writes ("Re: [Xen-devel] libxl: build fix"):

Quoted 1 line

Attached patch replaces basename with strrchr(3).

...

tools/libxl/xl_cmdimpl.c int main_cpupoolcreate(int argc, char ** · line 5433

Quoted 2 lines
tools/libxl/xl_cmdimpl.c +1 -1
-        name = basename(filename);
+        name = strrchr(filename, '/');

*ahem*

Ian.

#6 lore raw
Quoted 7 lines · On Tuesday 09 November 2010 12:54:45 Ian Jackson wrote:

Christoph Egger writes ("Re: [Xen-devel] libxl: build fix"):

Quoted 1 line

Attached patch replaces basename with strrchr(3).

...

Quoted 2 lines
tools/libxl/xl_cmdimpl.c +1 -1
-        name = basename(filename);
+        name = strrchr(filename, '/');

Sorry, should be

name = strrchr(filename, '/') + 1;

Christoph

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#7 lore raw
Quoted 11 lines · Christoph Egger
Quoted 6 lines · On Tuesday 09 November 2010 12:54:45 Ian Jackson wrote:

Christoph Egger writes ("Re: [Xen-devel] libxl: build fix"):

Quoted 1 line

Attached patch replaces basename with strrchr(3).

...

Quoted 2 lines
tools/libxl/xl_cmdimpl.c +1 -1
-        name = basename(filename);
+        name = strrchr(filename, '/');

Sorry, should be

  name = strrchr(filename, '/') + 1;

No, it should be

    name = strrchr(filename, '/');
    if (name)
        name++;
    else
        name = filename;

In fact even that isn't right because basename(3) discards (or at least ignores) trailing '/' characters.

jch

#8 lore raw

John Haxby writes ("Re: [Xen-devel] libxl: build fix"):

Quoted 7 lines

No, it should be

     name = strrchr(filename, '/');
     if (name)
         name++;
     else
         name = filename;

As you say.

Quoted 2 lines

In fact even that isn't right because basename(3) discards (or at least ignores) trailing '/' characters.

In this particular case, there won't be any, because if there were then opening the cpupool config file would fail.

Ian.