Patchwork [1/2] iperf: fix build on !MMU platforms

login
register
mail settings
Submitter Thomas Petazzoni
Date May 7, 2012, 4:39 p.m.
Message ID <1336408773-27312-1-git-send-email-thomas.petazzoni@free-electrons.com>
Download mbox | patch
Permalink /patch/157349/
State Changes Requested
Headers show

Comments

Thomas Petazzoni - May 7, 2012, 4:39 p.m.
Build tested on sh2a and blackfin architectures.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 package/iperf/iperf-add-pthread.patch      |   25 +++++++++++++++
 package/iperf/iperf-man-installation.patch |   15 +++++++++
 package/iperf/iperf-no-mmu.patch           |   48 ++++++++++++++++++++++++++++
 package/iperf/iperf.mk                     |    2 +-
 4 files changed, 89 insertions(+), 1 deletion(-)
 create mode 100644 package/iperf/iperf-add-pthread.patch
 create mode 100644 package/iperf/iperf-man-installation.patch
 create mode 100644 package/iperf/iperf-no-mmu.patch
Peter Korsgaard - May 7, 2012, 8:47 p.m.
>>>>> "Thomas" == Thomas Petazzoni <thomas.petazzoni@free-electrons.com> writes:

 Thomas> Build tested on sh2a and blackfin architectures.

