Last active
August 29, 2015 13:55
-
-
Save jamshid/8776435 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* If you get a strange JVM crash on CentOS 6 in code related to JNA and PAM, | |
* try uninstalling this RedHat package related to fingerprint scanners: | |
* | |
* sudo yum remove fprintd-pam | |
* | |
* Run this program with 100-500 threads -- the jvm usually crashes with | |
* a stack like below (from hs_error.log ). Probably related to issues like: | |
* https://bugzilla.redhat.com/show_bug.cgi?id=1010844. | |
* Probably also affected by machine resource limits. | |
* | |
* Download libpam4j and JNA jars (also reproducible with jna 3.5.2): | |
* http://mvnrepository.com/artifact/org.kohsuke/libpam4j | |
* https://github.com/twall/jna | |
* BUILD: javac -classpath ./jna-4.0.0.jar:./libpam4j-1.7.jar:. PamTest.java | |
* RUN: java -classpath ./jna-4.0.0.jar:./libpam4j-1.7.jar:. PamTest 100 | |
*/ | |
// Stack: [0x00007f1136dee000,0x00007f1136eef000], sp=0x00007f1136eebe40, free space=1015k | |
// Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) | |
// C [libdbus-1.so.3+0x27eb4] chmod+0x27eb4 | |
// | |
// Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) | |
// j com.sun.jna.Native.invokeInt(JI[Ljava/lang/Object;)I+0 | |
// j com.sun.jna.Function.invoke([Ljava/lang/Object;Ljava/lang/Class;Z)Ljava/lang/Object;+225 | |
// j com.sun.jna.Function.invoke(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;+262 | |
// j com.sun.jna.Library$Handler.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;+316 | |
// j com.sun.proxy.$Proxy0.pam_authenticate(Lorg/jvnet/libpam/impl/PAMLibrary$pam_handle_t;I)I+23 | |
// j org.jvnet.libpam.PAM.authenticate(Ljava/lang/String;Ljava/lang/String;)Lorg/jvnet/libpam/UnixUser;+34 | |
import java.util.concurrent.*; | |
import org.jvnet.libpam.PAM; | |
import org.jvnet.libpam.UnixUser; | |
public class PamTest { | |
private final static class PamTask implements Callable<String> { | |
public String call(){ | |
try { | |
PAM pam = new PAM("login"); | |
UnixUser u = pam.authenticate("gw-john", "password"); | |
System.out.println("User " + u.getUserName() + " " + u.getUID() + " " + u.getGID() + " " + u.getDir() + " " + u.getGecos() + " " + u.getShell() + " in " + u.getGroups()); | |
return u.getUserName(); | |
} catch (Exception e) { | |
System.out.println("Exception: " + e); | |
System.exit(1); | |
return null; | |
} | |
} | |
} | |
public static void main(String[] argv) { | |
try { | |
int NUM_THREADS = 50; | |
if (argv.length > 0) { | |
NUM_THREADS = Integer.parseInt(argv[0]); | |
} | |
ExecutorService poolWorkers = Executors.newFixedThreadPool(NUM_THREADS); | |
CompletionService<String> pool = new ExecutorCompletionService(poolWorkers); | |
for(int i = 0; i < NUM_THREADS; i++){ | |
pool.submit(new PamTask()); | |
} | |
for(int i = 0; i < NUM_THREADS; ++i){ | |
String result = pool.take().get(); | |
System.out.println(i + ". user: " + result); | |
} | |
poolWorkers.shutdown(); | |
} catch (Exception e) { | |
System.out.println("Exception: " + e); | |
e.printStackTrace(); | |
System.exit(1); | |
} | |
System.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment