[Buildroot] [PATCH] Raspberry Pi - WiringPi Library Package

Carsten Schoenert c.schoenert at gmail.com
Thu Jul 11 07:42:28 UTC 2013

Hello Guillermo,

Am 11.07.2013 08:38, schrieb Guillermo A. Amaral:
> I searched around for alternative ways around the issue when I first
> encountered it, it seemed no-oping it would be most portable/safest approach.

The O_CLOEXEC variable was introduced in 2.6.23.

>        O_CLOEXEC (Since Linux 2.6.23)
>               Enable the close-on-exec flag for the new file descriptor.
>               Specifying this flag permits a program to avoid additional
>               fcntl(2) F_SETFD operations to set the FD_CLOEXEC flag.
>               Additionally, use of this flag is essential in some
>               multithreaded programs since using a separate fcntl(2) F_SETFD
>               operation to set the FD_CLOEXEC flag does not suffice to avoid
>               race conditions where one thread opens a file descriptor at
>               the same time as another thread does a fork(2) plus execve(2).

So if you use a kernel less then 2.6.23 it make no sense to define
O_CLOEXEC to whatever you want, the kernel doesn't know this. And in the
opposite you can't defined it to some different then already defined for

The function 'open' can also used without the 3rd parameter.

So I think you have to check which kernel version is used and build a
patch which does something like

#ifdef KERNEL_VER < 2_6_23
  if ((fd = open ("/dev/mem", O_RDWR | O_SYNC) ) < 0)
  if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)

The guys from linux-wireless do a lot of this to get the wireless
package working om different kernel versions.


More information about the buildroot mailing list