All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Jones <tonyj@suse.de>
To: linux-audit@redhat.com
Subject: PATCH: ausearch doesn't correcly act as a filter when no EOF on input
Date: Mon, 17 Nov 2008 16:17:54 -0800	[thread overview]
Message-ID: <20081118001753.GA10221@suse.de> (raw)

This was filed as a bug in our bugzilla.

works : cat /var/log/audit/audit.log | ausearch -i -if /dev/stdin | cat
doesnt: tail -f /var/log/audit/audit.log | ausearch -i -if /dev/stdin | cat

Obviously it's a contrived example, they have more interesting processes each
side of the filter.   Issue is that tail -f never indicates EOF and if ausearch
stdout is a pipe (versus a file), the output can remain queued in the pipebuf.

Following patch fixes it, or a simpler patch could unconditionally flush stdout.

I've not looked for similar issues elsewhere.

Tony


--- ausearch.c.old	2008-11-17 15:55:47.000000000 -0800
+++ ausearch.c	2008-11-17 16:06:54.000000000 -0800
@@ -58,11 +58,11 @@
 extern int match(llist *l);
 extern void output_record(llist *l);
 
-static int input_is_pipe(void)
+static int is_pipe(int fd)
 {
 	struct stat st;
 
-	if (fstat(0, &st) == 0) {
+	if (fstat(fd, &st) == 0) {
 		if (S_ISFIFO(st.st_mode)) 
 			pipe_mode = 1;
 	}
@@ -92,7 +92,7 @@
 		rc = process_file(user_file);
 	else if (force_logs)
 		rc = process_logs();
-	else if (input_is_pipe())
+	else if (is_pipe(0))
 		rc = process_stdin();
 	else
 		rc = process_logs();
@@ -175,6 +175,7 @@
 {
 	llist entries; // entries in a record
 	int ret;
+	int flush = is_pipe(1);
 
 	/* For each record in file */
 	list_create(&entries);
@@ -185,6 +186,8 @@
 		}
 		if (match(&entries)) {
 			output_record(&entries);
+			if (flush) 
+				fflush(stdout);
 			found = 1;
 			if (just_one) {
 				list_clear(&entries);

             reply	other threads:[~2008-11-18  0:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-18  0:17 Tony Jones [this message]
2008-11-18 15:29 ` PATCH: ausearch doesn't correcly act as a filter when no EOF on input Steve Grubb
2008-11-19 18:26 ` Steve Grubb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081118001753.GA10221@suse.de \
    --to=tonyj@suse.de \
    --cc=linux-audit@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.