harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r964805 - /harmony/enhanced/java/trunk/drlvm/vm/vmcore/src/kernel_classes/native/Runtime_lnx.cpp
Date Fri, 16 Jul 2010 14:23:26 GMT
Author: hindessm
Date: Fri Jul 16 14:23:26 2010
New Revision: 964805

URL: http://svn.apache.org/viewvc?rev=964805&view=rev
Log:
Apply patch from "[#HARMONY-6587] [drlvm] Maybe we should give one more try
on the file given to a process".

Modified:
    harmony/enhanced/java/trunk/drlvm/vm/vmcore/src/kernel_classes/native/Runtime_lnx.cpp

Modified: harmony/enhanced/java/trunk/drlvm/vm/vmcore/src/kernel_classes/native/Runtime_lnx.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/drlvm/vm/vmcore/src/kernel_classes/native/Runtime_lnx.cpp?rev=964805&r1=964804&r2=964805&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/drlvm/vm/vmcore/src/kernel_classes/native/Runtime_lnx.cpp
(original)
+++ harmony/enhanced/java/trunk/drlvm/vm/vmcore/src/kernel_classes/native/Runtime_lnx.cpp
Fri Jul 16 14:23:26 2010
@@ -86,6 +86,7 @@ void JNICALL Java_java_lang_Runtime_0002
      int lenargv = 0;
      lenargv = env->GetArrayLength(cmdarray);
      char *argv[lenargv+1];
+     char *newArgv[lenargv+2];
      for ( i = 0; i < lenargv; i++ ) {
          jo = env->GetObjectArrayElement((jobjectArray)((jobject)cmdarray), (jsize) i);
          strChain = env->GetStringUTFChars((jstring) jo, 0);
@@ -182,11 +183,37 @@ void JNICALL Java_java_lang_Runtime_0002
              }
              free(cmdDir);
          }
-         
+
+         char *newArgv[lenargv+2];
          if (lenEnvp == 0) {
              execvp(argv[0], argv);
+             if (errno == ENOEXEC) {
+               // give another try
+               for (i=0; i<lenargv; i++) {
+                 strCmd = (char *)malloc(1+strlen(argv[i])); // + NUL symbol
+                 *strCmd = '\0';
+                 strcat(strCmd, argv[i]);
+                 newArgv[i+1] = strCmd;
+               }
+               newArgv[0] = strdup("/bin/sh");
+               newArgv[lenargv+1] = (char *)0;
+               execvp(newArgv[0], newArgv);
+             }
          } else {
              execve(argv[0], argv, strEnvpBeginAA);
+             if (errno == ENOEXEC) {
+               // give another try
+               for (i=0; i<lenargv; i++) {
+                 strCmd = (char *)malloc(1+strlen(argv[i])); // + NUL symbol
+                 *strCmd = '\0';
+                 strcat(strCmd, argv[i]);
+                 newArgv[i+1] = strCmd;
+               }
+               newArgv[0] = strdup("/bin/sh");
+               newArgv[lenargv+1] = (char *)0;
+               execve(newArgv[0], newArgv, strEnvpBeginAA);
+             }
+
              if(strchr(argv[0], '/') == NULL) {
                  char* curDir = NULL;
                  char* cmdPath = NULL;
@@ -212,6 +239,11 @@ void JNICALL Java_java_lang_Runtime_0002
          }
          write(fildesInfo[1], &errno, sizeof(int));
          INFO("Process initiation failed: " << strerror(errno));
+         for (i=0; i<lenargv+1; i++) {
+           if (newArgv[i] != NULL) {
+             free(newArgv[i]);
+           }
+         }
          // kill self
          kill(getpid(), 9);
      }
@@ -221,8 +253,18 @@ void JNICALL Java_java_lang_Runtime_0002
      close(fildesI[0]);
      close(fildesE[1]);
      close(fildesInfo[1]);
-     free(cmdDir);
-     free(strCmd);
+
+     for (i=0; i<lenargv; i++) {
+       if (argv[i] != NULL) {
+         free(argv[i]);
+       }
+     }
+
+     for (i=0; i<lenEnvp; i++) {
+       if (strEnvpBeginAA[i] != NULL) {
+         free(strEnvpBeginAA[i]);
+       }
+     }
 
      // get execution status from child
      int errno_child;



Mime
View raw message