Hi,
As noticed by Con Kolivas:
http://article.gmane.org/gmane.linux.kernel.ck/4045
`tail -f /dev/zero` eats all the available memory and swap until tail
gets killed by the OOM killer (on linux, at least).
The attached patch fixes it; it may not be perfect, but I think this
issue is worth fixing, so it can be a start.
Thanks,
--
Colin
--- src/tail.c.orig 2005-10-07 14:55:13.502248607 +0200
+++ src/tail.c 2005-10-07 14:58:55.000717872 +0200
@@ -64,6 +64,8 @@
/* FIXME: make Follow_name the default? */
#define DEFAULT_FOLLOW_MODE Follow_descriptor
+#define MAX_LINE_SIZE (1024*1024)
+
enum Follow_mode
{
/* Follow the name of each file: if the file is renamed, try to reopen
@@ -524,7 +526,8 @@
size_t total_lines = 0; /* Total number of newlines in all buffers. */
int errors = 0;
size_t n_read; /* Size in bytes of most recent read */
-
+ int total_read = 0;
+
first = last = xmalloc (sizeof (LBUFFER));
first->nbytes = first->nlines = 0;
first->next = NULL;
@@ -536,6 +539,13 @@
n_read = safe_read (fd, tmp->buffer, BUFSIZ);
if (n_read == 0 || n_read == SAFE_READ_ERROR)
break;
+
+ total_read += n_read;
+ if (total_read > MAX_LINE_SIZE) {
+ error (0, 0, _("too long line in %s"), quote (pretty_filename));
+ break;
+ }
+
tmp->nbytes = n_read;
*read_pos += n_read;
tmp->nlines = 0;
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils