Author: markt
Date: Mon Nov 28 20:18:04 2016
New Revision: 1771804

URL: http://svn.apache.org/viewvc?rev=1771804&view=rev
Log:
Sync numerous changes from 1.0.x post the creation of trunk. The effect of this 
should be that trunk contains all the fixes from 1.0.x as of the time of this 
commit.

Added:
    commons/proper/daemon/trunk/src/assembly/win.xml   (with props)
Modified:
    commons/proper/daemon/trunk/NOTICE.txt
    commons/proper/daemon/trunk/build.xml
    commons/proper/daemon/trunk/pom.xml
    commons/proper/daemon/trunk/src/assembly/src.xml
    
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/DaemonInitException.java
    
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonConfiguration.java
    
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonWrapper.java
    commons/proper/daemon/trunk/src/native/unix/INSTALL.txt
    commons/proper/daemon/trunk/src/native/unix/configure.in
    commons/proper/daemon/trunk/src/native/unix/native/arguments.c
    commons/proper/daemon/trunk/src/native/unix/native/arguments.h
    commons/proper/daemon/trunk/src/native/unix/native/help.c
    commons/proper/daemon/trunk/src/native/unix/native/home.c
    commons/proper/daemon/trunk/src/native/unix/native/java.c
    commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c
    commons/proper/daemon/trunk/src/native/unix/native/location.c
    commons/proper/daemon/trunk/src/native/unix/native/version.h
    commons/proper/daemon/trunk/src/native/unix/support/apsupport.m4
    commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/Makefile
    commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.c
    commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.manifest
    commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.rc
    commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/Makefile
    commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c
    commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.rc
    commons/proper/daemon/trunk/src/native/windows/include/cmdline.h
    commons/proper/daemon/trunk/src/native/windows/include/javajni.h
    commons/proper/daemon/trunk/src/native/windows/include/log.h
    commons/proper/daemon/trunk/src/native/windows/resources/license.rtf
    commons/proper/daemon/trunk/src/native/windows/src/cmdline.c
    commons/proper/daemon/trunk/src/native/windows/src/javajni.c
    commons/proper/daemon/trunk/src/native/windows/src/log.c
    commons/proper/daemon/trunk/src/native/windows/src/rprocess.c
    commons/proper/daemon/trunk/src/native/windows/src/service.c
    commons/proper/daemon/trunk/src/native/windows/src/utils.c
    commons/proper/daemon/trunk/src/samples/AloneDaemon.sh
    commons/proper/daemon/trunk/src/samples/Native.sh
    commons/proper/daemon/trunk/src/site/xdoc/binaries.xml
    commons/proper/daemon/trunk/src/site/xdoc/download_daemon.xml
    commons/proper/daemon/trunk/src/site/xdoc/jsvc.xml
    commons/proper/daemon/trunk/src/site/xdoc/procrun.xml

Modified: commons/proper/daemon/trunk/NOTICE.txt
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/NOTICE.txt?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/NOTICE.txt (original)
+++ commons/proper/daemon/trunk/NOTICE.txt Mon Nov 28 20:18:04 2016
@@ -1,5 +1,5 @@
 Apache Commons Daemon
 Copyright 1999-2016 The Apache Software Foundation
 
