Vincent Torri wrote:
Hey,
I would like to know how I can notify the file system on OpenSolaris.
The low level API on linux is Inotify (it's a kernel module), and on
Windows, it is ReadDirectoryChangeW||. Which one is it with OpenSolaris ?
You need to use the port event system.
See port_create(3C), port_associate(3C)
Below is a small example:
#include <stdio.h>
#include <port.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <poll.h>
#include <unistd.h>
#include <strings.h>
#include <errno.h>
int
main(int argc, char **argv)
{
int myport = port_create();
timespec_t timeout;
file_obj_t mysf = { 0 };
struct stat sbuf;
int myfd;
port_event_t pe;
int ret;
myfd = open("/tmp/test", O_RDONLY);
fstat(myfd, &sbuf);
for (;;) {
mysf.fo_name = "/tmp/test";
port_associate(myport, PORT_SOURCE_FILE, (uintptr_t)&mysf,
FILE_MODIFIED, NULL);
printf("Waiting for events...");
errno = 0;
ret = port_get(myport, &pe, NULL);
if (ret != 0) {
switch (errno) {
case EINTR:
continue;
case ETIME:
printf("Timer expired\n");
break;
default:
perror("port_get");
return (1);
}
}
printf("woke \n");
}
}
Compile that and then do things like:
touch /tmp/test/a
touch /tmp/test/b
--
Darren J Moffat
_______________________________________________
opensolaris-code mailing list
opensolaris-code@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code