mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
common: Fix gnupg_inotify_has_name.
* common/sysutils.c (gnupg_inotify_has_name): Take care of the alignment. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
96414baf36
commit
bc28f320fa
@ -1037,40 +1037,48 @@ int
|
|||||||
gnupg_inotify_has_name (int fd, const char *name)
|
gnupg_inotify_has_name (int fd, const char *name)
|
||||||
{
|
{
|
||||||
#if USE_NPTH && HAVE_INOTIFY_INIT
|
#if USE_NPTH && HAVE_INOTIFY_INIT
|
||||||
union {
|
#define BUFSIZE_FOR_INOTIFY (sizeof (struct inotify_event) + 255 + 1)
|
||||||
struct inotify_event ev;
|
char buf[BUFSIZE_FOR_INOTIFY];
|
||||||
char _buf[sizeof (struct inotify_event) + 255 + 1];
|
char *p;
|
||||||
} buf;
|
|
||||||
struct inotify_event *evp;
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
n = npth_read (fd, &buf, sizeof buf);
|
n = npth_read (fd, buf, sizeof buf);
|
||||||
|
p = buf;
|
||||||
/* log_debug ("notify read: n=%d\n", n); */
|
/* log_debug ("notify read: n=%d\n", n); */
|
||||||
evp = &buf.ev;
|
|
||||||
while (n >= sizeof (struct inotify_event))
|
while (n >= sizeof (struct inotify_event))
|
||||||
{
|
{
|
||||||
|
struct inotify_event ev;
|
||||||
|
const char *ev_name;
|
||||||
|
|
||||||
|
memcpy (&ev, p, sizeof (struct inotify_event));
|
||||||
|
|
||||||
|
if (ev.len > 255 + 1) /* Something goes wrong, skip this data. */
|
||||||
|
break;
|
||||||
|
|
||||||
|
ev_name = p + sizeof (struct inotify_event);
|
||||||
|
p += sizeof (struct inotify_event) + ev.len;
|
||||||
|
n -= sizeof (struct inotify_event) + ev.len;
|
||||||
|
|
||||||
/* log_debug (" mask=%x len=%u name=(%s)\n", */
|
/* log_debug (" mask=%x len=%u name=(%s)\n", */
|
||||||
/* evp->mask, (unsigned int)evp->len, evp->len? evp->name:""); */
|
/* ev.mask, (unsigned int)ev.len, ev.len? ev.name:""); */
|
||||||
if ((evp->mask & IN_UNMOUNT))
|
if ((ev.mask & IN_UNMOUNT))
|
||||||
{
|
{
|
||||||
/* log_debug (" found (dir unmounted)\n"); */
|
/* log_debug (" found (dir unmounted)\n"); */
|
||||||
return 3; /* Directory was unmounted. */
|
return 3; /* Directory was unmounted. */
|
||||||
}
|
}
|
||||||
if ((evp->mask & IN_DELETE_SELF))
|
if ((ev.mask & IN_DELETE_SELF))
|
||||||
{
|
{
|
||||||
/* log_debug (" found (dir removed)\n"); */
|
/* log_debug (" found (dir removed)\n"); */
|
||||||
return 2; /* Directory was removed. */
|
return 2; /* Directory was removed. */
|
||||||
}
|
}
|
||||||
if ((evp->mask & IN_DELETE))
|
if ((ev.mask & IN_DELETE))
|
||||||
{
|
{
|
||||||
if (evp->len >= strlen (name) && !strcmp (evp->name, name))
|
if (ev.len >= strlen (name) && !strcmp (ev_name, name))
|
||||||
{
|
{
|
||||||
/* log_debug (" found (file removed)\n"); */
|
/* log_debug (" found (file removed)\n"); */
|
||||||
return 1; /* File was removed. */
|
return 1; /* File was removed. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n -= sizeof (*evp) + evp->len;
|
|
||||||
evp = (struct inotify_event *)((char*)evp + sizeof (*evp) + evp->len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /*!(USE_NPTH && HAVE_INOTIFY_INIT)*/
|
#else /*!(USE_NPTH && HAVE_INOTIFY_INIT)*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user