-This product includes software developed at
+This product includes software developed by
 The Apache Software Foundation (http://www.apache.org/).

Modified: commons/proper/daemon/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/build.xml?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/build.xml (original)
+++ commons/proper/daemon/trunk/build.xml Mon Nov 28 20:18:04 2016
@@ -214,7 +214,7 @@
                 version="true"
                doctitle="<h1>${component.title}</h1>"
             windowtitle="${component.title} (Version ${component.version})"
-                 bottom="Copyright (c) 2002-2012 - Apache Software Foundation">
+                 bottom="Copyright (c) 2002-2016 - Apache Software Foundation">
       <classpath refid="compile.classpath"/>
       <classpath location="${ant.lib}/ant.jar"/>
     </javadoc>

Modified: commons/proper/daemon/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/pom.xml?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/pom.xml (original)
+++ commons/proper/daemon/trunk/pom.xml Mon Nov 28 20:18:04 2016
@@ -120,6 +120,7 @@
             <descriptor>src/assembly/native-src.xml</descriptor>
             <descriptor>src/assembly/bin.xml</descriptor>
             <descriptor>src/assembly/src.xml</descriptor>
+            <descriptor>src/assembly/win.xml</descriptor>
           </descriptors>
           <tarLongFileMode>gnu</tarLongFileMode>
         </configuration>

Modified: commons/proper/daemon/trunk/src/assembly/src.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/assembly/src.xml?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/assembly/src.xml (original)
+++ commons/proper/daemon/trunk/src/assembly/src.xml Mon Nov 28 20:18:04 2016
@@ -41,8 +41,10 @@
                 <exclude>native/unix/configure</exclude>
                 <exclude>native/unix/autom4te.cache/**</exclude>
                 <exclude>native/windows/**</exclude>
+                <!--
                 <exclude>media/**</exclude>
                 <exclude>site/**</exclude>
+                -->
             </excludes>
         </fileSet>
         <fileSet>

Added: commons/proper/daemon/trunk/src/assembly/win.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/assembly/win.xml?rev=1771804&view=auto
==============================================================================
--- commons/proper/daemon/trunk/src/assembly/win.xml (added)
+++ commons/proper/daemon/trunk/src/assembly/win.xml Mon Nov 28 20:18:04 2016
@@ -0,0 +1,46 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<assembly
+  xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0
 http://maven.apache.org/xsd/assembly-1.1.0.xsd";>
+    <id>bin-windows</id>
+    <formats>
+        <format>zip</format>
+    </formats>
+    <baseDirectory></baseDirectory>
+    <includeSiteDirectory>false</includeSiteDirectory>
+    <fileSets>
+        <fileSet>
+            <includes>
+                <include>LICENSE.txt</include>
+                <include>NOTICE.txt</include>
+                <include>RELEASE-NOTES.txt</include>
+            </includes>
+        </fileSet>
+        <fileSet>
+            <directory>target</directory>
+            <outputDirectory></outputDirectory>
+            <includes>
+                <include>*.exe</include>
+                <include>amd64/*.exe</include>
+                <include>ia64/*.exe</include>
+            </includes>
+        </fileSet>
+    </fileSets>
+</assembly>
+

Propchange: commons/proper/daemon/trunk/src/assembly/win.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/DaemonInitException.java
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/DaemonInitException.java?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- 
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/DaemonInitException.java
 (original)
+++ 
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/DaemonInitException.java
 Mon Nov 28 20:18:04 2016
@@ -20,6 +20,7 @@ package org.apache.commons.daemon;
  * Throw this during init if you can't initialise yourself for some expected 
  * reason.  Using this exception will cause the exception's message to come out
  * on stdout, rather than a dirty great stacktrace.
+ *
  * @author Nick Griffiths (nicobre...@gmail.com)
  * @version $Id$
  */

Modified: 
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonConfiguration.java?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- 
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonConfiguration.java
 (original)
+++ 
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonConfiguration.java
 Mon Nov 28 20:18:04 2016
@@ -116,8 +116,9 @@ public final class DaemonConfiguration
         int btoken;
         int ctoken = 0;
 
-        if (propValue == null)
+        if (propValue == null) {
             return null;
+        }
         expanded = new StringBuffer();
         btoken   = propValue.indexOf(BTOKEN);
         while (btoken != -1) {
@@ -175,7 +176,7 @@ public final class DaemonConfiguration
     /**
      * Gets the configuration property array.
      * <p>
-     * Property array is constructed form the lsit of properties
+     * Property array is constructed form the list of properties
      * which end with <code>[index]</code>
      * </p>
      * <pre>

Modified: 
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonWrapper.java
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonWrapper.java?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- 
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonWrapper.java
 (original)
+++ 
commons/proper/daemon/trunk/src/main/java/org/apache/commons/daemon/support/DaemonWrapper.java
 Mon Nov 28 20:18:04 2016
@@ -196,7 +196,7 @@ public class DaemonWrapper implements Da
         private String      call = null;
         private String[]    args = null;
         private Method      inst = null;
-        private Class<?>       main = null;
+        private Class<?>    main = null;
 
         protected Invoker()
         {

Modified: commons/proper/daemon/trunk/src/native/unix/INSTALL.txt
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/INSTALL.txt?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/INSTALL.txt (original)
+++ commons/proper/daemon/trunk/src/native/unix/INSTALL.txt Mon Nov 28 20:18:04 
2016
@@ -3,7 +3,7 @@ system you will need:
 
   An ANSI-C compliant compiler (GCC is good)
   A Java Platform 2 compliant SDK
-  GNU AutoConf (when building for SVN).
+  GNU AutoConf (when building from SVN).
 
 When building from SVN sources you need to build the "configure" program with:
 

Modified: commons/proper/daemon/trunk/src/native/unix/configure.in
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/configure.in?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/configure.in (original)
+++ commons/proper/daemon/trunk/src/native/unix/configure.in Mon Nov 28 
20:18:04 2016
@@ -59,8 +59,12 @@ AP_MSG_HEADER([Host support])
 AP_SUPPORTED_HOST()
 if test "$supported_os" = "darwin"
 then
+  if test -z "$JAVA_HOME" -a -x /usr/libexec/java_home
+  then
+    JAVA_HOME="`/usr/libexec/java_home 2>dev/null`"
+  fi
   if test -z "$JAVA_HOME" -a -d 
/System/Library/Frameworks/JavaVM.framework/Home; then
-       JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
+    JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
   fi
 
   _prevdir=`/bin/pwd`
@@ -115,7 +119,9 @@ fi
 AC_SUBST(LDCMD)
 if test "$supported_os" = "linux"
 then
-AC_CHECK_LIB([cap], [cap_init], [CFLAGS="$CFLAGS -DHAVE_LIBCAP" ; LIBS="$LIBS 
-lcap"])
+AC_CHECK_HEADER([sys/capability.h],
+                [CFLAGS="$CFLAGS -DHAVE_LIBCAP"],
+                AC_MSG_WARN([cannot find headers for libcap]))
 fi
 
 if test -z "$STRIPFLAGS"

Modified: commons/proper/daemon/trunk/src/native/unix/native/arguments.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/arguments.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/arguments.c (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/arguments.c Mon Nov 28 
20:18:04 2016
@@ -167,6 +167,7 @@ static arg_data *parse(int argc, char *a
     args->onum    = 0;            /* Zero arguments, but let's have some room 
*/
     args->clas    = NULL;         /* No class predefined */
     args->anum    = 0;            /* Zero class specific arguments but make 
room*/
+    args->cwd     = "/";           /* Use root as default */
     args->outfile = "/dev/null";   /* Swallow by default */
     args->errfile = "/dev/null";   /* Swallow by default */
     args->redirectstdin = true;    /* Redirect stdin to /dev/null by default */
@@ -237,6 +238,13 @@ static arg_data *parse(int argc, char *a
                 return NULL;
             }
         }
+        else if (!strcmp(argv[x], "-cwd")) {
+            args->cwd = optional(argc, argv, x++);
+            if (args->cwd == NULL) {
+                log_error("Invalid working directory specified");
+                return NULL;
+            }
+        }
         else if (!strcmp(argv[x], "-version")) {
             args->vers = true;
             args->dtch = false;
@@ -273,7 +281,8 @@ static arg_data *parse(int argc, char *a
                 log_error("Invalid umask specified");
                 return NULL;
             }
-            args->umask = atoi(temp);
+            /* Parameter must be in octal */
+            args->umask = (int)strtol(temp, NULL, 8);
             if (args->umask < 02) {
                 log_error("Invalid umask specified (min=02)");
                 return NULL;

Modified: commons/proper/daemon/trunk/src/native/unix/native/arguments.h
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/arguments.h?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/arguments.h (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/arguments.h Mon Nov 28 
20:18:04 2016
@@ -35,6 +35,8 @@ typedef struct {
     char *name;
     /** The JDK or JRE installation path (JAVA_HOME). */
     char *home;
+    /** Working directory (defaults to /). */
+    char *cwd;
     /** Options used to invoke the JVM. */
     char **opts;
     /** Number of JVM options. */

Modified: commons/proper/daemon/trunk/src/native/unix/native/help.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/help.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/help.c (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/help.c Mon Nov 28 
20:18:04 2016
@@ -60,6 +60,8 @@ void help(home_data *data)
     printf("        user used to run the daemon (defaults to current user)\n");
     printf("    -verbose[:class|gc|jni]\n");
     printf("        enable verbose output\n");
+    printf("    -cwd </full/path>\n");
+    printf("        set working directory to given location (defaults to 
/)\n");
     printf("    -outfile </full/path/to/file>\n");
     printf("        Location for output from stdout (defaults to 
/dev/null)\n");
     printf("        Use the value '&2' to simulate '1>&2'\n");
@@ -99,7 +101,7 @@ void help(home_data *data)
     printf("    -keepstdin\n");
     printf("        does not redirect stdin to /dev/null\n");
     printf("\njsvc (Apache Commons Daemon) " JSVC_VERSION_STRING "\n");
-    printf("Copyright (c) 1999-2011 Apache Software Foundation.\n");
+    printf("Copyright (c) 1999-2016 Apache Software Foundation.\n");
 
     printf("\n");
 }

Modified: commons/proper/daemon/trunk/src/native/unix/native/home.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/home.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/home.c (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/home.c Mon Nov 28 
20:18:04 2016
@@ -212,9 +212,13 @@ static home_data *find(char *path)
     home_data *data = NULL;
     int x = 0;
 
-    if (path == NULL) {
+    if (path == NULL || *path == '\0' || strcmp(path, "/") == 0) {
         log_debug("Home not specified on command line, using environment");
         path = getenv("JAVA_HOME");
+        if (path == NULL || *path == '\0' || strcmp(path, "/") == 0) {
+            /* guard against empty JAVA_HOME */
+            path = NULL;
+        }
     }
 
     if (path == NULL) {

Modified: commons/proper/daemon/trunk/src/native/unix/native/java.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/java.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/java.c (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/java.c Mon Nov 28 
20:18:04 2016
@@ -203,6 +203,13 @@ bool java_init(arg_data *args, home_data
             return false;
         }
     }
+    if (stat(appf, &sb)) {
+        if (replace(appf, 1024, "$JAVA_HOME/../MacOS/libjli.dylib",
+                    "$JAVA_HOME", data->path) != 0) {
+            log_error("Cannot replace values in loader library");
+            return false;
+        }
+    }
     apph = dso_link(appf);
     if (apph == NULL) {
         log_error("Cannot load required shell library %s", appf);

Modified: commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c Mon Nov 28 
20:18:04 2016
@@ -172,6 +172,48 @@ static int set_user_group(const char *us
 
 /* Set linux capability, user and group */
 #ifdef OS_LINUX
+/* CAPSALL is to allow to read/write at any location */
+#define LEGACY_CAPSALL  (1 << CAP_NET_BIND_SERVICE) +   \
+                        (1 << CAP_SETUID) +             \
+                        (1 << CAP_SETGID) +             \
+                        (1 << CAP_DAC_READ_SEARCH) +    \
+                        (1 << CAP_DAC_OVERRIDE)
+
+#define LEGACY_CAPSMAX  (1 << CAP_NET_BIND_SERVICE) +   \
+                        (1 << CAP_DAC_READ_SEARCH) +    \
+                        (1 << CAP_DAC_OVERRIDE)
+
+/* That a more reasonable configuration */
+#define LEGACY_CAPS     (1 << CAP_NET_BIND_SERVICE) +   \
+                        (1 << CAP_DAC_READ_SEARCH) +    \
+                        (1 << CAP_SETUID) +             \
+                        (1 << CAP_SETGID)
+
+/* probably the only one Java could use */
+#define LEGACY_CAPSMIN  (1 << CAP_NET_BIND_SERVICE) +   \
+                        (1 << CAP_DAC_READ_SEARCH)
+
+#define LEGACY_CAP_VERSION  0x19980330
+static int set_legacy_caps(int caps)
+{
+    struct __user_cap_header_struct caphead;
+    struct __user_cap_data_struct   cap;
+
+    memset(&caphead, 0, sizeof caphead);
+    caphead.version = LEGACY_CAP_VERSION;
+    caphead.pid = 0;
+    memset(&cap, 0, sizeof cap);
+    cap.effective = caps;
+    cap.permitted = caps;
+    cap.inheritable = caps;
+    if (syscall(__NR_capset, &caphead, &cap) < 0) {
+        log_error("set_caps: failed to set capabilities");
+        log_error("check that your kernel supports capabilities");
+        return -1;
+    }
+    return 0;
+}
+
 #ifdef HAVE_LIBCAP
 static cap_value_t caps_std[] = {
     CAP_NET_BIND_SERVICE,
@@ -188,6 +230,77 @@ static cap_value_t caps_min[] = {
 #define CAPS     1
 #define CAPSMIN  2
 
+
+typedef int     (*fd_cap_free)(void *);
+typedef cap_t   (*fd_cap_init)(void);
+typedef int     (*fd_cap_clear)(cap_t);
+typedef int     (*fd_cap_get_flag)(cap_t, cap_value_t, cap_flag_t, 
cap_flag_value_t *);
+typedef int     (*fd_cap_set_flag)(cap_t, cap_flag_t, int, const cap_value_t 
*, cap_flag_value_t);
+typedef int     (*fd_cap_set_proc)(cap_t);
+
+static dso_handle hlibcap = NULL;
+static fd_cap_free  fp_cap_free;
+static fd_cap_init  fp_cap_init;
+static fd_cap_clear fp_cap_clear;
+static fd_cap_get_flag fp_cap_get_flag;
+static fd_cap_set_flag fp_cap_set_flag;
+static fd_cap_set_proc fp_cap_set_proc;
+
+static const char *libcap_locs[] = {
+#ifdef __LP64__
+    "/lib64/libcap.so.2",
+    "/lib64/libcap.so.1",
+    "/lib64/libcap.so",
+    "/usr/lib64/libcap.so.2",
+    "/usr/lib64/libcap.so.1",
+    "/usr/lib64/libcap.so",
+#endif
+    "/lib/libcap.so.2",
+    "/lib/libcap.so.1",
+    "/lib/libcap.so",
+    "/usr/lib/libcap.so.2",
+    "/usr/lib/libcap.so.1",
+    "/usr/lib/libcap.so",
+    "libcap.so.2",
+    "libcap.so.1",
+    "libcap.so",
+    NULL
+};
+
+static int ld_libcap(void)
+{
+    int i = 0;
+    dso_handle dso = NULL;
+#define CAP_LDD(name) \
+    if ((fp_##name = dso_symbol(dso, #name)) == NULL) { \
+        log_error("cannot locate " #name " in libcap.so -- %s", dso_error());  
\
+        dso_unlink(dso);    \
+        return -1;          \
+    } else log_debug("loaded " #name " from libcap.")
+
+    if (hlibcap != NULL)
+        return 0;
+    while (libcap_locs[i] && dso == NULL) {
+        if ((dso = dso_link(libcap_locs[i++])))
+            break;
+    };
+    if (dso == NULL) {
+        log_error("failed loading capabilities library -- %s.", dso_error());
+        return -1;
+    }
+    CAP_LDD(cap_free);
+    CAP_LDD(cap_init);
+    CAP_LDD(cap_clear);
+
+    CAP_LDD(cap_get_flag);
+    CAP_LDD(cap_set_flag);
+    CAP_LDD(cap_set_proc);
+    hlibcap = dso;
+#undef CAP_LDD
+    return 0;
+}
+
+
 static int set_caps(int cap_type)
 {
     cap_t c;
@@ -196,6 +309,9 @@ static int set_caps(int cap_type)
     cap_value_t *caps;
     const char  *type;
 
+    if (ld_libcap()) {
+        return set_legacy_caps(cap_type);
+    }
     if (cap_type == CAPS) {
         ncap = sizeof(caps_std)/sizeof(cap_value_t);
         caps = caps_std;
@@ -212,16 +328,16 @@ static int set_caps(int cap_type)
         type = "null";
         flag = CAP_CLEAR;
     }
-    c = cap_init();
-    cap_clear(c);
-    cap_set_flag(c, CAP_EFFECTIVE,   ncap, caps, flag);
-    cap_set_flag(c, CAP_INHERITABLE, ncap, caps, flag);
-    cap_set_flag(c, CAP_PERMITTED,   ncap, caps, flag);
-    if (cap_set_proc(c) != 0) {
+    c = (*fp_cap_init)();
+    (*fp_cap_clear)(c);
+    (*fp_cap_set_flag)(c, CAP_EFFECTIVE,   ncap, caps, flag);
+    (*fp_cap_set_flag)(c, CAP_INHERITABLE, ncap, caps, flag);
+    (*fp_cap_set_flag)(c, CAP_PERMITTED,   ncap, caps, flag);
+    if ((*fp_cap_set_proc)(c) != 0) {
         log_error("failed setting %s capabilities.", type);
         return -1;
     }
-    cap_free(c);
+    (*fp_cap_free)(c);
     if (cap_type == CAPS)
         log_debug("increased capability set.");
     else if (cap_type == CAPSMIN)
@@ -233,45 +349,13 @@ static int set_caps(int cap_type)
 
 #else /* !HAVE_LIBCAP */
 /* CAPSALL is to allow to read/write at any location */
-#define CAPSALL (1 << CAP_NET_BIND_SERVICE) +   \
-                (1 << CAP_SETUID) +             \
-                (1 << CAP_SETGID) +             \
-                (1 << CAP_DAC_READ_SEARCH) +    \
-                (1 << CAP_DAC_OVERRIDE)
-
-#define CAPSMAX (1 << CAP_NET_BIND_SERVICE) +   \
-                (1 << CAP_DAC_READ_SEARCH) +    \
-                (1 << CAP_DAC_OVERRIDE)
-
-/* That a more reasonable configuration */
-#define CAPS    (1 << CAP_NET_BIND_SERVICE) +   \
-                (1 << CAP_DAC_READ_SEARCH) +    \
-                (1 << CAP_SETUID) +             \
-                (1 << CAP_SETGID)
-
-/* probably the only one Java could use */
-#define CAPSMIN (1 << CAP_NET_BIND_SERVICE) +   \
-                (1 << CAP_DAC_READ_SEARCH)
-
-#define LEGACY_CAP_VERSION  0x19980330
+#define CAPSALL LEGACY_CAPSALL
+#define CAPSMAX LEGACY_CAPSMAX
+#define CAPS    LEGACY_CAPS
+#define CAPSMIN LEGACY_CAPSMIN
 static int set_caps(int caps)
 {
-    struct __user_cap_header_struct caphead;
-    struct __user_cap_data_struct   cap;
-
-    memset(&caphead, 0, sizeof caphead);
-    caphead.version = LEGACY_CAP_VERSION;
-    caphead.pid = 0;
-    memset(&cap, 0, sizeof cap);
-    cap.effective = caps;
-    cap.permitted = caps;
-    cap.inheritable = caps;
-    if (syscall(__NR_capset, &caphead, &cap) < 0) {
-        log_error("set_caps: failed to set capabilities");
-        log_error("check that your kernel supports capabilities");
-        return -1;
-    }
-    return 0;
+    return set_legacy_caps(caps);
 }
 #endif
 
@@ -414,6 +498,56 @@ static sighandler_t signal_set(int sig,
     return hand;
 }
 
+static int mkdir0(const char *name, int perms)
+{
+    if (mkdir(name, perms) == 0)
+        return 0;
+    else
+        return errno;
+}
+
+static int mkdir1(char *name, int perms)
+{
+    int rc;
+
+    rc = mkdir0(name, perms);
+    if (rc == EEXIST)
+        return 0;
+    if (rc == ENOENT) {  /* Missing an intermediate dir */
+        char *pos;
+        if ((pos = strrchr(name, '/'))) {
+            *pos = '\0';
+            if (*name) {
+                if (!(rc = mkdir1(name, perms))) {
+                    /* Try again, now with parents created
+                     */
+                    *pos = '/';
+                    rc = mkdir0(name, perms);
+                }
+            }
+            *pos = '/';
+        }
+    }
+    return rc;
+}
+
+static int mkdir2(const char *name, int perms)
+{
+    int rc = 0;
+    char *pos;
+    char *dir = strdup(name);
+
+    if (!dir)
+        return ENOMEM;
+    if ((pos = strrchr(dir, '/'))) {
+        *pos = '\0';
+        if (*dir)
+            rc = mkdir1(dir, perms);
+    }
+    free(dir);
+    return rc;
+}
+
 /*
  * Check pid and if still running
  */
@@ -425,9 +559,16 @@ static int check_pid(arg_data *args)
     char buff[80];
     pid_t pidn = getpid();
     int i, pid;
+    int once = 0;
 
-    fd = open(args->pidf, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+retry:
+    fd = open(args->pidf, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | 
S_IROTH);
     if (fd < 0) {
+        if (once == 0 && (errno == ENOTDIR || errno == ENOENT)) {
+            once = 1;
+            if (mkdir2(args->pidf, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | 
S_IROTH) == 0)
+                goto retry;
+        }
         log_error("Cannot open PID file %s, PID is %d", args->pidf, pidn);
         return -1;
     }
@@ -650,13 +791,6 @@ static int child(arg_data *args, home_da
             return ret;
     }
 
-    /* create a new process group to prevent kill 0 killing the monitor 
process */
-#if defined(OS_FREEBSD) || defined(OS_DARWIN)
-    setpgid(0, 0);
-#else
-    setpgrp();
-#endif
-
 #ifdef OS_LINUX
     /* setuid()/setgid() only apply the current thread so we must do it now */
     if (linuxset_user_group(args->user, uid, gid) != 0)
@@ -781,6 +915,7 @@ static FILE *loc_freopen(char *outfile,
 {
     FILE *ftest;
 
+    mkdir2(outfile, S_IRWXU);
     ftest = fopen(outfile, mode);
     if (ftest == NULL) {
         fprintf(stderr, "Unable to redirect to %s\n", outfile);
@@ -1024,6 +1159,16 @@ int main(int argc, char *argv[])
         char *p1  = NULL;
         char *p2  = NULL;
 
+        /* We don't want to use a form of exec() that searches the
+         * PATH, so require that argv[0] be either an absolute or
+         * relative path.  Error out if this isn't the case.
+         */
+        tmp = strchr(argv[0], '/');
+        if (tmp == NULL) {
+            log_error("JSVC re-exec requires execution with an absolute or 
relative path");
+            return 1;
+        }
+
         /*
          * There is no need to change LD_LIBRARY_PATH
          * if we were not able to find a path to libjvm.so
@@ -1088,6 +1233,10 @@ int main(int argc, char *argv[])
 #endif
     }
 
+    if (chdir(args->cwd)) {
+        log_error("ERROR: jsvc was unable to "
+                  "change directory to: %s", args->cwd);
+    }
     /*
      * umask() uses inverse logic; bits are CLEAR for allowed access.
      */

Modified: commons/proper/daemon/trunk/src/native/unix/native/location.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/location.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/location.c (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/location.c Mon Nov 28 
20:18:04 2016
@@ -33,10 +33,20 @@ char *location_home[] = {
     "/System/Library/Frameworks/JavaVM.framework/Home",
     "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/",
 #elif defined(OS_LINUX) || defined(OS_SOLARIS) || defined(OS_BSD)
+    "/usr/java/default",
     "/usr/java",
     "/usr/local/java",
+    "/usr/lib/jvm/default-java",
+    "/usr/lib/jvm/java",
     "/etc/alternatives/java_sdk",
+    "/etc/alternatives/java_sdk_openjdk",
     "/etc/alternatives/jre",
+#if defined(__LP64__)
+    "/lib64/jvm/java",
+    "/lib64/jvm/java-openjdk",
+#endif
+    "/lib/jvm/java",
+    "/lib/jvm/java-openjdk",
 #elif defined(OS_CYGWIN)
     "/cygdrive/c/WINNT/system32/java",
 #elif defined(OS_SYSV)
@@ -74,6 +84,8 @@ char *location_jvm_cfg[] = {
 char *location_jvm_default[] = {
 #if defined(OS_DARWIN)
     "$JAVA_HOME/../Libraries/libjvm.dylib",
+    "$JAVA_HOME/jre/lib/server/libjvm.dylib",
+    "$JAVA_HOME/jre/lib/client/libjvm.dylib",
 #elif defined(OS_CYGWIN)
     "$JAVA_HOME/jre/bin/classic/jvm.dll",               /* Sun JDK 1.3 */
     "$JAVA_HOME/jre/bin/client/jvm.dll",                /* Sun JDK 1.4 */
@@ -131,6 +143,7 @@ char *location_jvm_default[] = {
  */
 char *location_jvm_configured[] = {
 #if defined(OS_DARWIN)
+    "$JAVA_HOME/jre/lib/$VM_NAME/libjvm.dylib",
     "$JAVA_HOME/../Libraries/lib$VM_NAME.dylib",
 #elif defined(OS_CYGWIN)
     "$JAVA_HOME/jre/bin/$VM_NAME/jvm.dll",              /* Sun JDK 1.3 */

Modified: commons/proper/daemon/trunk/src/native/unix/native/version.h
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/version.h?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/version.h (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/version.h Mon Nov 28 
20:18:04 2016
@@ -28,16 +28,16 @@
  * Minor API changes that do not cause binary compatibility problems.
  * Should be reset to 0 when upgrading JSVC_MAJOR_VERSION
  */
-#define JSVC_MINOR_VERSION      0
+#define JSVC_MINOR_VERSION      1
 
 /** patch level */
-#define JSVC_PATCH_VERSION      8
+#define JSVC_PATCH_VERSION      0
 
 /**
  *  This symbol is defined for internal, "development" copies of JSVC.
  *  This symbol will be #undef'd for releases.
  */
-#define JSVC_IS_DEV_VERSION     0
+#define JSVC_IS_DEV_VERSION     1
 
 /** Properly quote a value as a string in the C preprocessor */
 #define JSVC_STRINGIFY(n) JSVC_STRINGIFY_HELPER(n)

Modified: commons/proper/daemon/trunk/src/native/unix/support/apsupport.m4
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/support/apsupport.m4?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/support/apsupport.m4 (original)
+++ commons/proper/daemon/trunk/src/native/unix/support/apsupport.m4 Mon Nov 28 
20:18:04 2016
@@ -45,11 +45,13 @@ AC_DEFUN(AP_SUPPORTED_HOST,[
   sysv)
     CFLAGS="$CFLAGS -DOS_SYSV -DDSO_DLFCN"
     LIBS="$LIBS -ldl"
+    supported_os="sysv"
     ;;
   sysv4)
     CFLAGS="$CFLAGS -DOS_SYSV -DDSO_DLFCN -Kthread"
     LDFLAGS="-Kthread $LDFLAGS"
     LIBS="$LIBS -ldl"
+    supported_os="sysv4"
     ;;
   freebsd*)
     CFLAGS="$CFLAGS -DOS_FREEBSD -DDSO_DLFCN -D_THREAD_SAFE -pthread"
@@ -59,16 +61,17 @@ AC_DEFUN(AP_SUPPORTED_HOST,[
   osf5*)
     CFLAGS="$CFLAGS -pthread -DOS_TRU64 -DDSO_DLFCN -D_XOPEN_SOURCE_EXTENDED"
     LDFLAGS="$LDFLAGS -pthread"
+    supported_os="osf5"
     ;;
   hpux*)
-    CFLAGS="$CFLAGS -pthread -DOS_HPUX -DDSO_DLFCN"
-    LDFLAGS="$LDFLAGS -pthread"
-    LIBS="$LIBS -lpthread"
+    CFLAGS="$CFLAGS -DOS_HPUX -DDSO_DLFCN"
     supported_os="hp-ux"
+    host_os="hpux"
     ;;
   aix5*)
     CFLAGS="$CFLAGS -DOS_AIX -DDSO_DLFCN"
     LDFLAGS="$LDFLAGS -ldl"
+    supported_os="aix5"
     ;;
   kfreebsd*-gnu)
     CFLAGS="$CFLAGS -DOS_BSD -DDSO_DLFCN -pthread"
@@ -88,65 +91,84 @@ AC_DEFUN(AP_SUPPORTED_HOST,[
   case $host_cpu in
   powerpc64)
     CFLAGS="$CFLAGS -DCPU=\\\"ppc64\\\""
-    HOST_CPU=ppc64;;
+    HOST_CPU=ppc64
+    ;;
   powerpc64le)
     CFLAGS="$CFLAGS -DCPU=\\\"ppc64le\\\""
-    HOST_CPU=ppc64le;;
+    HOST_CPU=ppc64le
+    ;;
   powerpc*)
     CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\""
-    HOST_CPU=$host_cpu;;
+    HOST_CPU=$host_cpu
+    ;;
   sparc*)
     CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\""
-    HOST_CPU=$host_cpu;;
+    HOST_CPU=$host_cpu
+    ;;
   i?86|x86)
     CFLAGS="$CFLAGS -DCPU=\\\"i386\\\""
-    HOST_CPU=i386;;
+    HOST_CPU=i386
+    ;;
   x86_64 | amd64)
     CFLAGS="$CFLAGS -DCPU=\\\"amd64\\\""
-    HOST_CPU=amd64;;
+    HOST_CPU=amd64
+    ;;
   bs2000)
     CFLAGS="$CFLAGS -DCPU=\\\"osd\\\" -DCHARSET_EBCDIC -DOSD_POSIX"
     supported_os="osd"
     LDFLAGS="-Kno_link_stdlibs -B llm4"
     LIBS="$LIBS -lBLSLIB"
     LDCMD="/opt/C/bin/cc"
-    HOST_CPU=osd;;
+    HOST_CPU=osd
+    ;;
   mips | mipsn32 | mips64)
     CFLAGS="$CFLAGS -DCPU=\\\"mips\\\""
     supported_os="mips"
-    HOST_CPU=mips;;
+    HOST_CPU=mips
+    ;;
   alpha*)
     CFLAGS="$CFLAGS -DCPU=\\\"alpha\\\""
     supported_os="alpha"
-    HOST_CPU=alpha;;
+    HOST_CPU=alpha
+    ;;
   hppa2.0w|hppa64)
     CFLAGS="$CFLAGS -DCPU=\\\"PA_RISC2.0W\\\" -DSO_EXT=\\\"sl\\\""
-    HOST_CPU=PA_RISC2.0W;;
-  hppa2.0n)
+    host_cpu=hppa2.0w
+    HOST_CPU=PA_RISC2.0W
+    ;;
+  hppa2.0n|hppa32)
     CFLAGS="$CFLAGS -DCPU=\\\"PA_RISC2.0N\\\" -DSO_EXT=\\\"sl\\\""
-    HOST_CPU=PA_RISC2.0N;;
+    HOST_CPU=PA_RISC2.0N
+    ;;
   hppa2.0)
-    CFLAGS="$CFLAGS -DCPU=\\\"PA_RISC2.0\\\" -DSO_EXT=\\\"sl\\\""
-    HOST_CPU=PA_RISC2.0;;
+    if test "$host_os" = "hpux"
+    then
+        host_cpu=hppa2.0w
+        HOST_CPU=PA_RISC2.0W
+    else
+        HOST_CPU=PA_RISC2.0
+    fi
+    CFLAGS="$CFLAGS -DCPU=\\\"$HOST_CPU\\\" -DSO_EXT=\\\"sl\\\""
+    ;;
   mipsel | mipsn32el | mips64el)
     CFLAGS="$CFLAGS -DCPU=\\\"mipsel\\\""
     supported_os="mipsel"
-    HOST_CPU=mipsel;;
+    HOST_CPU=mipsel
+    ;;
   ia64w)
-    if test "$supported_os" = "hp-ux"
-    then
-        CFLAGS="$CFLAGS -mlp64 -DCPU=\\\"IA64W\\\" -DSO_EXT=\\\"so\\\""
-        LDFLAGS="$LDFLAGS -mlp64"
-    else
-        CFLAGS="$CFLAGS -DCPU=\\\"ia64\\\""
-    fi
-    HOST_CPU=ia64;;
-  ia64|ia64n)
-    if test "$supported_os" = "hp-ux"
+    CFLAGS="$CFLAGS -DCPU=\\\"IA64W\\\" -DSO_EXT=\\\"so\\\""
+    HOST_CPU=IA64W
+    ;;
+  ia64n)
+    CFLAGS="$CFLAGS -DCPU=\\\"IA64N\\\" -DSO_EXT=\\\"so\\\""
+    HOST_CPU=IA64N
+    ;;
+  ia64)
+    if test "$host_os" = "hpux"
     then
-        CFLAGS="$CFLAGS -milp32 -DCPU=\\\"IA64N\\\" -DSO_EXT=\\\"so\\\""
-        LDFLAGS="$LDFLAGS -milp32"
-        HOST_CPU=IA64N
+        CFLAGS="$CFLAGS -DCPU=\\\"IA64W\\\" -DSO_EXT=\\\"so\\\""
+        host_cpu=ia64w
+        HOST_CPU=IA64W
     else
         CFLAGS="$CFLAGS -DCPU=\\\"ia64\\\""
         HOST_CPU=ia64
@@ -158,22 +180,63 @@ AC_DEFUN(AP_SUPPORTED_HOST,[
   s390 | s390x)
     CFLAGS="$CFLAGS -DCPU=\\\"s390\\\""
     supported_os="s390"
-    HOST_CPU=s390;;
+    HOST_CPU=s390
+    ;;
   arm*)
     CFLAGS="$CFLAGS -DCPU=\\\"arm\\\""
     supported_os="arm"
-    HOST_CPU=arm  
+    HOST_CPU=arm
     ;;
-  aarch64*)
+  aarch64)
     CFLAGS="$CFLAGS -DCPU=\\\"aarch64\\\""
-    supported_os="linux"
+    supported_os="aarch64"
     HOST_CPU=aarch64
-    ;;  
+    ;;
   *)
     AC_MSG_RESULT([failed])
     AC_MSG_ERROR([Unsupported CPU architecture "$host_cpu"]);;
   esac
 
+  if test "x$GCC" = "xyes"
+  then
+    case $host_os-$host_cpu in
+    hpux-ia64n)
+        CFLAGS="-milp32 -pthread $CFLAGS"
+        LDFLAGS="-milp32 -pthread $LDFLAGS"
+        LIBS="$LIBS -lpthread"
+    ;;
+    hpux-ia64w)
+        CFLAGS="-mlp64 -pthread $CFLAGS"
+        LDFLAGS="-mlp64 -pthread $LDFLAGS"
+        LIBS="$LIBS -lpthread"
+    ;;
+    hpux-*)
+        CFLAGS="-pthread $CFLAGS"
+        LDFLAGS="-pthread $LDFLAGS"
+        LIBS="$LIBS -lpthread"
+    ;;
+    *)
+    ;;
+    esac
+  else
+    case $host_os-$host_cpu in
+    hpux-ia64n|hpux-hppa2.0n)
+        CFLAGS="+DD32 -mt $CFLAGS"
+        LDFLAGS="+DD32 -mt $LDFLAGS"
+    ;;
+    hpux-ia64w|hpux-hppa2.0w)
+        CFLAGS="+DD64 -mt $CFLAGS"
+        LDFLAGS="+DD64 -mt $LDFLAGS"
+    ;;
+    hpux-*)
+        CFLAGS="-mt $CFLAGS"
+        LDFLAGS="-mt $LDFLAGS"
+    ;;
+    *)
+    ;;
+    esac
+  fi
+
   AC_MSG_RESULT([ok])
   AC_SUBST(CFLAGS)
   AC_SUBST(LDFLAGS)

