summaryrefslogtreecommitdiff
path: root/inotail.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2006-12-28 14:51:14 +0100
committerTobias Klauser <tklauser@xenon.tklauser.home>2006-12-28 14:51:14 +0100
commit67eeaeb5cbf1669218db5ab560ec2d125e085f27 (patch)
treeb8abc2a615e9783407467b4aae17d333840e38e4 /inotail.c
parent30477ae86b35b311362a20e3f9b83378744c3b4e (diff)
inotail.c: Add and use ignore_file() function
Diffstat (limited to 'inotail.c')
-rw-r--r--inotail.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/inotail.c b/inotail.c
index 1fa1645..b032a4f 100644
--- a/inotail.c
+++ b/inotail.c
@@ -82,6 +82,12 @@ static void setup_file(struct file_struct *f)
f->i_watch = -1;
}
+static int ignore_file(struct file_struct *f, int n_ignored)
+{
+ f->ignore = 1;
+ return ++n_ignored;
+}
+
static inline char *pretty_name(char *filename)
{
return (strncmp(filename, "-", 1) == 0) ? "standard input" : filename;
@@ -315,10 +321,7 @@ ignore:
if (close(fil->fd) < 0)
fprintf(stderr, "Error: Could not close file '%s' (%s)\n", fil->name, strerror(errno));
- fil->ignore = 1;
- n_ignored++;
-
- return n_ignored;
+ return ignore_file(fil, n_ignored);
}
static int watch_files(struct file_struct *f, int n_files)
@@ -341,8 +344,7 @@ static int watch_files(struct file_struct *f, int n_files)
if (f[i].i_watch < 0) {
fprintf(stderr, "Error: Could not create inotify watch on file '%s' (%s)\n", f[i].name, strerror(errno));
- f[i].ignore = 1;
- n_ignored++;
+ n_ignored = ignore_file(&f[i], n_ignored);
}
} else
n_ignored++;
@@ -453,7 +455,7 @@ int main(int argc, char **argv)
setup_file(&files[i]);
ret = tail_file(&files[i], n_units, mode, forever);
if (ret < 0)
- files[i].ignore = 1;
+ ignore_file(&files[i], 0);
}
if (forever)