Bug 42365 - Suppress console for apr_proc_create() created process
Summary: Suppress console for apr_proc_create() created process
Status: NEW
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: 1.2.8
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-09 06:11 UTC by Joe Mudd
Modified: 2007-09-17 13:56 UTC (History)
0 users



Attachments
apr_thread_proc.h.diff (712 bytes, text/plain)
2007-07-13 14:58 UTC, Joe Mudd
Details
apr_arch_threadproc.h.diff.win32 (include/arch/win32/...) (300 bytes, text/plain)
2007-07-13 14:59 UTC, Joe Mudd
Details
proc.c.diff.beos (threadproc/beos/proc.c) (404 bytes, text/plain)
2007-07-13 15:00 UTC, Joe Mudd
Details
proc.c.diff.netware (threadproc/netware/proc.c) (408 bytes, text/plain)
2007-07-13 15:00 UTC, Joe Mudd
Details
proc.c.diff.os2 (threadproc/os2/proc.c) (404 bytes, text/plain)
2007-07-13 15:01 UTC, Joe Mudd
Details
proc.c.diff.unix (threadproc/unix/proc.c) (404 bytes, text/plain)
2007-07-13 15:01 UTC, Joe Mudd
Details
proc.c.diff.win32 (threadproc/win32/proc.c) (1.18 KB, text/plain)
2007-07-13 15:01 UTC, Joe Mudd
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Mudd 2007-05-09 06:11:58 UTC
I am creating child processes with:

   aStatus = apr_procattr_io_set(attr, APR_CHILD_BLOCK, APR_PARENT_BLOCK,
                                 APR_PARENT_BLOCK);
   ...
   aStatus = apr_procattr_cmdtype_set(attr, APR_SHELLCMD);

When created on Windows a console window is created.  I have added a new 
procattr call (apr_procattr_terminal_set) to allow the suppression of the 
console window.  Below are the diffs associated with the update.

Thanks for your consideration.

--- ../apr-1.2.8/./threadproc/netware/proc.c	Thu Aug  3 07:05:28 2006
+++ ./threadproc/netware/proc.c	Wed May  9 08:35:35 2007
@@ -47,6 +47,7 @@
     /* Default to a current path since NetWare doesn't handle it very well */
     apr_filepath_get(&((*new)->currdir), APR_FILEPATH_NATIVE, pool);
     (*new)->detached = 1;
+    (*new)->terminal = 1;
     return APR_SUCCESS;
 
 }
@@ -183,6 +184,13 @@
     attr->detached = detach;
     return APR_SUCCESS;
 }
+
+APR_DECLARE(apr_status_t) apr_procattr_terminal_set(apr_procattr_t *attr,
+                                                 apr_int32_t terminal)
+{
+    attr->terminal = terminal;
+    return APR_SUCCESS;
+}
 
 #if APR_HAS_FORK
 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
--- ../apr-1.2.8/./threadproc/win32/proc.c	Thu Aug  3 07:05:28 2006
+++ ./threadproc/win32/proc.c	Wed May  9 08:38:57 2007
@@ -58,6 +58,7 @@
     (*new) = (apr_procattr_t *)apr_pcalloc(pool, sizeof(apr_procattr_t));
     (*new)->pool = pool;
     (*new)->cmdtype = APR_PROGRAM;
+    (*new)->terminal = 1;
     return APR_SUCCESS;
 }
 
@@ -201,6 +202,13 @@
     return APR_SUCCESS;
 }
 
