openFd under -threaded gets interrupted

Mitar mmitar at
Fri Dec 18 12:40:48 EST 2009


I have written about this to Haskell cafe and they advised me to write it here.

I have a problem that I cannot open /dev/rfcomm0 device if I compile
my program with -threaded option. Like:

fd <- openFd "/dev/rfcomm0" ReadWrite Nothing OpenFileFlags { append =
False, noctty = True, exclusive = False, nonBlock = True, trunc =
False }

If I compile my program with -threaded option I always get such error:

interrupted (Interrupted system call)

But without -threaded it works flawlessly. I am using Linux 2.6.30
amd64, GHC 6.10.4. It was the same with 6.8. And I have tested it also
on 6.12.1.

After some testing I have discovered that the problem is only with
/dev/rfcomm0 as a device, that is with Bluetooth serial connection.
The problem is that rfcomm Linux kernel code contains:

if (signal_pending(current)) {
   err = -EINTR;

So if during open call some signal comes it returns EINTR. As it has
to open a connection to a Bluetooth device opening a /dev/rfcomm0 file
requires some time and during that time obviously there is some signal
sent by GHC with -threaded option which is not sent without it.

So please tell me what is the difference between open with and without
-threaded option in GHC as I would like to make a simple C test case.
I am not really sure if this is a feature or a bug in Linux Bluetooth
kernel implementation. But in combination with threaded GHC it makes
not working.

Also is there any workaround possible in Haskell/GHC? For example
making time while openFd is in progress without interrupts?

I have found very similar bug reported here:

but code from the patch does not seem to be included in official
kernel source code (but it is also a long time ago so many things have
probably changed). But the workaround mentioned there is working also
here. If I open /dev/rfcomm0 with some other program (so that
Bluetooth connection is made) before I run Haskell program then it
works in both cases, with or without -threaded option. Of course this
is not really useful workaround in my case, I would like to make a
stand-alone Haskell program. So if it is similar to that bug then
maybe it is a bug in Linux kernel.

So please help me solve this problem.


More information about the Glasgow-haskell-users mailing list