>>>>> "Peter" == Peter Pilgrim <[EMAIL PROTECTED]> writes:
Peter> `JavaUnix' is a portable extension API
Please note that some of these functions are not that portable -- not
even between JVMs on Linux.
E.g.
Peter> (*) Access to UNIX account identification:
Peter> `getuid()' / `setuid()'
The attached test program gives the following output with 1.3 green
threads:
% java -green UIDTest 1000
Thread[main,5,main] 0
Thread[second,5,main] 0
Setting UID to 1000
Thread[main,5,main] 1000
Thread[second,5,main] 1000
with the classic native threads VM or HotSpot it deadlocks:
% java -client UIDTest 1000
Thread[main,5,main] 0
Thread[second,5,main] 0
Setting UID to 1000
Thread[main,5,main] 1000
# 'second' doesn't wake up
If the test wouldn't hang the last line would be
Thread[second,5,main] 0
because UIDs are per-thread with LinuxThreads.
Juergen
PS: Some stuff I've noticed
* Building only works if "." is in PATH
* jar packaging doesn't work
* "extern pid_t getsid(pid_t pid);" should be "extern "C" ..."
(if you define _GNU_SOURCE you don't need this at all)
import javaunix.*;
public class UIDTest
{
static Object lock = new Object();
static boolean started = false;
static boolean goon = false;
public static void main(String[] args)
throws Throwable
{
System.out.println(Thread.currentThread() +
" " +
UnixSystem.getUid());
Thread t = new Thread(new Runnable() {
public void run()
{
System.out.println(Thread.currentThread() +
" " +
UnixSystem.getUid());
synchronized (lock) {
started = true;
lock.notify();
while (!goon) {
try {
lock.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
System.out.println(Thread.currentThread() +
" " +
UnixSystem.getUid());
}
}, "second");
t.start();
synchronized (lock) {
while (!started) {
lock.wait();
}
int uid = Integer.parseInt(args[0]);
System.out.println("Setting UID to " + uid);
UnixSystem.setUid(uid);
System.out.println(Thread.currentThread() +
" " +
UnixSystem.getUid());
goon = true;
lock.notify();
}
t.join();
}
}
--
Juergen Kreileder, Blackdown Java-Linux Team
http://www.blackdown.org/java-linux.html
JVM'01: http://www.usenix.org/events/jvm01/