Modified: commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/Makefile
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/Makefile?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/Makefile 
(original)
+++ commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/Makefile Mon 
Nov 28 20:18:04 2016
@@ -22,12 +22,19 @@ UNICODE = 1
 !include <..\..\include\Makefile.inc>
 
 !IF !DEFINED(PREFIX) || "$(PREFIX)" == ""
-PREFIX = .\..\..\dist
+PREFIX = .\..\..\..\..\..\target
 !ENDIF
 !IF !DEFINED(SRCDIR) || "$(SRCDIR)" == ""
 SRCDIR = .\..\..
 !ENDIF
 
+!IF "$(CPU)" == "X64"
+PREFIX = $(PREFIX)\amd64
+!ENDIF
+!IF "$(CPU)" == "I64"
+PREFIX = $(PREFIX)\ia64
+!ENDIF
+
 LFLAGS = $(LFLAGS) /version:1.0 /DYNAMICBASE /NXCOMPAT
 LIBS = $(LIBS) user32.lib gdi32.lib winspool.lib comdlg32.lib comctl32.lib 
shlwapi.lib netapi32.lib
 INCLUDES = -I$(SRCDIR)\include -I$(SRCDIR)\src $(JAVA_INCLUDES)

Modified: commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.c 
(original)
+++ commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.c Mon 
Nov 28 20:18:04 2016
@@ -561,6 +561,8 @@ void __generalPropertyRefresh(HWND hDlg)
 }
 
 static BOOL bpropCentered = FALSE;
