

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
4 messages in net.java.dev.jna.users[jna-users] Attempt at DNotify| From | Sent On | Attachments |
|---|---|---|
| Erik Earle | Jan 30, 2009 1:25 pm | .log, .java |
| Timothy Wall | Jan 31, 2009 5:50 pm | |
| Timothy Wall | Jan 31, 2009 5:53 pm | |
| Daniel Kaufmann | Feb 2, 2009 6:00 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | [jna-users] Attempt at DNotify | Actions... |
|---|---|---|
| From: | Erik Earle (erik...@yahoo.com) | |
| Date: | Jan 30, 2009 1:25:16 pm | |
| List: | net.java.dev.jna.users | |
| Attachments: | ||
I tried to duplicate the c example for dnotify.c here: http://souptonuts.sourceforge.net/code/dnotify.c.html
The attached is what I came up with. It works... somewhat.
- I get segmentation faults if I do anything other than touch or rm a file,
(opening a file with vi or 'echo foo > foo.txt' causes the fault)
- I don't get modified events.
- In spite of setting the flag for the calling the 3 arg callback, it still only
calls the single arg callback.
I'm running:
- Ubuntu Gutsy, Linux xxxxx 2.6.24-23-generic #1 SMP Thu Nov 27 18:44:42 UTC
2008 i686 GNU/Linux
- java version "1.6.0_07"
- jna-3.0.7
I've tried to get a memory dump using the instructions here:
https://jna.dev.java.net/#struct_debug (the "-Djna.dump_memory=true" prop) but
I the output just show this:
sigaction:
DNotify$SigAction(allocated@0x81155f0 (144 bytes)) {
DNotify$__sighandler_t
sa_sighandler@0=com.sun.jna.examples.linux.DNotify$1@1cd8669
DNotify$__sigaction_t
sa_sigaction@4=com.sun.jna.examples.linux.DNotify$2@337838
DNotify$__sigset_t sa_mask@8=DNotify$__sigset_t(allocated@0x8158810 (128
bytes)) {
int __val[32]@0=[I@119cca4
}
int sa_flags@88=4
DNotify$__sigrestorer_t
sa_restorer@8c=com.sun.jna.examples.linux.DNotify$3@ca2dce
}
memory dump
[00000000]
[00000000]
[00000000]
.... (just keeps repeating the zeros)
sometimes I get a core dump, that's also attached.
Any thoughts?
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package com.sun.jna.examples.linux;
import com.sun.jna.Callback; import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.Structure; import java.io.File;
/** * * @author eearle */ public class DNotify {
public static final int SA_SIGINFO = 4;
public static final int O_RDONLY = 0;
public static final int F_SETSIG = 10; /* Set number of signal to be sent.
*/
public static final int F_NOTIFY = 1026; /* Request notfications on a
directory. */
public static final int DN_ACCESS = 0x00000001; /* File accessed. */
public static final int DN_MODIFY = 0x00000002; /* File modified. */
public static final int DN_CREATE = 0x00000004; /* File created. */
public static final int DN_DELETE = 0x00000008; /* File removed. */
public static final int DN_RENAME = 0x00000010; /* File renamed. */
public static final int DN_ATTRIB = 0x00000020; /* File changed attibutes.
*/
public static final int DN_MULTISHOT = 0x80000000; /* Don't remove notifier.
*/
public static class __sigset_t extends Structure { private static final int SIGSET_NWORDS = 1024 / (8 * 4); // 32 bit public int[] __val = new int[SIGSET_NWORDS]; }
public interface __sighandler_t extends Callback { // void handler(int sig, siginfo_t *si, void *data) public void callback(int sig); }
public interface __sigaction_t extends Callback { // void handler(int sig, siginfo_t *si, void *data) // public void callback(int sig, Pointer si, Pointer data); public void callback(int sig, siginfo_t si, Pointer data); }
public interface __sigrestorer_t extends Callback { // void handler(int sig, siginfo_t *si, void *data) public void callback(); }
public static class SigAction extends Structure { public __sighandler_t sa_sighandler; public __sigaction_t sa_sigaction; public __sigset_t sa_mask; public int sa_flags; public __sigrestorer_t sa_restorer; }
public static class siginfo_t extends Structure {
public int si_signo; // Signal number.
public int si_errno; // If non-zero, an errno value associated with
this signal, as defined in <errno.h>.
public int si_code; // Signal code.
public int si_fd;
}
public interface CLibrary extends Library { public void sigemptyset(__sigset_t set);
// SigAction(SIGRTMIN + 1, &act, NULL); public int sigaction(int sig, SigAction action, SigAction oldAction);
//open(".", O_RDONLY); public int open(String path, int mode);
// fcntl(fd, F_SETSIG, SIGRTMIN + 1); public int fcntl(int __fd, int __cmd, int sig);
// pause(); public int pause ();
public int __libc_current_sigrtmin(); }
static volatile int event_fd; static volatile int event_sig;
public static void main(String[] args) {
System.out.println("RUNNING IN: "+new File(".").getAbsolutePath());
Native.setProtected(true); if(!Native.isProtected()) { System.out.println("\nVM CRASH PROTECTION IS NOT SUPPORTED\n"); } else { System.out.println("\nVM CRASH PROTECTION ENABLED\n"); }
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
int SIGRTMIN = INSTANCE.__libc_current_sigrtmin();
System.out.println("SIGRTMIN: "+SIGRTMIN);
SigAction sigaction = new SigAction();
sigaction.sa_sighandler = new __sighandler_t() { public void callback(int sig) { System.out.println("SIG HANDLER CALLBACK"); event_sig = sig; } };
sigaction.sa_sigaction = new __sigaction_t() { // public void callback(int sig, Pointer si, Pointer data) { public void callback(int sig, siginfo_t si, Pointer data) { System.out.println("SIG ACTION CALLBACK"); // System.out.println("Got event on fd="+si.si_fd+" sig="+sig); event_fd = si.si_fd; event_sig = sig; } };
sigaction.sa_restorer = new __sigrestorer_t() {
public void callback() { System.out.println("SIG RESTORER CALLBACK"); } };
INSTANCE.sigemptyset(sigaction.sa_mask); sigaction.sa_flags = SA_SIGINFO;
System.out.println("sigaction:\n"+sigaction.toString());
INSTANCE.sigaction(SIGRTMIN + 1, sigaction, null); int fd = INSTANCE.open(".", O_RDONLY);
INSTANCE.fcntl(fd, F_SETSIG, SIGRTMIN + 1);
//INSTANCE.fcntl(fd, F_NOTIFY,
DN_ACCESS|DN_MODIFY|DN_CREATE|DN_RENAME|DN_DELETE|DN_ATTRIB|DN_MULTISHOT);
INSTANCE.fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_RENAME |
DN_DELETE | DN_MULTISHOT);
/* we will now be notified if any of the files
in "." is modified or new files are created */
while (true) {
INSTANCE.pause();
System.out.println("Got event on fd="+event_fd+" sig="+event_sig);
}
}
}








.log, .java