+APR_DECLARE(apr_status_t) apr_procattr_terminal_set(apr_procattr_t *attr,
+                                                 apr_int32_t terminal)
+{
+    attr->terminal = terminal;
+    return APR_SUCCESS;
+}
+
 static apr_status_t attr_cleanup(void *theattr)
 {
     apr_procattr_t *attr = (apr_procattr_t *)theattr;    
@@ -396,6 +404,15 @@
     new->out = attr->parent_out;
     new->err = attr->parent_err;
 
+    if (!attr->terminal) {
+        /* If we are launching a console application that is to run
+         * without a console window and we are not Win9x, let Windows
+         * know that we do not want a console.
+         */
+        if (apr_os_level >= APR_WIN_NT)
+             dwCreationFlags |= CREATE_NO_WINDOW;
+    }
+
     if (attr->detached) {
         /* If we are creating ourselves detached, Then we should hide the
          * window we are starting in.  And we had better redfine our
--- ../apr-1.2.8/./threadproc/beos/proc.c	Thu Aug  3 07:05:28 2006
+++ ./threadproc/beos/proc.c	Wed May  9 08:34:30 2007
@@ -41,6 +41,7 @@
     (*new)->currdir = NULL; 
     (*new)->cmdtype = APR_PROGRAM;
     (*new)->detached = 0;
+    (*new)->terminal = 1;
     return APR_SUCCESS;
 }
 
@@ -141,6 +142,13 @@
     attr->detached = detach;
     return APR_SUCCESS;
 }
+
+APR_DECLARE(apr_status_t) apr_procattr_terminal_set(apr_procattr_t *attr,
+                                                 apr_int32_t terminal)
+{
+    attr->terminal = terminal;
+    return APR_SUCCESS;
+}
 
 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
 {
--- ../apr-1.2.8/./threadproc/unix/proc.c	Thu Aug  3 07:05:28 2006
+++ ./threadproc/unix/proc.c	Wed May  9 08:37:21 2007
@@ -31,6 +31,7 @@
     (*new)->pool = pool;
     (*new)->cmdtype = APR_PROGRAM;
     (*new)->uid = (*new)->gid = -1;
+    (*new)->terminal = 1;
     return APR_SUCCESS;
 }
 
@@ -188,6 +189,13 @@
     attr->detached = detach;
     return APR_SUCCESS;
 }
+
+APR_DECLARE(apr_status_t) apr_procattr_terminal_set(apr_procattr_t *attr,
+                                                 apr_int32_t terminal)
+{
+    attr->terminal = terminal;
+    return APR_SUCCESS;
+}
 
 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
 {
--- ../apr-1.2.8/./threadproc/os2/proc.c	Thu Aug  3 07:05:28 2006
+++ ./threadproc/os2/proc.c	Wed May  9 08:36:38 2007
@@ -52,6 +52,7 @@
     (*new)->currdir = NULL; 
     (*new)->cmdtype = APR_PROGRAM;
     (*new)->detached = FALSE;
+    (*new)->terminal = TRUE;
     return APR_SUCCESS;
 }
 
@@ -188,6 +189,13 @@
     attr->detached = detach;
     return APR_SUCCESS;
 }
+
+APR_DECLARE(apr_status_t) apr_procattr_terminal_set(apr_procattr_t *attr,
+                                                 apr_int32_t terminal)
+{
+    attr->terminal = terminal;
+    return APR_SUCCESS;
+}
 
 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
 {
--- ../apr-1.2.8/./include/apr_thread_proc.h	Thu Aug  3 07:05:28 2006
+++ ./include/apr_thread_proc.h	Wed May  9 08:31:50 2007
@@ -473,6 +473,16 @@
 APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, 
                                                  apr_int32_t detach);
 
+
+/**
+ * Determine if the child should start with a terminal.
+ * @param attr The procattr we care about.
+ * @param background Should the child start with a terminal?  Default is yes.
+ */
+APR_DECLARE(apr_status_t) apr_procattr_terminal_set(apr_procattr_t *attr,
+                                                 apr_int32_t terminal);
+
+
 #if APR_HAVE_STRUCT_RLIMIT
 /**
  * Set the Resource Utilization limits when starting a new process.
--- ../apr-1.2.8/./include/arch/netware/apr_arch_threadproc.h	Thu Aug  3 
07:05:28 2006
+++ ./include/arch/netware/apr_arch_threadproc.h	Wed May  9 08:40:28 2007
@@ -61,6 +61,7 @@
     char *currdir;
     apr_int32_t cmdtype;
     apr_int32_t detached;
+    apr_int32_t terminal;
     apr_int32_t addrspace;
 };
 
--- ../apr-1.2.8/./include/arch/win32/apr_arch_threadproc.h	Thu Aug  3 
07:05:28 2006
+++ ./include/arch/win32/apr_arch_threadproc.h	Wed May  9 08:39:47 2007
@@ -55,6 +55,7 @@
     char *currdir;
     apr_int32_t cmdtype;
     apr_int32_t detached;
+    apr_int32_t terminal;
     apr_child_errfn_t *errfn;
     apr_int32_t errchk;
 #ifndef _WIN32_WCE
--- ../apr-1.2.8/./include/arch/beos/apr_arch_threadproc.h	Thu Aug  3 
07:05:28 2006
+++ ./include/arch/beos/apr_arch_threadproc.h	Wed May  9 08:40:48 2007
@@ -84,6 +84,7 @@
     char *currdir;
     apr_int32_t cmdtype;
     apr_int32_t detached;
+    apr_int32_t terminal;
 };
 
 struct apr_thread_once_t {
--- ../apr-1.2.8/./include/arch/unix/apr_arch_threadproc.h	Thu Aug  3 
07:05:28 2006
+++ ./include/arch/unix/apr_arch_threadproc.h	Wed May  9 08:40:01 2007
@@ -84,6 +84,7 @@
     char *currdir;
     apr_int32_t cmdtype;
     apr_int32_t detached;
+    apr_int32_t terminal;
 #ifdef RLIMIT_CPU
     struct rlimit *limit_cpu;
 #endif
--- ../apr-1.2.8/./include/arch/os2/apr_arch_threadproc.h	Thu Aug  3 
07:05:28 2006
+++ ./include/arch/os2/apr_arch_threadproc.h	Wed May  9 08:40:15 2007
@@ -56,6 +56,7 @@
     char *currdir;
     apr_int32_t cmdtype;
     apr_int32_t detached;
+    apr_int32_t terminal;
 };
 
 struct apr_thread_once_t {
Comment 1 Davi Arnaut 2007-05-12 10:46:40 UTC
A stub implementation of apr_procattr_terminal_set is missing for threadproc/unix.
Also, next time submit the patch as an attachment. Thanks.
Comment 2 Davi Arnaut 2007-05-12 10:49:16 UTC
(In reply to comment #1)
> A stub implementation of apr_procattr_terminal_set is missing for threadproc/unix.
> Also, next time submit the patch as an attachment. Thanks.

Oops, it's not. But the terminal flag won't be used then, do we really need it ?
Comment 3 Joe Mudd 2007-05-14 04:23:57 UTC
You are correct.  The terminal flag is not needed in threadproc/unix.  I placed 
it there in case someone else found a need.  It can be removed.

Sorry about the inline vs attachment.
Comment 4 Joe Mudd 2007-07-13 14:58:58 UTC
Created attachment 20511 [details]
apr_thread_proc.h.diff

Adding individual diffs for the pieces/parts affected.
Comment 5 Joe Mudd 2007-07-13 14:59:45 UTC
Created attachment 20512 [details]
apr_arch_threadproc.h.diff.win32 (include/arch/win32/...)
Comment 6 Joe Mudd 2007-07-13 15:00:16 UTC
Created attachment 20513 [details]
proc.c.diff.beos (threadproc/beos/proc.c)
Comment 7 Joe Mudd 2007-07-13 15:00:42 UTC
Created attachment 20514 [details]
proc.c.diff.netware (threadproc/netware/proc.c)
Comment 8 Joe Mudd 2007-07-13 15:01:04 UTC
Created attachment 20515 [details]
proc.c.diff.os2 (threadproc/os2/proc.c)
Comment 9 Joe Mudd 2007-07-13 15:01:27 UTC
Created attachment 20516 [details]
proc.c.diff.unix (threadproc/unix/proc.c)
Comment 10 Joe Mudd 2007-07-13 15:01:57 UTC
Created attachment 20517 [details]
proc.c.diff.win32 (threadproc/win32/proc.c)
Comment 11 Joe Mudd 2007-07-13 15:02:59 UTC
Updated the diffs to be against the latest greatest source and packaged them up 
as individual attachments.
Comment 12 William A. Rowe Jr. 2007-07-21 16:49:50 UTC
By default, we should be creating processes without a visible console.

Simply put, APR needs to create similar behavior across platforms, and
relieve the application author from dealing with platform quirks (such
as console windows popping up.)

I don't have a huge issue with offering console windows as a platform
feature where they can be supported, in apr 1.3.0 or later, but certainly
wouldn't want to see this become the default behavior.  terminal below
must default to 0.

So the gist of your patch (eliminating console windows) would be a good
addition across APR 0.9, 1.2 and trunk.  Adding the option would be of
interest only as a new API in trunk for version 1.3 or 2.0 (whichever
comes first) per our versioning rules.

Bottom line rule to apply is the principle of least surprise to authors
as they port from platform to platform.
Comment 13 Joe Mudd 2007-09-17 13:56:43 UTC
Do you require a new patch for 1.2 that always suppresses the console window?

I agree that the window should be suppressed.  The current patch was written to 
keep backwards compatibility in case there were uses that relied on the current 
behavior.

Also, unless indicated otherwise, I do not see a need for a new API in 1.3 nor 
2.0 once the windows source is updated to always suppress the console window.

Thanks.