8 messages in net.java.dev.jna.usersRe: [jna-users] Is there a way to han...
FromSent OnAttachments
Dennis PortelloMay 14, 2007 7:27 am 
Wayne MeissnerMay 14, 2007 5:59 pm 
Dennis PortelloMay 15, 2007 10:48 pm 
Wayne MeissnerMay 16, 2007 3:54 am 
Timothy WallMay 16, 2007 5:51 am 
Timothy WallAug 27, 2007 9:53 am 
Dennis PortelloAug 27, 2007 9:59 am 
Timothy WallAug 27, 2007 11:27 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Is there a way to handle a union construct?Actions...
From:Wayne Meissner (wmei@gmail.com)
Date:May 14, 2007 5:59:35 pm
List:net.java.dev.jna.users

Dennis Portello wrote:

Hi,

I've been experimenting with JNA over the last few days to gain access to POSIX functions on Linux/Unix.

So far I've had success with calling setuid when running Apache Tomcat so I can start as root and move to a non-privileged account during runtime.

For my next trick, I'd like to write a signal handler so I can initiate a proper shutdown when a SIGINT or SIGHUP is caught.

My dilemma is this, I was in the process of implementing the sigalert struct in java when I came across a union. I've looked around the jna code, examples on the site, and whatever emails I could find and found nothing regarding this issue.

I couldn't find the sigalert structure anywhere. Did you mean struct sigaction, with its union of function pointers?

Assuming sigaction, there currently isn't any way to set function pointers in a structure anyway - so using the old signal(3) call might be a better bet to hook signal handlers for now.

Could someone provide insight as to how I might handle a c union with JNA, or is this something that's not currently possible?

There is no easy way to do it currently. You can always point multiple structures at the same memory region. e.g. class Foo extends Structure { public int i1; public int i2;

public Foo(Pointer p) { useMemory(p); } } class Bar extends Structure { public long l; public Bar(Pointer p) { useMemory(p); } } Pointer p = new Memory(...) Foo f = new Foo(p); foo.i1 = 0xdeadbeef; foo.i2 = 0xcafebabe; foo.write(); Bar b = new Bar(p); b.read(); System.out.println("l=" + b.l);