id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking	branch_state	votes
2949	[ Optimization ]: replace pipe() by pipe2()	pavlinux		"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.


{{{#!diff
diff --git a/lib/utilunix.c b/lib/utilunix.c
index c3c6704..0127544 100644
--- a/lib/utilunix.c
+++ b/lib/utilunix.c
@@ -340,7 +340,7 @@ tilde_expand (const char *directory)
 void
 open_error_pipe (void)
 {
-    if (pipe (error_pipe) < 0)
+    if (pipe2(error_pipe, O_DIRECT) < 0)
     {
         message (D_NORMAL, _(""Warning""), _(""Pipe failed""));
     }
diff --git a/src/background.c b/src/background.c
index a68fe86..affe8c0 100644
--- a/src/background.c
+++ b/src/background.c
@@ -514,10 +514,10 @@ do_background (struct FileOpContext *ctx, char *info)
     int back_comm[2];           /* back connection */
     pid_t pid;
 
-    if (pipe (comm) == -1)
+    if (pipe2(comm, O_DIRECT) == -1)
         return -1;
 
-    if (pipe (back_comm) == -1)
+    if (pipe2(back_comm, O_DIRECT) == -1)
         return -1;
 
     pid = fork ();
diff --git a/src/cons.handler.c b/src/cons.handler.c
index 610db28..97a09b6 100644
--- a/src/cons.handler.c
+++ b/src/cons.handler.c
@@ -148,7 +148,7 @@ handle_console_linux (console_action_t action)
         status = close (pipefd1[1]);
         status = close (pipefd2[0]);
         /* Create two pipes for communication */
-        if (!((pipe (pipefd1) == 0) && ((pipe (pipefd2)) == 0)))
+        if (!((pipe2(pipefd1, O_DIRECT) == 0) && ((pipe2(pipefd2, O_DIRECT)) == 0)))
         {
             mc_global.tty.console_flag = '\0';
             break;
diff --git a/src/subshell.c b/src/subshell.c
index 510cf4d..b19117a 100644
--- a/src/subshell.c
+++ b/src/subshell.c
@@ -850,7 +850,7 @@ init_subshell (void)
                 return;
             }
         }
-        else /* subshell_type is BASH or ZSH */ if (pipe (subshell_pipe))
+        else /* subshell_type is BASH or ZSH */ if (pipe2(subshell_pipe, O_DIRECT))
         {
             perror (__FILE__ "": couldn't create pipe"");
             mc_global.tty.use_subshell = FALSE;
diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c
index 5c84175..e02ec77 100644
--- a/src/vfs/fish/fish.c
+++ b/src/vfs/fish/fish.c
@@ -312,7 +312,7 @@ fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
     int fileset1[2], fileset2[2];
     int res;
 
-    if ((pipe (fileset1) < 0) || (pipe (fileset2) < 0))
+    if ((pipe2(fileset1, O_DIRECT) < 0) || (pipe2(fileset2, O_DIRECT) < 0))
         vfs_die (""Cannot pipe(): %m."");
 
     res = fork ();

}}}

"	enhancement	new	major	Future Releases	mc-core	master						no branch	
