Skip to content

Commit

Permalink
[refactor] we could just check ENOMEM int directly
Browse files Browse the repository at this point in the history
... a follow-up for jrubyGH-5352
  • Loading branch information
kares committed Oct 12, 2018
1 parent 117d751 commit c0278dc
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions core/src/main/java/org/jruby/RubyKernel.java
Expand Up @@ -43,6 +43,16 @@

package org.jruby;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import jnr.constants.platform.Errno;
import jnr.posix.POSIX;

import org.jruby.anno.FrameField;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
Expand Down Expand Up @@ -78,13 +88,6 @@
import org.jruby.util.io.OpenFile;
import org.jruby.util.io.PopenExecutor;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.jruby.RubyBasicObject.UNDEF;
import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.RubyInteger.singleCharByteList;
Expand Down Expand Up @@ -1804,25 +1807,27 @@ private static IRubyObject execCommon(ThreadContext context, IRubyObject env, IR
// attempt to shut down the JMX server
jmxStopped = runtime.getBeanManager().tryShutdownAgent();

runtime.getPosix().chdir(System.getProperty("user.dir"));
final POSIX posix = runtime.getPosix();

posix.chdir(System.getProperty("user.dir"));

if (Platform.IS_WINDOWS) {
// Windows exec logic is much more elaborate; exec() in jnr-posix attempts to duplicate it
runtime.getPosix().exec(progStr, argv);
posix.exec(progStr, argv);
} else {
// TODO: other logic surrounding this call? In jnr-posix?
@SuppressWarnings("unchecked")
final Map<String, String> ENV = (Map<String, String>) runtime.getENV();
ArrayList<String> envStrings = new ArrayList<String>(ENV.size() + 1);
ArrayList<String> envStrings = new ArrayList<>(ENV.size() + 1);
for ( Map.Entry<String, String> envEntry : ENV.entrySet() ) {
envStrings.add( envEntry.getKey() + '=' + envEntry.getValue() );
}
envStrings.add(null);

int status = runtime.getPosix().execve(progStr, argv, envStrings.toArray(new String[envStrings.size()]));
if (Platform.IS_WSL && status == -1) {
if (runtime.getErrno(runtime.getPosix().errno()) == runtime.getErrno().getClass("ENOMEM")) {
runtime.getPosix().exec(progStr, argv);
int status = posix.execve(progStr, argv, envStrings.toArray(new String[envStrings.size()]));
if (Platform.IS_WSL && status == -1) { // work-around a bug in Windows Subsystem for Linux
if (posix.errno() == Errno.ENOMEM.intValue()) {
posix.exec(progStr, argv);
}
}
}
Expand Down

0 comments on commit c0278dc

Please sign in to comment.