Skip to contentSkip to conversation

mdadm: fix portability issues encountered while building against musl libc

PATCH In review John Spencer 3 participants 4 messages Feb 9, 2013 – Feb 11, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mdadm: fix portability issues encountered while building against musl libc

From 23114b8c77982717cc3ce3d437321c7fb0b1c918 Mon Sep 17 00:00:00 2001
From: John Spencer <[email protected]>
Date: Sat, 2 Feb 2013 17:26:45 +0100
Subject: [PATCH 1/3] platform-intel: canonicalize_file_name() is not portable

this is a GLIBC specific feature and should not be used.

according to its manpage:
"The call canonicalize_file_name(path) is equivalent to the call realpath(path, NULL)."

thus, we use realpath so it works everywhere.

---
 platform-intel.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
platform-intel.c +2 -2
index 0dcf07c..d8d4942 100644
@@ -116,7 +116,7 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
 
 		list->dev_id = (__u16) dev_id;
 		list->type = type;
-		list->path = canonicalize_file_name(path);
+		list->path = realpath(path, NULL);
 		list->next = NULL;
 		if ((list->pci_id = strrchr(list->path, '/')) != NULL)
 			list->pci_id++;
@@ -459,7 +459,7 @@ char *devt_to_devpath(dev_t dev)
 	char device[46];
 
 	sprintf(device, "/sys/dev/block/%d:%d/device", major(dev), minor(dev));
-	return canonicalize_file_name(device);
+	return realpath(device, NULL);
 }
 
 char *diskfd_to_devpath(int fd)
Signature · 1 line
1.7.3.4

From 9467d1dcef907addbd9ef4f0f9068766674fd587 Mon Sep 17 00:00:00 2001
From: John Spencer <[email protected]>
Date: Sat, 2 Feb 2013 17:37:55 +0100
Subject: [PATCH 2/3] mdadm.h: fix ugly glibc specific ifdeffery

the code that was exposed on anything else than dietlibc and klibc is entirely glibc specific and broke the build on musl libc.

---
 mdadm.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
mdadm.h +2 -2
index f1352e3..addd423 100644
@@ -25,9 +25,9 @@
 #define	_GNU_SOURCE
 #define _FILE_OFFSET_BITS 64
 #include	<unistd.h>
-#if !defined(__dietlibc__) && !defined(__KLIBC__)
+#ifdef __GLIBC__
 extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
-#else
+#elif !defined(lseek64)
 # if defined(__NO_STAT64) || __WORDSIZE != 32
 # define lseek64 lseek
 # endif
Signature · 1 line
1.7.3.4

From eb55533b387c0805ac11134bab1404108851ef04 Mon Sep 17 00:00:00 2001
From: John Spencer <[email protected]>
Date: Sat, 2 Feb 2013 17:40:20 +0100
Subject: [PATCH 3/3] remove -Werror from Makefile

using -Werror breaks the build for any libc/compiler combination the author didnt test yet, so it is insane to use it by default.

fixes build on musl libc.

---
 Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
index b9787d6..0169824 100644
@@ -42,7 +42,7 @@ KLIBC_GCC = gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIB
 
 CC = $(CROSS_COMPILE)gcc
 CXFLAGS = -ggdb
-CWFLAGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter
+CWFLAGS = -Wall -Wstrict-prototypes -Wextra -Wno-unused-parameter
 ifdef WARN_UNUSED
 CWFLAGS += -Wp,-D_FORTIFY_SOURCE=2 -O
 endif
Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 1 line · John Spencer

Hi,

Inline patches are prefered to ease review, you can use git send-email to send the patches directly from the command line following a tutorial like this:
http://blog.bisect.de/2012/01/how-to-send-patches-via-git-send-email.html

That aside I don't think removing Werror is the correct choice, mdadm is primarily compiled with gcc + glibc.
If you are using a non-default compiler collection, chances are you can handle removing Werror yourself or correcting the issues and posting the patches here such as you did.

Signature · 2 lines
CTO | Orion Virtualisation Solutions | www.orionvm.com.au
Phone: 1300 56 99 52 | Mobile: 0428 754 846
#2 lore raw
In reply to John Spencer
Quoted 32 lines · On Sun, 10 Feb 2013 00:15:51 +0100 John Spencer <[email protected]>…
Quoted 1 line

From 23114b8c77982717cc3ce3d437321c7fb0b1c918 Mon Sep 17 00:00:00 2001

From: John Spencer <[email protected]>
Date: Sat, 2 Feb 2013 17:26:45 +0100
Subject: [PATCH 1/3] platform-intel: canonicalize_file_name() is not portable

this is a GLIBC specific feature and should not be used.

according to its manpage:
"The call canonicalize_file_name(path) is equivalent to the call realpath(path, NULL)."

thus, we use realpath so it works everywhere.

---
 platform-intel.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
platform-intel.c +1 -1
index 0dcf07c..d8d4942 100644
@@ -116,7 +116,7 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
 
 		list->dev_id = (__u16) dev_id;
 		list->type = type;
-		list->path = canonicalize_file_name(path);
+		list->path = realpath(path, NULL);
 		list->next = NULL;
 		if ((list->pci_id = strrchr(list->path, '/')) != NULL)
 			list->pci_id++;

platform-intel.c char *devt_to_devpath(dev_t dev) · line 465

Quoted 8 lines
platform-intel.c +1 -1
@@ -459,7 +459,7 @@ char *devt_to_devpath(dev_t dev)
 	char device[46];
 
 	sprintf(device, "/sys/dev/block/%d:%d/device", major(dev), minor(dev));
-	return canonicalize_file_name(device);
+	return realpath(device, NULL);
 }
 
 char *diskfd_to_devpath(int fd)

Hi,
I've applied this one and the GCC #ifdef - thanks.

I haven't applied the last one, but not because I don't appreciate being called insane :-)

I like having -Werror as it encourages people to report any warnings they get, and it keeps me "honest".
If it is a problem for you, you can easily
make CWFLAGS=

or set the C Warning FLAGS to whatever you like - they are deliberately kept separate from other CFLAGS.

Thanks,
NeilBrown

#3 lore raw
Quoted 3 lines · NeilBrown

Hi,
I've applied this one and the GCC #ifdef - thanks.

thanks!

Quoted 3 lines

I haven't applied the last one, but not because I don't appreciate being called insane :-)

he he :)

Quoted 3 lines

I like having -Werror as it encourages people to report any warnings they get, and it keeps me "honest".

well, i dont think anyone except of the author(s) wants that flag activated by default so that they can find warnings without looking to closely.

Quoted 2 lines

If it is a problem for you, you can easily
make CWFLAGS=

i know, but "broken-by-default" is not a very friendly setting.
there are quite a couple of warnings GCC emits that are simply bogus.
i'd rather if the one that actually wants this hardcore setting uses make CWFLAGS=-Werror (or make FATAL=1) instead of forcing his policy on all users.

Quoted 6 lines

or set the C Warning FLAGS to whatever you like - they are deliberately kept separate from other CFLAGS.

Thanks,
NeilBrown

thanks,
--JS