flat assembler
Message board for the users of flat assembler.

Index > Linux > Asynchronus named pipes

Author
Thread Post new topic Reply to topic
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf 21 Jun 2009, 20:23
Hello,

I am trying to make my program handle a named pipe asynchronously wile I have tested and gotten everything to work (program will respond to SIGIO properly and do a nonblocking open properly), doing "echo a > myNamedPipe" still does not trigger a SIGIO.

My kernel is 2.6.21. Will this ever work? Where is the problem?

The reason I am using named pipes and not something else is simplicity.

Here is the relevant initialization code:
Code:
; creates a FIFO (named pipe)

        ;MKNOD IN CURRENT DIRECTORY
        mov     eax,14          ;sys_mknod
        mov     ebx,fifoFile
        mov     ecx,4096 + 777o ;S_IFIFO with a+rwx
        int     0x80

        ;REGISTER ASYNC IO HANDLER
        mov     eax,48          ;sys_signal
        mov     ebx,29          ;handle IO signal
        mov     ecx,fifoRead
        int     0x80

        ;OPEN FIFO
        mov     eax,5           ;sys_open
        mov     ebx,fifoFile
        mov     ecx,00024000o   ;O_RDONLY, FASYNC and O_NONBLOCK
        int     0x80
        mov     [fifoFN],eax

        ;GET OUR PID
        mov     eax,20          ;sys_getpid
        int     0x80
        mov     [fifoPID],eax

        ;TELL KERNEL WE WANT CALLBACK
        mov     eax,55          ;sys_fcntl
        mov     ebx,[fifoFN]
        mov     ecx,8           ;F_SETOWN
        mov     edx,[fifoPID]
        int     0x80

        ;WE WANT A SIGIO CALLBACK
        mov     eax,55          ;sys_fcntl
        mov     ebx,[fifoFN]
        mov     ecx,10          ;F_SETSIG
        xor     edx,edx         ;SIGIO
        int     0x80

        ;REEMPHASIZE FASYNC TO AVOID KERNEL BUG
        mov     eax,55          ;sys_fcntl
        mov     ebx,[fifoFN]
        mov     ecx,3           ;F_GETFL
        int     0x80
        push    eax             ;save result

        mov     eax,55
        mov     ebx,[fifoFN]
        mov     ecx,4           ;F_SETFL
        pop     edx             ;restore F_GETFL result
        or      edx,00024000o   ;O_RDONLY, FASYNC and O_NONBLOCK
        int     0x80
    


Thanks a lot for any help in advance.
Post 21 Jun 2009, 20:23
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 215
Location: Budapest, Hungary
Endre 23 Jun 2009, 08:12
I don't see where (and how) you have installed your signal handler.

Oh sorry, I found it Sad.
Post 23 Jun 2009, 08:12
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 215
Location: Budapest, Hungary
Endre 24 Jun 2009, 17:48
Ok, I've tracked down the reason of the problem. If you open the pipe with O_ASYNC (FASYNC) flag set then you won't get SIGIO (SIGPOLL). I don't know why (kernel bug?). So you must not set this flag when opening the pipe (independently of whether you are on the read or the write end of the pipe and whether you set O_ASYNC with fcntl or not).
Post 24 Jun 2009, 17:48
View user's profile Send private message Reply with quote
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf 28 Jun 2009, 21:05
That fixed it, thanks. Smile

I noticed a message regarding that particular kernel bug before (apparently, it makes some kind of sense, although then all the documentation is wrong), that's why the re-emphasis code is for anyway; I just didn't know that setting FASYNC in the first place will break it too.

Thanks again.

EDIT: Yup, a bug: http://bugzilla.kernel.org/show_bug.cgi?id=5993
Post 28 Jun 2009, 21:05
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 215
Location: Budapest, Hungary
Endre 29 Jun 2009, 09:20
I'm using gentoo kernel 2.6.29-r5. It doesn't contain any bugfix regarding this strange behavior either. At least it's good to know that you first have to clear the F_ASYNC flag and then reenable it again to have things work.
Quote:
I just didn't know that setting FASYNC in the first place will break it too
I didn't know either, just played with the flags and thus it turned out to be the cause Smile .
Post 29 Jun 2009, 09:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.