Skip to content

Commit

Permalink
[JENKINS-40470] Jobs didn't finish on Solaris 11 Intel node (#2701)
Browse files Browse the repository at this point in the history
* [JENKINS-40470] Jobs didn't finish on Solaris 11 Intel node

* make length limit a system property

(cherry picked from commit 4df0c56)
  • Loading branch information
csiden authored and olivergondza committed Jan 11, 2017
1 parent 7831263 commit 4ade65d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions core/src/main/java/hudson/util/ProcessTree.java
Expand Up @@ -787,6 +787,14 @@ private class SolarisProcess extends UnixProcess {
private static final byte PR_MODEL_ILP32 = 1;
private static final byte PR_MODEL_LP64 = 2;

/*
* An arbitrary upper-limit on how many characters readLine() will
* try reading before giving up. This avoids having readLine() loop
* over the entire process address space if this class has bugs.
*/
private final int LINE_LENGTH_LIMIT =
SystemProperties.getInteger(Solaris.class.getName()+".lineLimit", 10000);

/*
* True if target process is 64-bit (Java process may be different).
*/
Expand Down Expand Up @@ -900,7 +908,7 @@ public synchronized List<String> getArguments() {
for( int n=0; n<argc; n++ ) {
// read a pointer to one entry
LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(argp+n*psize));
long addr = b64 ? m.getLong(0) : m.getInt(0);
long addr = b64 ? m.getLong(0) : to64(m.getInt(0));

arguments.add(readLine(fd, addr, "argv["+ n +"]"));
}
Expand Down Expand Up @@ -935,7 +943,7 @@ public synchronized EnvVars getEnvironmentVariables() {
for( int n=0; ; n++ ) {
// read a pointer to one entry
LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(envp+n*psize));
long addr = b64 ? m.getLong(0) : m.getInt(0);
long addr = b64 ? m.getLong(0) : to64(m.getInt(0));
if (addr == 0) // completed the walk
break;

Expand All @@ -959,7 +967,13 @@ private String readLine(int fd, long addr, String prefix) throws IOException {
Memory m = new Memory(1);
byte ch = 1;
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int i = 0;
while(true) {
if (i++ > LINE_LENGTH_LIMIT) {
LOGGER.finest("could not find end of line, giving up");
throw new IOException("could not find end of line, giving up");
}

LIBC.pread(fd, m, new NativeLong(1), new NativeLong(addr));
ch = m.getByte(0);
if (ch == 0)
Expand Down

0 comments on commit 4ade65d

Please sign in to comment.