Thanks. Have you sent these patches upstream?

 Thomas> ++++ b/src/Listener.cpp
 Thomas> +@@ -679,7 +679,11 @@
 Thomas> +     pid_t pid; 
 Thomas> + 
 Thomas> +     /* Create a child process & if successful, exit from the parent process */ 
 Thomas> ++#ifndef HAVE_FORK
 Thomas> ++    if ( (pid = vfork()) == -1 ) {
 Thomas> ++#else
 Thomas> +     if ( (pid = fork()) == -1 ) {
 Thomas> ++#endif
 Thomas> +         fprintf( stderr, "error in first child create\n");     
 Thomas> +         exit(0); 

I believe you aren't allowed to call exit() after vfork (but should use
_exit() instead).

http://unix.stackexchange.com/questions/5364/why-should-a-child-of-a-vfork-or-fork-call-exit-instead-of-exit
Arnout Vandecappelle - May 11, 2012, 8:23 p.m.
On 05/07/12 22:47, Peter Korsgaard wrote:
>>>>>> "Thomas" == Thomas Petazzoni<thomas.petazzoni@free-electrons.com>  writes:
>
>   Thomas>  Build tested on sh2a and blackfin architectures.
>
> Thanks. Have you sent these patches upstream?
>
>   Thomas>  ++++ b/src/Listener.cpp
>   Thomas>  +@@ -679,7 +679,11 @@
>   Thomas>  +     pid_t pid;
>   Thomas>  +
>   Thomas>  +     /* Create a child process&  if successful, exit from the parent process */
>   Thomas>  ++#ifndef HAVE_FORK
>   Thomas>  ++    if ( (pid = vfork()) == -1 ) {
>   Thomas>  ++#else
>   Thomas>  +     if ( (pid = fork()) == -1 ) {
>   Thomas>  ++#endif
>   Thomas>  +         fprintf( stderr, "error in first child create\n");
>   Thomas>  +         exit(0);
>
> I believe you aren't allowed to call exit() after vfork (but should use
> _exit() instead).
>
> http://unix.stackexchange.com/questions/5364/why-should-a-child-of-a-vfork-or-fork-call-exit-instead-of-exit

  This particular exit is OK, because it is in the error case.
It's the one below that is not OK.  Or rather, nothing is OK, because
the child process after a vfork is not supposed to do anything except
exec() or _exit() - it certainly shouldn't return from the function.
In fact, on Linux the parent process is suspended until the child either
_exit()s or exec()s, so it doesn't daemonize at all.

  I'm not sure how you can daemonize in a posixly-correct way on a NOMMU
target.  But since we're running on Linux, we can just use daemon(),
right?  Both glibc and uclibc define it AFAIK.

  Regards,
  Arnout

Patch

diff --git a/package/iperf/iperf-add-pthread.patch b/package/iperf/iperf-add-pthread.patch
new file mode 100644
index 0000000..4997b75
--- /dev/null
+++ b/package/iperf/iperf-add-pthread.patch
@@ -0,0 +1,25 @@ 
+Fix pthread link problem
+
+Some toolchains support linking against pthread by passing
+-pthread. For such toolchains, iperf was working because
+@PTHREAD_CFLAGS@ was used.
+
+However, some other toolchains (ex: Renesas 2010.09) requires passing
+-lpthread to link against the pthread library. And this was breaking
+in iperf because @PTHREAD_LIBS@ wasn't used. We fix this here.
+
+Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+
+Index: b/src/Makefile.am
+===================================================================
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -12,7 +12,7 @@
+ AM_CXXFLAGS = -Wall
+ AM_CFLAGS = -Wall
+ 
+-iperf_LDFLAGS = @CFLAGS@ @PTHREAD_CFLAGS@ @WEB100_CFLAGS@ @DEFS@
++iperf_LDFLAGS = @CFLAGS@ @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ @WEB100_CFLAGS@ @DEFS@
+ 
+ iperf_SOURCES = \
+ 		Client.cpp \
diff --git a/package/iperf/iperf-man-installation.patch b/package/iperf/iperf-man-installation.patch
new file mode 100644
index 0000000..7c63b2d
--- /dev/null
+++ b/package/iperf/iperf-man-installation.patch
@@ -0,0 +1,15 @@ 
+Fix man installation
+
+Using man_MANS and dist_man_MANS is redundant, and makes the Makefile
+try to install twice the iperf.1 manpage, which fails.
+
+Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+
+Index: b/man/Makefile.am
+===================================================================
+--- a/man/Makefile.am
++++ b/man/Makefile.am
+@@ -1,2 +1 @@
+-man_MANS = iperf.1
+-dist_man_MANS = $(man_MANS)
++dist_man_MANS = iperf.1
diff --git a/package/iperf/iperf-no-mmu.patch b/package/iperf/iperf-no-mmu.patch
new file mode 100644
index 0000000..b9f89b2
--- /dev/null
+++ b/package/iperf/iperf-no-mmu.patch
@@ -0,0 +1,48 @@ 
+Add support for building in no-MMU mode
+
+This adds a check for the fork() function in configure.ac, then
+conditionnally calls either fork() or vfork() depending on which one
+is available.
+
+Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+
+Index: b/configure.ac
+===================================================================
+--- a/configure.ac
++++ b/configure.ac
+@@ -66,6 +66,7 @@
+ dnl check for -lnsl, -lsocket
+ AC_CHECK_FUNC(gethostbyname,,AC_CHECK_LIB(nsl, gethostbyname))
+ AC_CHECK_FUNC(socket,,AC_CHECK_LIB(socket, socket))
++AC_CHECK_FUNC(fork)
+ 
+ dnl Checks for header files.
+ AC_HEADER_STDC
+Index: b/src/Listener.cpp
+===================================================================
+--- a/src/Listener.cpp
++++ b/src/Listener.cpp
+@@ -679,7 +679,11 @@
+     pid_t pid; 
+ 
+     /* Create a child process & if successful, exit from the parent process */ 
++#ifndef HAVE_FORK
++    if ( (pid = vfork()) == -1 ) {
++#else
+     if ( (pid = fork()) == -1 ) {
++#endif
+         fprintf( stderr, "error in first child create\n");     
+         exit(0); 
+     } else if ( pid != 0 ) {
+@@ -695,7 +699,11 @@
+ 
+ 
+     /* Now fork() and get released from the terminal */  
++#ifndef HAVE_FORK
++    if ( (pid = vfork()) == -1 ) {
++#else
+     if ( (pid = fork()) == -1 ) {
++#endif
+         fprintf( stderr, "error\n");   
+         exit(0); 
+     } else if ( pid != 0 ) {
diff --git a/package/iperf/iperf.mk b/package/iperf/iperf.mk
index 26cd3fb..614f8f6 100644
--- a/package/iperf/iperf.mk
+++ b/package/iperf/iperf.mk
@@ -6,7 +6,7 @@ 
 IPERF_VERSION = 2.0.5
 IPERF_SOURCE = iperf-$(IPERF_VERSION).tar.gz
 IPERF_SITE = http://$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/iperf
-
+IPERF_AUTORECONF = YES
 IPERF_CONF_ENV = \
 	ac_cv_func_malloc_0_nonnull=yes \
 	ac_cv_type_bool=yes \