EINTR and "slow system calls" - Linux

This is a discussion on EINTR and "slow system calls" - Linux ; Hello All! I've searched through the google code search service: http://www.google.com/codesearch?hl=...B8%D1%81%D0%BA and found that code like this while ((r = read (fd, buf, len)) nothing*/ ; or like this while ((ret = read(f, buf, count)) restore_old_errno(old_errno); } is widely used ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: EINTR and "slow system calls"

  1. EINTR and "slow system calls"

    Hello All!

    I've searched through the google code search service:
    http://www.google.com/codesearch?hl=...B8%D1%81%D0%BA

    and found that code like this

    while ((r = read (fd, buf, len)) < 0 && errno == EINTR) /*do
    nothing*/ ;

    or like this

    while ((ret = read(f, buf, count)) < 0 && geterrno() == EINTR) {
    restore_old_errno(old_errno);
    }

    is widely used in open source projects.

    Is it correct at all?

    I always thought, that signal may terminate the system call in any
    point
    (in particular exactly before return).
    Will system calls correctly handle repeated calls?
    And why?

    Thanks!


  2. Re: EINTR and "slow system calls"

    Hello.

    > Hello All!
    >
    > I've searched through the google code search service:http://www.google.com/codesearch?hl=...read+%2B+EINTR...
    >
    > and found that code like this
    >
    > while ((r = read (fd, buf, len)) < 0 && errno == EINTR) /*do
    > nothing*/ ;
    >
    > or like this
    >
    > while ((ret = read(f, buf, count)) < 0 && geterrno() == EINTR) {
    > restore_old_errno(old_errno);
    >
    > }
    >
    > is widely used in open source projects.
    >
    > Is it correct at all?


    yep, if in this code SIGINT was caught or ignored

    >
    > I always thought, that signal may terminate the system call in any
    > point
    > (in particular exactly before return).


    why terminate? SIGINT can be just ignored or caught and replaced with
    some number of actions.
    I think, you just need to find in this code signal(SIGINT, handler)
    function.

    Good luck.



  3. Re: EINTR and "slow system calls"

    "Krivenok Dmitry" writes:
    > I've searched through the google code search service:
    > http://www.google.com/codesearch?hl=...B8%D1%81%D0%BA
    >
    > and found that code like this
    >
    > while ((r = read (fd, buf, len)) < 0 && errno == EINTR) /*do
    > nothing*/ ;
    >
    > or like this
    >
    > while ((ret = read(f, buf, count)) < 0 && geterrno() == EINTR) {
    > restore_old_errno(old_errno);
    > }
    >
    > is widely used in open source projects.
    >
    > Is it correct at all?
    >
    > I always thought, that signal may terminate the system call in any
    > point


    It may not. The system call implementation in the kernel
    needs to explictly check for a pending signal to be
    interruptible at all. If the call is implemented
    correctly, restarting it should work.


+ Reply to Thread