summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-09-07 13:52:16 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-09-07 13:52:16 +0200
commitfa4c8b85b1d5966beeda6b8b28046eb45a63332d (patch)
treeb636284376d94fe9e3c6ec18e547b154723271aa
parent80a71e08f368bde5add474dd7d9d497ecd835532 (diff)
New upstream release v0.50.5-1
-rw-r--r--Makefile2
-rw-r--r--changelog7
-rw-r--r--debian/changelog7
-rw-r--r--debian/compat2
-rw-r--r--debian/control2
-rw-r--r--inotail.c54
-rw-r--r--inotail.h4
7 files changed, 47 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index bcb8cd4..cfa1402 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
#
# Licensed under the terms of the GNU General Public License; version 2 or later.
-VERSION = 0.4
+VERSION = 0.5
# Paths
prefix = /usr/local
diff --git a/changelog b/changelog
index 851ac3e..f25cc5e 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,10 @@
+inotail 0.5
+
+ * Output verbose file headers correctly when used in a pipe
+ * Small code cleanups
+
+ -- Tobias Klauser <tklauser@distanz.ch> 2007-09-07 13:30
+
inotail 0.4
* Use dynamic buffers of optimal size (st_blksize in struct stat) for
diff --git a/debian/changelog b/debian/changelog
index 0ef3352..4e00f7f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+inotail (0.5-1) unstable; urgency=low
+
+ * New upstream release
+ * Update debhelper compatibility level from 4 to 5
+
+ -- Tobias Klauser <tklauser@access.unizh.ch> Fri, 07 Sep 2007 13:47:09 +0200
+
inotail (0.4-1) unstable; urgency=low
* New upstream release
diff --git a/debian/compat b/debian/compat
index b8626c4..7ed6ff8 100644
--- a/debian/compat
+++ b/debian/compat
@@ -1 +1 @@
-4
+5
diff --git a/debian/control b/debian/control
index 6362a90..58d225d 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: inotail
Section: utils
Priority: optional
Maintainer: Tobias Klauser <tklauser@access.unizh.ch>
-Build-Depends: debhelper (>= 4)
+Build-Depends: debhelper (>= 5)
Standards-Version: 3.7.2
Package: inotail
diff --git a/inotail.c b/inotail.c
index 8561054..920d5a5 100644
--- a/inotail.c
+++ b/inotail.c
@@ -94,8 +94,8 @@ static void usage(const int status)
static inline void setup_file(struct file_struct *f)
{
f->fd = f->i_watch = -1;
- f->st_size = 0;
- f->st_blksize = DEFAULT_BUFFER_SIZE;
+ f->size = 0;
+ f->blksize = DEFAULT_BUFFER_SIZE;
f->ignore = 0;
}
@@ -119,8 +119,10 @@ static void write_header(char *filename)
static unsigned short first_file = 1;
static char *last = NULL;
- if (last != filename)
+ if (last != filename) {
fprintf(stdout, "%s==> %s <==\n", (first_file ? "" : "\n"), pretty_name(filename));
+ fflush(stdout); /* Make sure the header is printed before the content */
+ }
first_file = 0;
last = filename;
@@ -128,14 +130,14 @@ static void write_header(char *filename)
static off_t lines_to_offset_from_end(struct file_struct *f, unsigned long n_lines)
{
- off_t offset = f->st_size;
- char *buf = emalloc(f->st_blksize);
+ off_t offset = f->size;
+ char *buf = emalloc(f->blksize);
n_lines++; /* We also count the last \n */
while (offset > 0 && n_lines > 0) {
int i;
- ssize_t rc, block_size = f->st_blksize; /* Size of the current block we're reading */
+ ssize_t rc, block_size = f->blksize; /* Size of the current block we're reading */
if (offset < block_size)
block_size = offset;
@@ -180,11 +182,11 @@ static off_t lines_to_offset_from_begin(struct file_struct *f, unsigned long n_l
return 0;
n_lines--;
- buf = emalloc(f->st_blksize);
+ buf = emalloc(f->blksize);
- while (offset <= f->st_size && n_lines > 0) {
+ while (offset <= f->size && n_lines > 0) {
int i;
- ssize_t rc, block_size = f->st_blksize;
+ ssize_t rc, block_size = f->blksize;
if (lseek(f->fd, offset, SEEK_SET) == (off_t) -1) {
fprintf(stderr, "Error: Could not seek in file '%s' (%s)\n", f->name, strerror(errno));
@@ -232,8 +234,8 @@ static off_t bytes_to_offset(struct file_struct *f, unsigned long n_bytes)
if (from_begin) {
if (n_bytes > 0)
offset = (off_t) n_bytes - 1;
- } else if ((off_t) n_bytes < f->st_size)
- offset = f->st_size - (off_t) n_bytes;
+ } else if ((off_t) n_bytes < f->size)
+ offset = f->size - (off_t) n_bytes;
return offset;
}
@@ -241,13 +243,13 @@ static off_t bytes_to_offset(struct file_struct *f, unsigned long n_bytes)
static ssize_t tail_pipe(struct file_struct *f)
{
ssize_t rc;
- char *buf = emalloc(f->st_blksize);
+ char *buf = emalloc(f->blksize);
if (verbose)
write_header(f->name);
/* We will just tail everything here */
- while ((rc = read(f->fd, buf, f->st_blksize)) > 0) {
+ while ((rc = read(f->fd, buf, f->blksize)) > 0) {
if (write(STDOUT_FILENO, buf, (size_t) rc) <= 0) {
/* e.g. when writing to a pipe which gets closed */
fprintf(stderr, "Error: Could not write to stdout (%s)\n", strerror(errno));
@@ -285,7 +287,7 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch
}
if (!IS_TAILABLE(finfo.st_mode)) {
- fprintf(stderr, "Error: '%s' of unsupported file type\n", f->name);
+ fprintf(stderr, "Error: '%s' of unsupported file type (%s)\n", f->name, strerror(errno));
ignore_file(f);
return -1;
}
@@ -294,8 +296,8 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch
if (IS_PIPELIKE(finfo.st_mode) || f->fd == STDIN_FILENO)
return tail_pipe(f);
- f->st_size = finfo.st_size;
- f->st_blksize = finfo.st_blksize; /* TODO: Can this value be 0? */
+ f->size = finfo.st_size;
+ f->blksize = finfo.st_blksize; /* TODO: Can this value be 0? */
if (mode == M_LINES)
offset = lines_to_offset(f, n_units);
@@ -316,9 +318,9 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch
return -1;
}
- buf = emalloc(f->st_blksize);
+ buf = emalloc(f->blksize);
- while ((bytes_read = read(f->fd, buf, f->st_blksize)) > 0)
+ while ((bytes_read = read(f->fd, buf, f->blksize)) > 0)
write(STDOUT_FILENO, buf, (size_t) bytes_read);
if (!forever) {
@@ -335,35 +337,36 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch
static int handle_inotify_event(struct inotify_event *inev, struct file_struct *f)
{
- char *fbuf;
int ret = 0;
if (inev->mask & IN_MODIFY) {
+ char *fbuf;
ssize_t rc;
struct stat finfo;
- fbuf = emalloc(f->st_blksize);
-
if (verbose)
write_header(f->name);
/* Seek to old file size */
- if (lseek(f->fd, f->st_size, SEEK_SET) == (off_t) -1) {
+ if (lseek(f->fd, f->size, SEEK_SET) == (off_t) -1) {
fprintf(stderr, "Error: Could not seek in file '%s' (%s)\n", f->name, strerror(errno));
ret = -1;
goto ignore;
}
- while ((rc = read(f->fd, fbuf, f->st_blksize)) != 0)
+ fbuf = emalloc(f->blksize);
+
+ while ((rc = read(f->fd, fbuf, f->blksize)) != 0)
write(STDOUT_FILENO, fbuf, (size_t) rc);
if (fstat(f->fd, &finfo) < 0) {
fprintf(stderr, "Error: Could not stat file '%s' (%s)\n", f->name, strerror(errno));
ret = -1;
+ free(fbuf);
goto ignore;
}
- f->st_size = finfo.st_size;
+ f->size = finfo.st_size;
free(fbuf);
return ret;
@@ -378,7 +381,6 @@ static int handle_inotify_event(struct inotify_event *inev, struct file_struct *
ignore:
ignore_file(f);
- free(fbuf);
return ret;
}
@@ -476,7 +478,7 @@ int main(int argc, char **argv)
optarg++;
if (!is_digit(*optarg)) {
- fprintf(stderr, "Invalid number of lines: %s\n", optarg);
+ fprintf(stderr, "Error: Invalid number of units: %s\n", optarg);
exit(EXIT_FAILURE);
}
n_units = strtoul(optarg, NULL, 0);
diff --git a/inotail.h b/inotail.h
index f7c1406..c95c4f8 100644
--- a/inotail.h
+++ b/inotail.h
@@ -19,8 +19,8 @@ enum { M_LINES, M_BYTES };
struct file_struct {
char *name; /* Name of file (or '-' for stdin) */
int fd; /* File descriptor (or -1 if file is not open */
- off_t st_size; /* File size */
- blksize_t st_blksize; /* Blocksize for filesystem I/O */
+ off_t size; /* File size */
+ blksize_t blksize; /* Blocksize for filesystem I/O */
unsigned ignore; /* Whether to ignore the file in further processing */
int i_watch; /* Inotify watch associated with file_struct */
};