Index: include/apr_portable.h
===================================================================
--- include/apr_portable.h	(revision 603256)
+++ include/apr_portable.h	(working copy)
@@ -369,6 +369,20 @@
                                              apr_pool_t *cont);
 
 /**
+ * convert the file from os specific type to apr type.
+ * @param file The apr file we are converting to.
+ * @param thefile The os specific pipe to convert
+ * @param flags The flags that were used to open this file.
+ * @param cont The pool to use if it is needed.
+ * @remark On Unix, it is only possible to put a file descriptor into
+ *         an apr file type.
+ */
+APR_DECLARE(apr_status_t) apr_os_pipe_flags_put(apr_file_t **file,
+                                             apr_os_file_t *thefile,
+                                             apr_int32_t flags,
+                                             apr_pool_t *cont);
+
+/**
  * convert the dir from os specific type to apr type.
  * @param dir The apr dir we are converting to.
  * @param thedir The os specific dir to convert
Index: file_io/unix/pipe.c
===================================================================
--- file_io/unix/pipe.c	(revision 603256)
+++ file_io/unix/pipe.c	(working copy)
@@ -138,6 +138,14 @@
                                              int register_cleanup,
                                              apr_pool_t *pool)
 {
+    return apr_os_pipe_flags_put(file, thefile, register_cleanup ? 0 : APR_FILE_NOCLEANUP, pool);
+}
+
+APR_DECLARE(apr_status_t) apr_os_pipe_flags_put(apr_file_t **file,
+                                             apr_os_file_t *thefile,
+                                             apr_int32_t flags,
+                                             apr_pool_t *pool)
+{
     int *dafile = thefile;
     
     (*file) = apr_pcalloc(pool, sizeof(apr_file_t));
@@ -148,14 +156,12 @@
     (*file)->timeout = -1;
     (*file)->ungetchar = -1; /* no char avail */
     (*file)->filedes = *dafile;
-    if (!register_cleanup) {
-        (*file)->flags = APR_FILE_NOCLEANUP;
-    }
+    (*file)->flags = flags;
     (*file)->buffered = 0;
 #if APR_HAS_THREADS
     (*file)->thlock = NULL;
 #endif
-    if (register_cleanup) {
+    if (!((*file)->flags & APR_FILE_NOCLEANUP)) {
         apr_pool_cleanup_register((*file)->pool, (void *)(*file),
                                   apr_unix_file_cleanup,
                                   apr_pool_cleanup_null);
@@ -179,46 +185,22 @@
 APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t *pool)
 {
     int filedes[2];
+    apr_status_t rc;
 
     if (pipe(filedes) == -1) {
         return errno;
     }
     
-    (*in) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
-    (*in)->pool = pool;
-    (*in)->filedes = filedes[0];
-    (*in)->is_pipe = 1;
-    (*in)->fname = NULL;
-    (*in)->buffered = 0;
+    if ((rc = apr_os_pipe_flags_put(in, &filedes[0], APR_INHERIT, pool)) != APR_SUCCESS)
+        return rc;
+
     (*in)->blocking = BLK_ON;
-    (*in)->timeout = -1;
-    (*in)->ungetchar = -1;
-    (*in)->flags = APR_INHERIT;
-#if APR_HAS_THREADS
-    (*in)->thlock = NULL;
-#endif
-#ifndef WAITIO_USES_POLL
-    (*in)->pollset = NULL;
-#endif
-    (*out) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
-    (*out)->pool = pool;
-    (*out)->filedes = filedes[1];
-    (*out)->is_pipe = 1;
-    (*out)->fname = NULL;
-    (*out)->buffered = 0;
+
+    if ((rc = apr_os_pipe_flags_put(out, &filedes[1], APR_INHERIT, pool)) != APR_SUCCESS)
+        return rc;
+
     (*out)->blocking = BLK_ON;
-    (*out)->flags = APR_INHERIT;
-    (*out)->timeout = -1;
-#if APR_HAS_THREADS
-    (*out)->thlock = NULL;
-#endif
-#ifndef WAITIO_USES_POLL
-    (*out)->pollset = NULL;
-#endif
-    apr_pool_cleanup_register((*in)->pool, (void *)(*in), apr_unix_file_cleanup,
-                         apr_pool_cleanup_null);
-    apr_pool_cleanup_register((*out)->pool, (void *)(*out), apr_unix_file_cleanup,
-                         apr_pool_cleanup_null);
+
     return APR_SUCCESS;
 }
 
