Bugzilla – Attachment 56009 Details for
Bug 131322
inotify support broken
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
IDP Log In
|
Forgot Password
better test application
test_inotify.c (text/plain), 2.90 KB, created by
Dirk Mueller
on 2005-10-31 14:49:24 UTC
(
hide
)
Description:
better test application
Filename:
MIME Type:
Creator:
Dirk Mueller
Created:
2005-10-31 14:49:24 UTC
Size:
2.90 KB
patch
obsolete
>#include <unistd.h> >#include <fcntl.h> >#include <sys/syscall.h> >#include <linux/types.h> >#include <linux/inotify.h> >#include <assert.h> >#include <fcntl.h> >#include <sys/ioctl.h> >#include <stdio.h> > >// Linux kernel headers are the greatest (!) > >static inline int inotify_init (void) >{ > return syscall (__NR_inotify_init); >} > >static inline int inotify_add_watch (int fd, const char *name, __u32 mask) >{ > return syscall (__NR_inotify_add_watch, fd, name, mask); >} > >static inline int inotify_rm_watch (int fd, __u32 wd) >{ > return syscall (__NR_inotify_rm_watch, fd, wd); >} > >struct foo { > const char* path; > int wd; >}; > >static struct foo watches[] = { > { "/suse/stbinner", 2 }, > // { "/suse/stbinner/kate.crash", 3 }, > // { "/suse/stbinner/kate.crash.2", -1 }, > // { "/usr/src/work/kdelibs3/kdemm.diff", 4 }, >// { "/etc/samba/smb.conf", 5 }, >// { "/etc/security/fileshare.conf", 6 }, > { "/etc/exports", 7 }, >// { "/etc", 8 }, >// { "/etc/samba", 9 }, >// { "/etc/security", 10 }, > //{ "/usr/src/work/kdelibs3", 11 } >}; > >int main() >{ > int m_inotify_fd = inotify_init(); > printf("m_inotify_fd: %d\n", m_inotify_fd); > int i; > > fd_set rfds; > struct timeval tv; > int retval; > > int wd = inotify_add_watch ( m_inotify_fd, "/", 0x800 ); > assert(wd > 0); > int r = inotify_rm_watch( m_inotify_fd, wd ); > assert(r == 0); > > for(i = 0; i < sizeof(watches)/sizeof(struct foo); ++i) { > int r = inotify_add_watch(m_inotify_fd, watches[i].path, IN_MODIFY|IN_ATTRIB|IN_MOVED_FROM|IN_MOVED_TO|IN_CREATE|IN_DELETE|IN_DELETE_SELF|0x800); > assert(r > 0); > watches[i].wd = r; > } > > printf("ok, now going into the loop\n"); > > > while(1) { > FD_ZERO(&rfds); > FD_SET(m_inotify_fd, &rfds); > retval = select(m_inotify_fd+1, &rfds, NULL, NULL, NULL); > > if(retval < 0) { > printf("select failed.. trying again\n"); > continue; > } > > int pending = -1; > int offset = 0; > char buf[4096]; > assert( m_inotify_fd > -1 ); > ioctl( m_inotify_fd, FIONREAD, &pending ); > > while ( pending > 0 ) { > > if ( pending > (int)sizeof( buf ) ) > pending = sizeof( buf ); > > pending = read( m_inotify_fd, buf, pending); > > while ( pending > 0 ) { > struct inotify_event *event = (struct inotify_event *) &buf[offset]; > pending -= sizeof( struct inotify_event ) + event->len; > offset += sizeof( struct inotify_event ) + event->len; > > if (event->mask & IN_IGNORED) > printf("--> ignored\n"); > > printf("ev wd: %d mask %x\n", event->wd, event->mask); > > if (event->mask & IN_DELETE_SELF) { > printf ("---> got deleteself signal..\n"); > > for (i = 0; sizeof(watches)/sizeof(struct foo); ++i) > if (watches[i].wd == event->wd) > printf (" for path %s\n", watches[i].path); > int r = inotify_rm_watch(m_inotify_fd, event->wd); > assert(r == 0); > } > } > } > } > > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
Attachments on
bug 131322
:
55935
| 56009 |
60580
|
61968