+static HWND _generalPropertyHwnd = NULL;
+
 LRESULT CALLBACK __generalProperty(HWND hDlg,
                                    UINT uMessage,
                                    WPARAM wParam,
@@ -572,6 +574,7 @@ LRESULT CALLBACK __generalProperty(HWND
     switch (uMessage) {
         case WM_INITDIALOG:
             {
+                _generalPropertyHwnd = hDlg;
                 if (!bEnableTry)
                     apxCenterWindow(GetParent(hDlg), NULL);
                 else if (!bpropCentered)
@@ -1469,6 +1472,7 @@ void ShowServiceProperties(HWND hWnd)
 
     PropertySheetW(&psH);
     _propertyOpened = FALSE;
+    _generalPropertyHwnd = NULL;
     if (!bEnableTry)
         PostQuitMessage(0);
      bpropCentered = FALSE;
@@ -1485,8 +1489,10 @@ static void signalService(LPCWSTR szServ
     lstrlcatW(en, SIZ_DESLEN, szServiceName);
     lstrlcatW(en, SIZ_DESLEN, L"SIGNAL");
     for (i = 7; i < lstrlenW(en); i++) {
-        if (en[i] >= L'a' && en[i] <= L'z')
-            en[i] = en[i] - 32;
+        if (en[i] == L' ')
+            en[i] = L'_';
+        else
+            en[i] = towupper(en[i]);
     }
 
 
@@ -1609,6 +1615,27 @@ static BOOL saveConfiguration()
     return TRUE;
 }
 
+static BOOL isManagerRunning = FALSE;
+static DWORD WINAPI refreshThread(LPVOID lpParam)
+{
+    while (isManagerRunning) {
+        /* Refresh property window */
+        DWORD os = 0;
+        if (_currentEntry)
+            os = _currentEntry->stServiceStatus.dwCurrentState;
+        _currentEntry = apxServiceEntry(hService, TRUE);
+        if (_currentEntry && _currentEntry->stServiceStatus.dwCurrentState != 
os) {
+            if (_gui_store->hMainWnd)
+                PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                            MAKEWPARAM(IDMS_REFRESH, 0), 0);
+            if (_generalPropertyHwnd)
+                __generalPropertyRefresh(_generalPropertyHwnd);
+        }
+        Sleep(1000);
+    }
+    return 0;
+}
+
 /* Main program entry
  * Since we are inependant from CRT
  * the arguments are not used
@@ -1738,6 +1765,8 @@ int WINAPI WinMain(HINSTANCE hInstance,
             apxDisplayError(TRUE, NULL, 0, apxLoadResourceA(IDS_ERRSREG, 0));
         return FALSE;
     }
+    isManagerRunning = TRUE;
+    CreateThread(NULL, 0, refreshThread, NULL, 0, NULL);
     /* Create main invisible window */
     _gui_store->hMainWnd = CreateWindow(_gui_store->szWndClass,
                                         apxLoadResource(IDS_APPLICATION, 0),
@@ -1751,7 +1780,6 @@ int WINAPI WinMain(HINSTANCE hInstance,
     }
     if (lpCmdline->dwCmdIndex == 3)
         PostMessage(_gui_store->hMainWnd, WM_COMMAND, IDM_TM_START, 0);
-
     while (GetMessage(&msg, NULL, 0, 0))  {
         if(!TranslateAccelerator(_gui_store->hMainWnd,
                                  _gui_store->hAccel, &msg)) {
@@ -1759,6 +1787,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
             DispatchMessage(&msg);
         }
     }
+    isManagerRunning = FALSE;
     saveConfiguration();
 
 cleanup:

Modified: 
commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.manifest
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.manifest?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- 
commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.manifest 
(original)
+++ 
commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.manifest 
Mon Nov 28 20:18:04 2016
@@ -23,4 +23,12 @@
 <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" 
version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" 
language="*" />
 </dependentAssembly>
 </dependency>
+<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+<security>
+<!-- Windows UAC support -->
+<requestedPrivileges>
+<requestedExecutionLevel level="requireAdministrator" 
uiAccess="false"></requestedExecutionLevel>
+</requestedPrivileges>
+</security>
+</trustInfo>
 </assembly>

Modified: commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.rc
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.rc?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.rc 
(original)
+++ commons/proper/daemon/trunk/src/native/windows/apps/prunmgr/prunmgr.rc Mon 
Nov 28 20:18:04 2016
@@ -42,7 +42,7 @@ BEGIN
                     ES_READONLY | WS_BORDER | WS_VSCROLL,0,31,335,115
     CONTROL         
"BMP_JAKARTA",IDC_STATIC,"Static",SS_BITMAP|0x00000040L,0,0,337,30
     LTEXT           " ",IDC_ABOUTAPP,2,150,270,12
-    LTEXT           "Copyright (c) 2000-2012 The Apache Software 
Foundation.",IDC_STATIC,2,160,270,12
+    LTEXT           "Copyright (c) 2000-2016 The Apache Software 
Foundation.",IDC_STATIC,2,160,270,12
     LTEXT           "http://commons.apache.org",IDC_STATIC,2,170,270,12
     PUSHBUTTON      "&System Info",IAB_SYSINF,285,170,50,14
 END
@@ -230,7 +230,7 @@ BEGIN
     IDS_APPLICATION     RSTR_PSM
     IDS_APPVERSION      "Version 1.1.0"
     IDS_APPFULLNAME     RSTR_PSM " Version " PRG_VERSION
-    IDS_APPCOPYRIGHT    "Copyright (c) 2000-2012 The Apache Software 
Foundation"
+    IDS_APPCOPYRIGHT    "Copyright (c) 2000-2016 The Apache Software 
Foundation"
     IDS_APPDESCRIPTION  "Apache Commons Daemon Service Management Tool"
     IDS_ALREAY_RUNING   "An instance of '%S' application is already running"
     IDS_ERRORCMD        "Unknown command line option '%s'\nSee the manual for 
command line usage."
@@ -280,7 +280,7 @@ BEGIN
       VALUE "FileDescription", RSTR_PSM "\0"
       VALUE "FileVersion", PRG_VERSION
       VALUE "InternalName", RSTR_PSM "\0"
-      VALUE "LegalCopyright", "Copyright (c) 2000-2012 The Apache Software 
Foundation.\0"
+      VALUE "LegalCopyright", "Copyright (c) 2000-2016 The Apache Software 
Foundation.\0"
       VALUE "OriginalFilename", "prunmgr.exe\0"
       VALUE "ProductName", RSTR_PSM "\0"
       VALUE "ProductVersion", PRG_VERSION

Modified: commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/Makefile
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/Makefile?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/Makefile 
(original)
+++ commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/Makefile Mon 
Nov 28 20:18:04 2016
@@ -22,7 +22,7 @@ UNICODE = 1
 !include <..\..\include\Makefile.inc>
 
 !IF !DEFINED(PREFIX) || "$(PREFIX)" == ""
-PREFIX = .\..\..\dist
+PREFIX = .\..\..\..\..\..\target
 !ENDIF
 !IF !DEFINED(SRCDIR) || "$(SRCDIR)" == ""
 SRCDIR = .\..\..

Modified: commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c 
(original)
+++ commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c Mon 
Nov 28 20:18:04 2016
@@ -263,8 +263,11 @@ DWORD WINAPI eventThread(LPVOID lpParam)
             continue;
         }
         if (dw == WAIT_OBJECT_0 && gSignalValid) {
-            if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0))
-                apxLogWrite(APXLOG_MARK_SYSERR);
+            if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0)) {
+                /* Invoke Thread dump */
+                if (gWorker && _jni_startup)
+                    apxJavaDumpAllStacks(gWorker);
+            }
             ResetEvent(gSignalEvent);
             continue;
         }
