mturk       2005/06/30 00:10:29

  Modified:    jni/java/org/apache/tomcat/jni Stdlib.java
               jni/native/include tcn.h
               jni/native/src jnilib.c proc.c stdlib.c
  Log:
  Add getpid and getppid functions. The getppid function on WIndows is
  simulated by passing the environment value to the child process.
  
  Revision  Changes    Path
  1.3       +13 -1     
jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Stdlib.java
  
  Index: Stdlib.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Stdlib.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Stdlib.java       14 Jan 2005 14:42:37 -0000      1.2
  +++ Stdlib.java       30 Jun 2005 07:10:29 -0000      1.3
  @@ -74,4 +74,16 @@
        */
       public static native void free(long mem);
   
  +    /**
  +     * Get current process pid.
  +     * @return current pid or < 1 in case of error.
  +     */
  +    public static native int getpid();
  +
  +    /**
  +     * Get current process parent pid.
  +     * @return parent pid or < 1 in case of error.
  +     */
  +    public static native int getppid();
  +
   }
  
  
  
  1.27      +2 -1      jakarta-tomcat-connectors/jni/native/include/tcn.h
  
  Index: tcn.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/include/tcn.h,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- tcn.h     23 Jun 2005 08:58:05 -0000      1.26
  +++ tcn.h     30 Jun 2005 07:10:29 -0000      1.27
  @@ -83,6 +83,7 @@
   #define TCN_FINFO_CLASS TCN_CLASS_PATH "FileInfo"
   #define TCN_AINFO_CLASS TCN_CLASS_PATH "Sockaddr"
   #define TCN_ERROR_CLASS TCN_CLASS_PATH "Error"
  +#define TCN_PARENT_IDE  "TCN_PARENT_ID"
   
   #define UNREFERENCED(P)      (P) = (P)
   #define UNREFERENCED_STDARGS e = e; o = o
  
  
  
  1.13      +12 -2     jakarta-tomcat-connectors/jni/native/src/jnilib.c
  
  Index: jnilib.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/jnilib.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- jnilib.c  23 Jun 2005 08:58:05 -0000      1.12
  +++ jnilib.c  30 Jun 2005 07:10:29 -0000      1.13
  @@ -42,6 +42,8 @@
   static jmethodID jString_init;
   static jmethodID jString_getBytes;
   
  +int tcn_parent_pid = 0;
  +
   /* Called by the JVM when APR_JAVA is loaded */
   JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
   {
  @@ -67,7 +69,15 @@
           return JNI_ERR;
       if(tcn_load_ainfo_class(env, jAinfo_class) != APR_SUCCESS)
           return JNI_ERR;
  -
  +#ifdef WIN32
  +    {
  +        char *ppid = getenv(TCN_PARENT_IDE);
  +        if (ppid)
  +            tcn_parent_pid = atoi(ppid);
  +    }
  +#else
  +    tcn_parent_pid = getppid();
  +#endif
       apr_initialize();
   
       return  JNI_VERSION_1_4;
  
  
  
  1.6       +19 -4     jakarta-tomcat-connectors/jni/native/src/proc.c
  
  Index: proc.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/proc.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- proc.c    17 Jun 2005 09:41:30 -0000      1.5
  +++ proc.c    30 Jun 2005 07:10:29 -0000      1.6
  @@ -209,7 +209,7 @@
           as = (*e)->GetArrayLength(e, args);
       if (env)
           es = (*e)->GetArrayLength(e, args);
  -    if (as > MAX_ARGS_SIZE || es > MAX_ENV_SIZE) {
  +    if (as > (MAX_ARGS_SIZE - 1) || es > (MAX_ENV_SIZE - 2)) {
           TCN_FREE_CSTRING(progname);
           return APR_EINVAL;
       }
  @@ -219,19 +219,34 @@
               s_args[i] = tcn_get_string(e, str);
               (*e)->DeleteLocalRef(e, str);
           }
  +        s_args[i] = NULL;
           pargs = (const char * const *)&s_args[0];
       }
       if (es) {
           for (i = 0; i < es; i++) {
               jstring str = (*e)->GetObjectArrayElement(e, env, i);
  -            s_env[i] = tcn_get_string(e, str);
  +            s_env[i+1] = tcn_get_string(e, str);
               (*e)->DeleteLocalRef(e, str);
           }
  +#ifdef WIN32
  +        s_env[i++] = apr_psprintf(p, TCN_PARENT_IDE "=%d", getpid());
  +#endif
  +        s_env[i] = NULL;
           penv = (const char * const *)&s_env[0];
       }
  -
  +#ifdef WIN32
  +    else {
  +        char pps[32];
  +        itoa(getpid(), pps, 10);
  +        SetEnvironmentVariable(TCN_PARENT_IDE, pps);
  +    }
  +#endif
       rv = apr_proc_create(np, J2S(progname), pargs,
                            penv, a, p);
  +#ifdef WIN32
  +    if (!es)
  +        SetEnvironmentVariable(TCN_PARENT_IDE, NULL);
  +#endif
   
       /* Free local resources */
       TCN_FREE_CSTRING(progname);
  
  
  
  1.4       +15 -1     jakarta-tomcat-connectors/jni/native/src/stdlib.c
  
  Index: stdlib.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/stdlib.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- stdlib.c  17 Jun 2005 09:41:30 -0000      1.3
  +++ stdlib.c  30 Jun 2005 07:10:29 -0000      1.4
  @@ -21,6 +21,8 @@
    
   #include "tcn.h"
   
  +extern int tcn_parent_pid;
  +
   TCN_IMPLEMENT_CALL(jlong, Stdlib, malloc)(TCN_STDARGS, jint size)
   {
       UNREFERENCED_STDARGS;
  @@ -103,3 +105,15 @@
           return JNI_FALSE;
   }
   
  +TCN_IMPLEMENT_CALL(jint, Stdlib, getpid)(TCN_STDARGS)
  +{
  +    UNREFERENCED_STDARGS;
  +    return (jint)getpid();
  +}
  +
  +TCN_IMPLEMENT_CALL(jint, Stdlib, getppid)(TCN_STDARGS)
  +{
  +    UNREFERENCED_STDARGS;
  +    return (jint)tcn_parent_pid;
  +}
  +
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to