Ticket #2949 (new enhancement) — at Initial Version

Opened 11 years ago

Last modified 7 years ago

[ Optimization ]: replace pipe() by pipe2()

Reported by: pavlinux Owned by:
Priority: major Milestone:
Component: mc-core Version: master
Keywords: Cc: gotar@…
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

Description

Linux only :-P

  • The pipe2() was added to Linux in version 2.6.27. It is a variant of the normal
  • pipe syscall, but takes an extra flags argument which can be the ORed value of
  • O_NONBLOCK and O_CLOEXEC. The original pipe syscall is now defined as like the
  • pipe2 syscall, but with the flags variable set to zero.
  • The pipe2() glibc support is available starting with version 2.9.
  • The pipe2() is Linux-specific.
  • lib/utilunix.c

    diff --git a/lib/utilunix.c b/lib/utilunix.c
    index c3c6704..0127544 100644
    a b tilde_expand (const char *directory) 
    340340void 
    341341open_error_pipe (void) 
    342342{ 
    343     if (pipe (error_pipe) < 0) 
     343    if (pipe2(error_pipe, O_DIRECT) < 0) 
    344344    { 
    345345        message (D_NORMAL, _("Warning"), _("Pipe failed")); 
    346346    } 
  • src/background.c

    diff --git a/src/background.c b/src/background.c
    index a68fe86..affe8c0 100644
    a b do_background (struct FileOpContext *ctx, char *info) 
    514514    int back_comm[2];           /* back connection */ 
    515515    pid_t pid; 
    516516 
    517     if (pipe (comm) == -1) 
     517    if (pipe2(comm, O_DIRECT) == -1) 
    518518        return -1; 
    519519 
    520     if (pipe (back_comm) == -1) 
     520    if (pipe2(back_comm, O_DIRECT) == -1) 
    521521        return -1; 
    522522 
    523523    pid = fork (); 
  • src/cons.handler.c

    diff --git a/src/cons.handler.c b/src/cons.handler.c
    index 610db28..97a09b6 100644
    a b handle_console_linux (console_action_t action) 
    148148        status = close (pipefd1[1]); 
    149149        status = close (pipefd2[0]); 
    150150        /* Create two pipes for communication */ 
    151         if (!((pipe (pipefd1) == 0) && ((pipe (pipefd2)) == 0))) 
     151        if (!((pipe2(pipefd1, O_DIRECT) == 0) && ((pipe2(pipefd2, O_DIRECT)) == 0))) 
    152152        { 
    153153            mc_global.tty.console_flag = '\0'; 
    154154            break; 
  • src/subshell.c

    diff --git a/src/subshell.c b/src/subshell.c
    index 510cf4d..b19117a 100644
    a b init_subshell (void) 
    850850                return; 
    851851            } 
    852852        } 
    853         else /* subshell_type is BASH or ZSH */ if (pipe (subshell_pipe)) 
     853        else /* subshell_type is BASH or ZSH */ if (pipe2(subshell_pipe, O_DIRECT)) 
    854854        { 
    855855            perror (__FILE__ ": couldn't create pipe"); 
    856856            mc_global.tty.use_subshell = FALSE; 
  • src/vfs/fish/fish.c

    diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c
    index 5c84175..e02ec77 100644
    a b fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[]) 
    312312    int fileset1[2], fileset2[2]; 
    313313    int res; 
    314314 
    315     if ((pipe (fileset1) < 0) || (pipe (fileset2) < 0)) 
     315    if ((pipe2(fileset1, O_DIRECT) < 0) || (pipe2(fileset2, O_DIRECT) < 0)) 
    316316        vfs_die ("Cannot pipe(): %m."); 
    317317 
    318318    res = fork (); 
Note: See TracTickets for help on using tickets.