@@ -284,24 +287,22 @@ static BOOL redirectStdStreams(APX_STDWR
     BOOL aErr = FALSE;
     BOOL aOut = FALSE;
 
-    if (lpWrapper->szStdOutFilename || lpWrapper->szStdErrFilename) {
-        /* Alloc console if it doesn't exists. */
-        if (!AttachConsole(ATTACH_PARENT_PROCESS) &&
-             GetLastError() == ERROR_INVALID_HANDLE) {
-            HWND hc;
-            AllocConsole();
-            if ((hc = GetConsoleWindow()) != NULL)
-                ShowWindow(hc, SW_HIDE);
-        }
+    /* Allocate console if we have none
+     */
+    if (GetConsoleWindow() == NULL) {
+        HWND hc;
+        AllocConsole();
+        if ((hc = GetConsoleWindow()) != NULL)
+            ShowWindow(hc, SW_HIDE);
     }
     /* redirect to file or console */
     if (lpWrapper->szStdOutFilename) {
         if (lstrcmpiW(lpWrapper->szStdOutFilename, PRSRV_AUTO) == 0) {
             WCHAR lsn[1024];
             aOut = TRUE;
-            lstrcpyW(lsn, lpCmdline->szApplication);
+            lstrlcpyW(lsn, 1020, lpCmdline->szApplication);
+            lstrlcatW(lsn, 1020, L"-stdout");
             lstrlocaseW(lsn);
-            lstrcatW(lsn, L"-stdout");
             lpWrapper->szStdOutFilename = apxLogFile(gPool,
                                                      lpWrapper->szLogPath,
                                                      lsn,
@@ -326,9 +327,9 @@ static BOOL redirectStdStreams(APX_STDWR
         if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
             WCHAR lsn[1024];
             aErr = TRUE;
-            lstrcpyW(lsn, lpCmdline->szApplication);
+            lstrlcpyW(lsn, 1020, lpCmdline->szApplication);
+            lstrlcatW(lsn, 1020, L"-stderr");
             lstrlocaseW(lsn);
-            lstrcatW(lsn, L"-stderr");
             lpWrapper->szStdErrFilename = apxLogFile(gPool,
                                                      lpWrapper->szLogPath,
                                                      lsn,
@@ -382,7 +383,7 @@ static void printVersion(void)
 {
     fwprintf(stderr, L"Commons Daemon Service Runner version %S/Win%d (%S)\n",
             PRG_VERSION, PRG_BITS, __DATE__);
-    fwprintf(stderr, L"Copyright (c) 2000-2012 The Apache Software 
Foundation.\n\n"
+    fwprintf(stderr, L"Copyright (c) 2000-2016 The Apache Software 
Foundation.\n\n"
                      L"For bug reporting instructions, please see:\n"
                      L"<URL:https://issues.apache.org/jira/browse/DAEMON>.");
 }
@@ -555,6 +556,7 @@ static BOOL docmdInstallService(LPAPXCMD
     DWORD dwStart = SERVICE_DEMAND_START;
     DWORD dwType  = SERVICE_WIN32_OWN_PROCESS;
     WCHAR szImage[SIZ_HUGLEN];
+    WCHAR szName[SIZ_BUFLEN];
 
     apxLogWrite(APXLOG_MARK_DEBUG "Installing service...");
     hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
@@ -579,12 +581,15 @@ static BOOL docmdInstallService(LPAPXCMD
         lstrlcatW(szImage, SIZ_HUGLEN, L".exe");
     }
     else
-        lstrcpyW(szImage, SO_INSTALL);
+        lstrlcpyW(szImage, SIZ_HUGLEN, SO_INSTALL);
     /* Replace not needed quotes */
     apxStrQuoteInplaceW(szImage);
     /* Add run-service command line option */
-    lstrlcatW(szImage, SIZ_HUGLEN, L" //RS//");
-    lstrlcatW(szImage, SIZ_HUGLEN, lpCmdline->szApplication);
+    lstrlcatW(szImage, SIZ_HUGLEN, L" ");
+    lstrlcpyW(szName, SIZ_BUFLEN, L"//RS//");
+    lstrlcatW(szName, SIZ_BUFLEN, lpCmdline->szApplication);
+    apxStrQuoteInplaceW(szName);
+    lstrlcatW(szImage, SIZ_HUGLEN, szName);
     SO_INSTALL = apxPoolStrdupW(gPool, szImage);
     /* Ensure that option gets saved in the registry */
     ST_INSTALL |= APXCMDOPT_FOUND;
@@ -826,24 +831,29 @@ static BOOL docmdUpdateService(LPAPXCMDL
 }
 
 
-/* Report the service status to the SCM
+/* Report the service status to the SCM, including service specific exit code
  */
-int reportServiceStatus(DWORD dwCurrentState,
-                        DWORD dwWin32ExitCode,
-                        DWORD dwWaitHint)
+static BOOL reportServiceStatusE(DWORD dwCurrentState,
+                                 DWORD dwWin32ExitCode,
+                                 DWORD dwWaitHint,
+                                 DWORD dwServiceSpecificExitCode)
 {
    static DWORD dwCheckPoint = 1;
    BOOL fResult = TRUE;
 
+   apxLogWrite(APXLOG_MARK_DEBUG "reportServiceStatusE: %d, %d, %d, %d",
+               dwCurrentState, dwWin32ExitCode, dwWaitHint, 
dwServiceSpecificExitCode);
+
    if (_service_mode && _service_status_handle) {
-       if (dwCurrentState == SERVICE_START_PENDING)
-            _service_status.dwControlsAccepted = 0;
+       if (dwCurrentState == SERVICE_RUNNING)
+            _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP | 
SERVICE_ACCEPT_SHUTDOWN;
         else
-            _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+            _service_status.dwControlsAccepted = 0;
 
        _service_status.dwCurrentState  = dwCurrentState;
        _service_status.dwWin32ExitCode = dwWin32ExitCode;
        _service_status.dwWaitHint      = dwWaitHint;
+       _service_status.dwServiceSpecificExitCode = dwServiceSpecificExitCode;
 
        if ((dwCurrentState == SERVICE_RUNNING) ||
            (dwCurrentState == SERVICE_STOPPED))
@@ -853,11 +863,29 @@ int reportServiceStatus(DWORD dwCurrentS
        fResult = SetServiceStatus(_service_status_handle, &_service_status);
        if (!fResult) {
            /* TODO: Deal with error */
+           apxLogWrite(APXLOG_MARK_ERROR "Failed to set service status");
        }
    }
    return fResult;
 }
 
+/* Report the service status to the SCM
+ */
+static BOOL reportServiceStatus(DWORD dwCurrentState,
+                                DWORD dwWin32ExitCode,
+                                DWORD dwWaitHint)
+{
+    return reportServiceStatusE(dwCurrentState, dwWin32ExitCode, dwWaitHint, 
0);
+}
+
+static BOOL reportServiceStatusStopped(DWORD exitCode)
+{
+    if (exitCode) {
+        return reportServiceStatusE(SERVICE_STOPPED, 
ERROR_SERVICE_SPECIFIC_ERROR, 0, exitCode);
+    } else {
+        return reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+    }
+}
 
 BOOL child_callback(APXHANDLE hObject, UINT uMsg,
                     WPARAM wParam, LPARAM lParam)
@@ -880,7 +908,7 @@ static int onExitStop(void)
 {
     if (_service_mode) {
         apxLogWrite(APXLOG_MARK_DEBUG "Stop exit hook called ...");
-        reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+        reportServiceStatusStopped(0);
     }
     return 0;
 }
@@ -889,7 +917,16 @@ static int onExitStart(void)
 {
     if (_service_mode) {
         apxLogWrite(APXLOG_MARK_DEBUG "Start exit hook called ...");
-        reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+        apxLogWrite(APXLOG_MARK_DEBUG "VM exit code: %d", apxGetVmExitCode());
+        /* Reporting the service as stopped even with a non-zero exit code
+         * will not cause recovery actions to be initiated, so don't report at 
all.
+         * "A service is considered failed when it terminates without 
reporting a
+         * status of SERVICE_STOPPED to the service controller"
+         * http://msdn.microsoft.com/en-us/library/ms685939(VS.85).aspx
+         */
+        if (apxGetVmExitCode() == 0) {
+            reportServiceStatusStopped(0);
+        }
     }
     return 0;
 }
@@ -943,15 +980,17 @@ static DWORD WINAPI serviceStop(LPVOID l
             apxLogWrite(APXLOG_MARK_ERROR "Failed starting java");
             rv = 3;
         }
-        else if (lstrcmpA(_jni_sclass, "java/lang/System") == 0) {
-            reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 5000);
-            apxLogWrite(APXLOG_MARK_DEBUG "Forcing java jni System.exit worker 
to finish...");
-            return 0;
-        }
         else {
-            apxLogWrite(APXLOG_MARK_DEBUG "Waiting for java jni stop worker to 
finish...");
-            apxJavaWait(hWorker, INFINITE, FALSE);
-            apxLogWrite(APXLOG_MARK_DEBUG "Java jni stop worker finished.");
+            if (lstrcmpA(_jni_sclass, "java/lang/System") == 0) {
+                reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 20 * 1000);
+                apxLogWrite(APXLOG_MARK_DEBUG "Forcing java jni System.exit 
worker to finish...");
+                return 0;
+            }
+            else {
+                apxLogWrite(APXLOG_MARK_DEBUG "Waiting for java jni stop 
worker to finish...");
+                apxJavaWait(hWorker, INFINITE, FALSE);
+                apxLogWrite(APXLOG_MARK_DEBUG "Java jni stop worker 
finished.");
+            }
         }
         wait_to_die = TRUE;
     }
@@ -979,7 +1018,7 @@ static DWORD WINAPI serviceStop(LPVOID l
         }
         if (!apxProcessSetExecutableW(hWorker, SO_STOPIMAGE)) {
             apxLogWrite(APXLOG_MARK_ERROR "Failed setting process executable 
%S",
-                           SO_STOPIMAGE);
+                        SO_STOPIMAGE);
             rv = 2;
             goto cleanup;
         }
@@ -1037,7 +1076,6 @@ cleanup:
         CloseHandle(gSignalThread);
         gSignalEvent = NULL;
     }
-    SetEvent(gShutdownEvent);
     if (timeout > 0x7FFFFFFF)
         timeout = INFINITE;     /* If the timeout was '-1' wait forewer */
     if (wait_to_die && !timeout)
@@ -1073,8 +1111,8 @@ cleanup:
         apxHandleSendMessage(gWorker, WM_CLOSE, 0, 0);
     }
 
-    apxLogWrite(APXLOG_MARK_INFO "Service stopped.");
-    reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+    apxLogWrite(APXLOG_MARK_INFO "Service stop thread completed.");
+    SetEvent(gShutdownEvent);
     return rv;
 }
 
@@ -1159,6 +1197,8 @@ static DWORD serviceStart()
             /* Add LibraryPath to the PATH */
            apxAddToPathW(gPool, SO_LIBPATH);
         }
+        /* Set the environment using putenv, so JVM can use it */
+        setInprocEnvironment();
         /* Redirect process */
         gWorker = apxCreateProcessW(gPool,
                                     0,
@@ -1258,12 +1298,14 @@ void WINAPI service_ctrl_handler(DWORD d
     HANDLE stopThread;
 
     switch (dwCtrlCode) {
+        case SERVICE_CONTROL_SHUTDOWN:
+            apxLogWrite(APXLOG_MARK_INFO "Service SHUTDOWN signalled");
         case SERVICE_CONTROL_STOP:
-            reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3000);
+            reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3 * 1000);
             /* Stop the service asynchronously */
             stopThread = CreateThread(NULL, 0,
                                       serviceStop,
-                                      (LPVOID)SERVICE_CONTROL_STOP,
+                                      (LPVOID)dwCtrlCode,
                                       0, &threadId);
 #if 0
             /* Seems we don't need to wait for the stop thread
@@ -1272,18 +1314,6 @@ void WINAPI service_ctrl_handler(DWORD d
             WaitForSingleObject(stopThread, INFINITE);
 #endif
             CloseHandle(stopThread);
-
-            return;
-        case SERVICE_CONTROL_SHUTDOWN:
-            apxLogWrite(APXLOG_MARK_INFO "Service SHUTDOWN signaled");
-            reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3000);
-            /* Stop the service asynchronously */
-            stopThread = CreateThread(NULL, 0,
-                                      serviceStop,
-                                      (LPVOID)SERVICE_CONTROL_SHUTDOWN,
-                                      0, &threadId);
-            WaitForSingleObject(stopThread, INFINITE);
-            CloseHandle(stopThread);
             return;
         case SERVICE_CONTROL_INTERROGATE:
             reportServiceStatus(_service_status.dwCurrentState,
@@ -1334,8 +1364,7 @@ void WINAPI serviceMain(DWORD argc, LPTS
     DWORD rc = 0;
     _service_status.dwServiceType      = SERVICE_WIN32_OWN_PROCESS;
     _service_status.dwCurrentState     = SERVICE_START_PENDING;
-    _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
-                                         SERVICE_ACCEPT_PAUSE_CONTINUE;
+    _service_status.dwControlsAccepted = SERVICE_CONTROL_INTERROGATE;
     _service_status.dwWin32ExitCode    = 0;
     _service_status.dwCheckPoint       = 0;
     _service_status.dwWaitHint         = 0;
@@ -1351,7 +1380,10 @@ void WINAPI serviceMain(DWORD argc, LPTS
         lstrlcatW(en, SIZ_DESLEN, _service_name);
         lstrlcatW(en, SIZ_DESLEN, PRSRV_SIGNAL);
         for (i = 7; i < lstrlenW(en); i++) {
-            en[i] = towlower(en[i]);
+            if (en[i] == L' ')
+                en[i] = L'_';
+            else
+                en[i] = towupper(en[i]);
         }
         gSignalEvent = CreateEventW(sa, TRUE, FALSE, en);
         CleanNullACL((void *)sa);
@@ -1504,15 +1536,18 @@ void WINAPI serviceMain(DWORD argc, LPTS
         goto cleanup;
     }
     if (gShutdownEvent) {
-        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+
         /* Ensure that shutdown thread exits before us */
         apxLogWrite(APXLOG_MARK_DEBUG "Waiting for ShutdownEvent");
+        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);
         WaitForSingleObject(gShutdownEvent, ONE_MINUTE);
-        apxLogWrite(APXLOG_MARK_DEBUG "ShutdownEvent signalled");
+        apxLogWrite(APXLOG_MARK_DEBUG "ShutdownEvent signaled");
         CloseHandle(gShutdownEvent);
+
         /* This will cause to wait for all threads to exit
          */
         apxLogWrite(APXLOG_MARK_DEBUG "Waiting 1 minute for all threads to 
exit");
+        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, ONE_MINUTE);
         apxDestroyJvm(ONE_MINUTE);
     }
     else {
@@ -1525,12 +1560,12 @@ void WINAPI serviceMain(DWORD argc, LPTS
         reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
     }
     apxLogWrite(APXLOG_MARK_DEBUG "JVM destroyed.");
-    reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+    reportServiceStatusStopped(apxGetVmExitCode());
 
     return;
 cleanup:
     /* Cleanup */
-    reportServiceStatus(SERVICE_STOPPED, ERROR_SERVICE_SPECIFIC_ERROR, rc);
+    reportServiceStatusStopped(rc);
     gExitval = rc;
     return;
 }
@@ -1635,9 +1670,9 @@ void __cdecl main(int argc, char **argv)
         goto cleanup;
     }
     apxCmdlineLoadEnvVars(lpCmdline);
-    if (lpCmdline->dwCmdIndex < 5) {
+    if (lpCmdline->dwCmdIndex < 6) {
         if (!loadConfiguration(lpCmdline) &&
-            lpCmdline->dwCmdIndex < 4) {
+            lpCmdline->dwCmdIndex < 5) {
             apxLogWrite(APXLOG_MARK_ERROR "Load configuration failed");
             rv = 2;
             goto cleanup;
@@ -1734,8 +1769,6 @@ cleanup:
         apxLogWrite(APXLOG_MARK_INFO "Commons Daemon procrun finished");
     if (lpCmdline)
         apxCmdlineFree(lpCmdline);
-    if (_service_status_handle)
-        CloseHandle(_service_status_handle);
     _service_status_handle = NULL;
     _service_mode = FALSE;
     _flushall();

Modified: commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.rc
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.rc?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.rc 
(original)
+++ commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.rc Mon 
Nov 28 20:18:04 2016
@@ -44,7 +44,7 @@ BEGIN
       VALUE "FileDescription", RSTR_PRUNSRV "\0"
       VALUE "FileVersion", PRG_VERSION
       VALUE "InternalName", RSTR_PRUNSRV "\0"
-      VALUE "LegalCopyright", "Copyright (c) 2000-2012 The Apache Software 
Foundation.\0"
+      VALUE "LegalCopyright", "Copyright (c) 2000-2016 The Apache Software 
Foundation.\0"
       VALUE "OriginalFilename", "prunsrv.exe\0"
       VALUE "ProductName", RSTR_PRUNSRV "\0"
       VALUE "ProductVersion", PRG_VERSION

Modified: commons/proper/daemon/trunk/src/native/windows/include/cmdline.h
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/include/cmdline.h?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/include/cmdline.h (original)
+++ commons/proper/daemon/trunk/src/native/windows/include/cmdline.h Mon Nov 28 
20:18:04 2016
@@ -30,8 +30,8 @@ __APXBEGIN_DECLS
 #define APXCMDOPT_SRV   0x00000200  /* Save to service registry */
 #define APXCMDOPT_USR   0x00000400  /* Save to user registry */
 
-#define APXCMDOPT_FOUND 0x00001000  /* The option is present in cmdline */
-#define APXCMDOPT_ADD   0x00002000  /* The option is present in cmdline as ++*/
+#define APXCMDOPT_FOUND 0x00001000  /* The option is present in cmdline as -- 
*/
+#define APXCMDOPT_ADD   0x00002000  /* The option is present in cmdline as ++ 
*/
 
 
 typedef struct APXCMDLINEOPT APXCMDLINEOPT;

Modified: commons/proper/daemon/trunk/src/native/windows/include/javajni.h
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/include/javajni.h?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/include/javajni.h (original)
+++ commons/proper/daemon/trunk/src/native/windows/include/javajni.h Mon Nov 28 
20:18:04 2016
@@ -32,7 +32,7 @@ typedef struct stAPXJAVA_THREADARGS
     DWORD       bJniVfprintf;
     LPCSTR      szClassName;
     LPCSTR      szMethodName;
-    LPCVOID     lpArguments;    
+    LPCVOID     lpArguments;
     BOOL        setErrorOrOut;
     LPCWSTR     szStdErrFilename;
     LPCWSTR     szStdOutFilename;
@@ -63,6 +63,11 @@ DWORD       apxJavaSetOptions(APXHANDLE
 
 BOOL        apxDestroyJvm(DWORD dwTimeout);
 
+DWORD       apxGetVmExitCode();
+
+void        apxSetVmExitCode(DWORD exitCode);
+
+void        apxJavaDumpAllStacks(APXHANDLE hJava);
 
 __APXEND_DECLS
 

Modified: commons/proper/daemon/trunk/src/native/windows/include/log.h
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/include/log.h?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/include/log.h (original)
+++ commons/proper/daemon/trunk/src/native/windows/include/log.h Mon Nov 28 
20:18:04 2016
@@ -38,6 +38,16 @@ __APXBEGIN_DECLS
         UnlockFile(file, 0, 0, 512, 0);             \
     APXMACRO_END
 
+#define APX_LOGENTER()                              \
+    if (_pt_sys_loglock)                            \
+        EnterCriticalSection(_pt_sys_loglock);      \
+    else (void)0
+
+#define APX_LOGLEAVE()                              \
+    if (_pt_sys_loglock)                            \
+        LeaveCriticalSection(_pt_sys_loglock);      \
+    else (void)0
+
 #define APXLOG_LEVEL_DEBUG  0
 #define APXLOG_LEVEL_INFO   1
 #define APXLOG_LEVEL_WARN   2

Modified: commons/proper/daemon/trunk/src/native/windows/resources/license.rtf
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/resources/license.rtf?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
Binary files - no diff available.

Modified: commons/proper/daemon/trunk/src/native/windows/src/cmdline.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/cmdline.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/cmdline.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/cmdline.c Mon Nov 28 
20:18:04 2016
@@ -179,6 +179,21 @@ LPAPXCMDLINE apxCmdlineParse(
                     lpOptions[l].dwType |= APXCMDOPT_FOUND;
                     break;
                 }
+                if (add) {
+                    if (!(lpOptions[l].dwType & APXCMDOPT_FOUND)) {
+                        /* Only set add flag in case there was no --option
+                         */
+                        lpOptions[l].dwType |= APXCMDOPT_ADD;
+                    }
+                }
+                else if (lpOptions[l].dwType & APXCMDOPT_ADD) {
+                    /* We have ++option --option ...
+                     * Discard earlier values and go over.
+                     */
+                     lpOptions[l].dwType &= ~APXCMDOPT_ADD;
+                     lpOptions[l].dwValue = 0;
+                     lpOptions[l].szValue = 0;
+                }
                 if (lpOptions[l].dwType & APXCMDOPT_STR)
                     lpOptions[l].szValue = val;
                 else if (lpOptions[l].dwType & APXCMDOPT_INT)
@@ -214,8 +229,6 @@ LPAPXCMDLINE apxCmdlineParse(
                     }
                 }
                 lpOptions[l].dwType |= APXCMDOPT_FOUND;
-                if (add)
-                    lpOptions[l].dwType |= APXCMDOPT_ADD;
                 match = l + 1;
                 break;
             }
@@ -249,7 +262,7 @@ void apxCmdlineFree(
  * Each variable is prfixed with PR_
  * for example 'set PR_JVM=auto' has a same meaning as providing '--Jvm auto'
  * on the command line.
- * Multistring varisables are added to the present conf.
+ * Multistring variables are added to the present conf.
  */
 void apxCmdlineLoadEnvVars(
     LPAPXCMDLINE lpCmdline)

Modified: commons/proper/daemon/trunk/src/native/windows/src/javajni.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/javajni.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/javajni.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/javajni.c Mon Nov 28 
20:18:04 2016
@@ -47,6 +47,9 @@ static DYNLOAD_FPTR_DECLARE(JNI_CreateJa
 DYNOLAD_TYPE_DECLARE(JNI_GetCreatedJavaVMs, JNICALL, jint)(JavaVM **, jsize, 
jsize *);
 static DYNLOAD_FPTR_DECLARE(JNI_GetCreatedJavaVMs) = NULL;
 
+DYNOLAD_TYPE_DECLARE(JVM_DumpAllStacks, JNICALL, void)(JNIEnv *, jclass);
+static DYNLOAD_FPTR_DECLARE(JVM_DumpAllStacks) = NULL;
+
 static HANDLE  _st_sys_jvmDllHandle = NULL;
 static JavaVM *_st_sys_jvm = NULL;
 
@@ -113,6 +116,7 @@ typedef struct APXJAVAVM {
     DWORD           dwWorkerStatus;
     SIZE_T          szStackSize;
     HANDLE          hWorkerSync;
+    HANDLE          hWorkerInit;
 } APXJAVAVM, *LPAPXJAVAVM;
 
 /* This is no longer exported in jni.h
@@ -139,31 +143,42 @@ typedef struct APX_JDK1_1InitArgs {
 #define JAVA_CLASSSTRING    "java/lang/String"
 #define MSVCRT71_DLLNAME    L"\\msvcrt71.dll"
 
-static __inline BOOL __apxJvmAttach(LPAPXJAVAVM lpJava)
+static DWORD vmExitCode = 0;
+
+static __inline BOOL __apxJvmAttachEnv(LPAPXJAVAVM lpJava, JNIEnv **lpEnv,
+                                       LPBOOL lpAttached)
 {
     jint _iStatus;
 
-    if (!_st_sys_jvm)
+    if (!_st_sys_jvm || !lpJava->lpJvm)
       return FALSE;
     _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
-                                          (void **)&(lpJava->lpEnv),
+                                          (void **)lpEnv,
                                           lpJava->iVersion);
     if (_iStatus != JNI_OK) {
-        if (_iStatus == JNI_EDETACHED)
+        if (_iStatus == JNI_EDETACHED) {
             _iStatus = (*(lpJava->lpJvm))->AttachCurrentThread(lpJava->lpJvm,
-                                                (void **)&(lpJava->lpEnv), 
NULL);
+                                                (void **)lpEnv, NULL);
+            if (lpAttached)
+                *lpAttached = TRUE;
+        }
     }
     if (_iStatus != JNI_OK) {
-        lpJava->lpEnv = NULL;
+        *lpEnv = NULL;
         return FALSE;
     }
     else
         return TRUE;
 }
 
+static __inline BOOL __apxJvmAttach(LPAPXJAVAVM lpJava)
+{
+    return __apxJvmAttachEnv(lpJava, &lpJava->lpEnv, NULL);
+}
+
 static __inline BOOL __apxJvmDetach(LPAPXJAVAVM lpJava)
 {
-    if (!_st_sys_jvm)
+    if (!_st_sys_jvm || !lpJava->lpJvm)
       return FALSE;
     if ((*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm) != JNI_OK) {
         lpJava->lpEnv = NULL;
@@ -183,10 +198,22 @@ static BOOL __apxLoadJvmDll(LPCWSTR szJv
     if (!IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
         return TRUE;    /* jvm.dll is already loaded */
 
-    if (!dllJvmPath || *dllJvmPath == L'\0')
+    if (dllJvmPath && *dllJvmPath) {
+        /* Explicit JVM path.
+         * Check if provided argument is valid
+         */
+        if (GetFileAttributesW(dllJvmPath) == INVALID_FILE_ATTRIBUTES) {
+            /* DAEMON-247: Invalid RuntimeLib explicitly specified is error.
+             */
+            apxLogWrite(APXLOG_MARK_DEBUG "Invalid RuntimeLib specified '%S'", 
dllJvmPath);
+            return FALSE;
+        }
+    }
+    else {
         dllJvmPath = apxGetJavaSoftRuntimeLib(NULL);
-    if (!dllJvmPath)
-        return FALSE;
+        if (!dllJvmPath)
+            return FALSE;
+    }
     if (GetFileAttributesW(dllJvmPath) == INVALID_FILE_ATTRIBUTES) {
         /* DAEMON-184: RuntimeLib registry key is invalid.
          * Check from Jre JavaHome directly
@@ -267,6 +294,7 @@ static BOOL __apxLoadJvmDll(LPCWSTR szJv
     DYNLOAD_FPTR_LOAD(JNI_GetDefaultJavaVMInitArgs, _st_sys_jvmDllHandle);
     DYNLOAD_FPTR_LOAD(JNI_CreateJavaVM,             _st_sys_jvmDllHandle);
     DYNLOAD_FPTR_LOAD(JNI_GetCreatedJavaVMs,        _st_sys_jvmDllHandle);
+    DYNLOAD_FPTR_LOAD(JVM_DumpAllStacks,            _st_sys_jvmDllHandle);
 
     if (!DYNLOAD_FPTR(JNI_GetDefaultJavaVMInitArgs) ||
         !DYNLOAD_FPTR(JNI_CreateJavaVM) ||
@@ -438,6 +466,13 @@ static jint JNICALL __apxJniVfprintf(FIL
     return rv;
 }
 
+static void JNICALL __apxJniExit(jint exitCode)
+{
+    apxLogWrite(APXLOG_MARK_DEBUG "Exit hook with exit code %d", exitCode);
+    vmExitCode = exitCode;
+    return;
+}
+
 static LPSTR __apxStrIndexA(LPCSTR szStr, int nCh)
 {
     LPSTR pStr;
@@ -624,6 +659,9 @@ apxJavaInitialize(APXHANDLE hJava, LPCST
             ++sOptions;
         if (szClassPath && *szClassPath)
             ++sOptions;
+
+        sOptions++; /* unconditionally set for extraInfo exit */
+
         nOptions = __apxMultiSzToJvmOptions(hJava->hPool, lpOptions,
                                             &lpJvmOptions, sOptions);
         if (szClassPath && *szClassPath) {
@@ -641,6 +679,12 @@ apxJavaInitialize(APXHANDLE hJava, LPCST
             lpJvmOptions[nOptions - sOptions].extraInfo    = __apxJniVfprintf;
             --sOptions;
         }
+
+        /* unconditionally add hook for System.exit() in order to store exit 
code */
+        lpJvmOptions[nOptions - sOptions].optionString = "exit";
+        lpJvmOptions[nOptions - sOptions].extraInfo    = __apxJniExit;
+        --sOptions;
+
         if (dwMs) {
             wsprintfA(iB[0], "-Xms%dm", dwMs);
             lpJvmOptions[nOptions - sOptions].optionString = iB[0];
@@ -897,12 +941,18 @@ static DWORD WINAPI __apxJavaWorkerThrea
     apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread started %s:%s",
                 lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
     lpJava->dwWorkerStatus = 1;
-    SetEvent(lpJava->hWorkerSync);
+    SetEvent(lpJava->hWorkerInit);
+    /* Ensure apxJavaStart worker has read our status */
+    WaitForSingleObject(lpJava->hWorkerSync, INFINITE);
     JNICALL_3(CallStaticVoidMethod,
               lpJava->clWorker.jClazz,
               lpJava->clWorker.jMethod,
               lpJava->clWorker.jArgs);
     if (JVM_EXCEPTION_CHECK(lpJava)) {
+        apxLogWrite(APXLOG_MARK_DEBUG "Exception has been thrown");
+        vmExitCode = 1;
+        (*((lpJava)->lpEnv))->ExceptionDescribe((lpJava)->lpEnv);
+        __apxJvmDetach(lpJava);
         WORKER_EXIT(6);
     }
     else {
@@ -913,7 +963,7 @@ finished:
         lpJava->dwWorkerStatus = 0;
         apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished %s:%s with 
status=%d",
                     lpJava->clWorker.sClazz, lpJava->clWorker.sMethod, rv);
-        SetEvent(lpJava->hWorkerSync);
+        SetEvent(lpJava->hWorkerInit);
     }
     ExitThread(rv);
     /* never gets here but keep the compiler happy */
@@ -928,6 +978,7 @@ apxJavaStart(LPAPXJAVA_THREADARGS pArgs)
     if (!lpJava)
         return FALSE;
     lpJava->dwWorkerStatus = 0;
+    lpJava->hWorkerInit    = CreateEvent(NULL, FALSE, FALSE, NULL);
     lpJava->hWorkerSync    = CreateEvent(NULL, FALSE, FALSE, NULL);
     lpJava->hWorkerThread  = CreateThread(NULL,
                                           lpJava->szStackSize,
@@ -940,9 +991,10 @@ apxJavaStart(LPAPXJAVA_THREADARGS pArgs)
     }
     ResumeThread(lpJava->hWorkerThread);
     /* Wait until the worker thread initializes */
-    WaitForSingleObject(lpJava->hWorkerSync, INFINITE);
+    WaitForSingleObject(lpJava->hWorkerInit, INFINITE);
     if (lpJava->dwWorkerStatus == 0)
         return FALSE;
+    SetEvent(lpJava->hWorkerSync);
     if (lstrcmpA(lpJava->clWorker.sClazz, "java/lang/System")) {
         /* Give some time to initialize the thread
          * Unless we are calling System.exit(0).
@@ -1215,3 +1267,30 @@ apxJavaSetOut(APXHANDLE hJava, BOOL setE
 
 }
 
+DWORD apxGetVmExitCode(void) {
+    return vmExitCode;
+}
+
+void apxSetVmExitCode(DWORD exitCode) {
+    vmExitCode = exitCode;
+    return;
+}
+
+void
+apxJavaDumpAllStacks(APXHANDLE hJava)
+{
+    BOOL bAttached;
+    LPAPXJAVAVM lpJava;
+    JNIEnv *lpEnv = NULL;
+
+    if (DYNLOAD_FPTR(JVM_DumpAllStacks) == NULL ||
+        hJava == NULL ||
+        hJava->dwType != APXHANDLE_TYPE_JVM)
+        return;
+    lpJava = APXHANDLE_DATA(hJava);
+    if (__apxJvmAttachEnv(lpJava, &lpEnv, &bAttached)) {
+        DYNLOAD_FPTR(JVM_DumpAllStacks)(lpEnv, NULL);
+        if (bAttached)
+            (*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm);
+    }
+}

Modified: commons/proper/daemon/trunk/src/native/windows/src/log.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/log.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/log.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/log.c Mon Nov 28 
20:18:04 2016
@@ -41,9 +41,10 @@ typedef struct apx_logfile_st {
 } apx_logfile_st;
 
 /* Per-application master log file */
-static apx_logfile_st *_st_sys_loghandle = NULL;
-
-static apx_logfile_st  _st_sys_errhandle = { NULL, APXLOG_LEVEL_WARN, FALSE};
+static apx_logfile_st   *_st_sys_loghandle = NULL;
+static CRITICAL_SECTION  _st_sys_loglock;
+static CRITICAL_SECTION *_pt_sys_loglock = NULL;
+static apx_logfile_st    _st_sys_errhandle = { NULL, APXLOG_LEVEL_WARN, FALSE};
 
 static void logRotate(apx_logfile_st *lf, LPSYSTEMTIME t)
 {
@@ -88,6 +89,10 @@ static void logRotate(apx_logfile_st *lf
         /* TODO: Log something */
         return;
     }
+    /* Make sure we relock the correct file */
+    APX_LOGLOCK(h);
+    APX_LOGUNLOCK(lf->hFile);
+    /* Close original handle */
     CloseHandle(lf->hFile);
     lf->hFile = h;
 }
@@ -171,6 +176,10 @@ HANDLE apxLogOpen(
     SYSTEMTIME sysTime;
     apx_logfile_st *h;
 
+    if (_pt_sys_loglock == NULL) {
+        InitializeCriticalSection(&_st_sys_loglock);
+        _pt_sys_loglock = &_st_sys_loglock;
+    }
     GetLocalTime(&sysTime);
     if (!szPath) {
         if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
@@ -300,10 +309,14 @@ apxLogWrite(
     if (IS_INVALID_HANDLE(lf)) {
         lf = &_st_sys_errhandle;
         lf->hFile = GetStdHandle(STD_ERROR_HANDLE);
+    }
+    if (lf == &_st_sys_errhandle) {
+        /* Do not rotate if redirected to console */
         dolock = FALSE;
     }
     if (dwLevel < lf->dwLogLevel)
         return 0;
+    APX_LOGENTER();
     if (f && (lf->dwLogLevel == APXLOG_LEVEL_DEBUG || dwLevel == 
APXLOG_LEVEL_ERROR)) {
         f = (szFile + lstrlenA(szFile) - 1);
         while(f != szFile && '\\' != *f && '/' != *f)
@@ -346,6 +359,8 @@ apxLogWrite(
             buffer[--len] = '\0';
         if (!IS_INVALID_HANDLE(lf->hFile)) {
             SYSTEMTIME t;
+            /* Append operation */
+            SetFilePointer(lf->hFile, 0, &wr, FILE_END);
             GetLocalTime(&t);
             if (dolock) {
                 APX_LOGLOCK(lf->hFile);
@@ -363,14 +378,18 @@ apxLogWrite(
                 wsprintfA(sb, "(%10s:%-4d) ", f, dwLine);
                 WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
             }
+
+            /* add thread ID to log output */
+            wsprintfA(sb, "[%5d] ", GetCurrentThreadId());
+            WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
+
             if (len)
                 WriteFile(lf->hFile, buffer, len, &wr, NULL);
 
             /* Terminate the line */
             WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
-#ifdef _DEBUG_FULL
-            FlushFileBuffers(lf->hFile);
-#endif
+            if (dwLevel)
+                FlushFileBuffers(lf->hFile);
             if (dolock) {
                 APX_LOGUNLOCK(lf->hFile);
             }
@@ -383,6 +402,7 @@ apxLogWrite(
         }
 #endif
     }
+    APX_LOGLEAVE();
     /* Restore the last Error code */
     SetLastError(err);
     if (szFormat && err != 0 && dwLevel == APXLOG_LEVEL_ERROR) {

Modified: commons/proper/daemon/trunk/src/native/windows/src/rprocess.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/rprocess.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/rprocess.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/rprocess.c Mon Nov 28 
20:18:04 2016
@@ -116,6 +116,12 @@ static DWORD WINAPI __apxProcWorkerThrea
     if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
                             INFINITE) == WAIT_OBJECT_0) {
         lpProc->dwChildStatus |= CHILD_MAINTREAD_FINISHED;
+
+        /* store worker's exit code as VM exit code for later use */
+        GetExitCodeProcess(lpProc->stProcInfo.hProcess, &dwExitCode);
+        apxLogWrite(APXLOG_MARK_DEBUG "Child process exit code %d", 
dwExitCode);
+        apxSetVmExitCode(dwExitCode);
+
 #if 0
         if (hProcess->fnCallback)
             (*hProcess->fnCallback)(hProcess, WM_QUIT, (WPARAM)dwExitCode, 0);

Modified: commons/proper/daemon/trunk/src/native/windows/src/service.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/service.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/service.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/service.c Mon Nov 28 
20:18:04 2016
@@ -147,7 +147,7 @@ apxServiceOpen(APXHANDLE hService, LPCWS
         lpService->stServiceEntry.szObjectName[0] = L'\0';
     }
     if (!QueryServiceConfigW(lpService->hService, NULL, 0, &dwNeeded)) {
-        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
                // This is expected. The call is expected to fail with the 
required
                // buffer size set in dwNeeded.
                // Clear the last error to prevent it being logged if a genuine

Modified: commons/proper/daemon/trunk/src/native/windows/src/utils.c
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/utils.c?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/utils.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/utils.c Mon Nov 28 
20:18:04 2016
@@ -318,7 +318,7 @@ apxMultiSzToArrayW(APXHANDLE hPool, LPCW
 
     *lppArray = (LPWSTR *)buff;
     p = (LPWSTR)(buff + (n + 2) * sizeof(LPWSTR));
-    AplCopyMemory(p, lpString, (l + 1) * sizeof(WCHAR) + sizeof(WCHAR));
+    AplCopyMemory(p, lpString, (l + 1) * sizeof(WCHAR));
     for (i = 0; i < n; i++) {
         (*lppArray)[i] = p;
         while (*p)
@@ -347,7 +347,7 @@ apxMultiSzToArrayA(APXHANDLE hPool, LPCS
 
     *lppArray = (LPSTR *)buff;
     p = (LPSTR)(buff + (n + 2) * sizeof(LPSTR));
-    AplCopyMemory(p, lpString, (l + 1) * sizeof(CHAR) + sizeof(CHAR));
+    AplCopyMemory(p, lpString, (l + 1) * sizeof(CHAR));
     for (i = 0; i < n; i++) {
         (*lppArray)[i] = p;
         while (*p)

Modified: commons/proper/daemon/trunk/src/samples/AloneDaemon.sh
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/samples/AloneDaemon.sh?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/samples/AloneDaemon.sh (original)
+++ commons/proper/daemon/trunk/src/samples/AloneDaemon.sh Mon Nov 28 20:18:04 
2016
@@ -1,5 +1,5 @@
 #!/bin/sh
-# 
+#
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.

Modified: commons/proper/daemon/trunk/src/samples/Native.sh
URL: 
http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/samples/Native.sh?rev=1771804&r1=1771803&r2=1771804&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/samples/Native.sh (original)
+++ commons/proper/daemon/trunk/src/samples/Native.sh Mon Nov 28 20:18:04 2016
@@ -1,18 +1,20 @@
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements.  See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License.  You may obtain a copy of the License at
-##
-##     http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-##
+#!/bin/sh
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 # for linux ;-) and Mac OS X
 case `uname -s` in
   Darwin)


Reply via email to