aboutsummaryrefslogtreecommitdiff
path: root/src/watcher.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-10 23:25:11 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-03-10 23:26:52 +0200
commit39a97e438dde837ada9a99cceea93a1cf97db19e (patch)
treeefc492dcfcdc2c21bfdec5c31692b348601cd94a /src/watcher.c
parent87602f5492b842f734dffe22f4e2f85dbc6ce713 (diff)
downloadwydawca-39a97e438dde837ada9a99cceea93a1cf97db19e.tar.gz
wydawca-39a97e438dde837ada9a99cceea93a1cf97db19e.tar.bz2
Provide a convenient debugging macro.
Rename logmsg to wy_log.
Diffstat (limited to 'src/watcher.c')
-rw-r--r--src/watcher.c60
1 files changed, 25 insertions, 35 deletions
diff --git a/src/watcher.c b/src/watcher.c
index 1ba7c71..0af885b 100644
--- a/src/watcher.c
+++ b/src/watcher.c
@@ -84,19 +84,15 @@ create_watcher(struct spool *sp, void *data)
return 0;
if (!sp->inotify_enable) {
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG,
- "disabling inotify support for spool %s",
- sp->tag);
+ wy_debug(2, ("disabling inotify support for spool %s",
+ sp->tag));
return 0;
}
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "spool %s: creating watcher %s", sp->tag,
- path);
+ wy_debug(2, ("spool %s: creating watcher %s", sp->tag, path));
dwp = malloc(sizeof(*dwp));
if (!dwp) {
- logmsg(LOG_ERR, "not enough memory");
+ wy_log(LOG_ERR, "not enough memory");
return 1;
}
dwp->spool = sp;
@@ -106,7 +102,7 @@ create_watcher(struct spool *sp, void *data)
IN_DELETE | IN_CREATE | IN_CLOSE_WRITE |
IN_MOVED_FROM | IN_MOVED_TO);
if (wd == -1) {
- logmsg(LOG_ERR, "cannot set watch on %s: %s", path,
+ wy_log(LOG_ERR, "cannot set watch on %s: %s", path,
strerror(errno));
free(dwp);
return 1;
@@ -123,16 +119,14 @@ watcher_init()
int ifd, rc;
if (!inotify_enable) {
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "disabling inotify support");
+ wy_debug(2, ("disabling inotify support"));
return -1;
}
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "setting up inotify");
+ wy_debug(2, ("setting up inotify"));
ifd = inotify_init();
if (ifd == -1) {
- logmsg(LOG_ERR, "inotify_init: %s", strerror(errno));
+ wy_log(LOG_ERR, "inotify_init: %s", strerror(errno));
return -1;
}
@@ -140,12 +134,11 @@ watcher_init()
if (rc)
exit(EX_OSERR);
if (!dirwatcher_list) {
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "inotify: nothing to watch");
+ wy_debug(2, ("inotify: nothing to watch"));
close(ifd);
ifd = -1;
- } else if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "inotify initialized successfully");
+ } else
+ wy_debug(2, ("inotify initialized successfully"));
return ifd;
}
@@ -160,7 +153,7 @@ process_event(struct inotify_event *ep)
if (ep->mask & IN_IGNORED)
/* nothing */ ;
else if (ep->mask & IN_Q_OVERFLOW)
- logmsg(LOG_NOTICE, "event queue overflow");
+ wy_log(LOG_NOTICE, "event queue overflow");
else if (ep->mask & IN_UNMOUNT)
/* FIXME: not sure if there's
anything to do. Perhaps we should
@@ -169,29 +162,26 @@ process_event(struct inotify_event *ep)
*/ ;
else if (!dwp) {
if (ep->name)
- logmsg(LOG_NOTICE, "unrecognized event %x for %s",
+ wy_log(LOG_NOTICE, "unrecognized event %x for %s",
ep->mask, ep->name);
else
- logmsg(LOG_NOTICE, "unrecognized event %x", ep->mask);
+ wy_log(LOG_NOTICE, "unrecognized event %x", ep->mask);
} else if (ep->mask & IN_CREATE) {
- if (wy_debug_level > 0)
- logmsg(LOG_DEBUG, "%s/%s created",
- dwp->spool->source_dir, ep->name);
+ wy_debug(1, ("%s/%s created",
+ dwp->spool->source_dir, ep->name));
} else if (ep->mask & (IN_DELETE | IN_MOVED_FROM)) {
- if (wy_debug_level > 0)
- logmsg(LOG_DEBUG, "%s/%s %s", dwp->spool->source_dir,
- ep->name,
- ep->mask & IN_DELETE ? "deleted" : "moved out");
+ wy_debug(1, ("%s/%s %s", dwp->spool->source_dir,
+ ep->name,
+ ep->mask & IN_DELETE ? "deleted" : "moved out"));
triplet_remove_file(dwp->spool, ep->name);
} else if (ep->mask & (IN_CLOSE_WRITE | IN_MOVED_TO)) {
- if (wy_debug_level > 0)
- logmsg(LOG_DEBUG, "%s/%s written",
- dwp->spool->source_dir, ep->name);
+ wy_debug(1, ("%s/%s written",
+ dwp->spool->source_dir, ep->name));
if (spool_add_new_file(dwp->spool, ep->name, 0, NULL) == 0
&& (tp = link_processable_triplets()))
schedule_job(&inotify_spool, getuid(), tp);
} else
- logmsg(LOG_NOTICE, "%s/%s: unexpected event %x",
+ wy_log(LOG_NOTICE, "%s/%s: unexpected event %x",
dwp->spool->source_dir, ep->name, ep->mask);
}
@@ -206,7 +196,7 @@ watcher_run(int ifd)
int rdbytes;
if (ioctl(ifd, FIONREAD, &n)) {
- logmsg(LOG_ERR, "ioctl: %s", strerror(errno));
+ wy_log(LOG_ERR, "ioctl: %s", strerror(errno));
return -1;
}
if (offset + n > sizeof buffer)
@@ -216,12 +206,12 @@ watcher_run(int ifd)
if (rdbytes == -1) {
if (errno == EINTR) {
/*FIXME
- logmsg (LOG_NOTICE, "got signal %d", signo);
+ wy_log (LOG_NOTICE, "got signal %d", signo);
*/
return 0;
}
- logmsg(LOG_NOTICE, "read failed: %s", strerror(errno));
+ wy_log(LOG_NOTICE, "read failed: %s", strerror(errno));
return -1;
}
}

Return to:

Send suggestions and report system problems to the System administrator.