Linux Container Development
 help / color / mirror / Atom feed
From: sukadev-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org
To: serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org
Cc: Containers <containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>
Subject: [RFC][PATCH][cryo] Read/print contents of fifo
Date: Tue, 17 Jun 2008 14:30:40 -0700	[thread overview]
Message-ID: <20080617213040.GC11826@us.ibm.com> (raw)


From 0f5b3ea20238e0704a71252a3d495ca0db61e1dc Mon Sep 17 00:00:00 2001
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Sat, 14 Jun 2008 11:45:00 -0700
Subject: [RFC][PATCH] Read/print contents of fifo.

To test that checkpoint/restart of pipes is working, read
one byte at a time from the pipe and write to stdout.

After checkpoint, both the checkpointed application and the
restarted application should continue reading from the checkpoint.

The '-e' option to the program, tests with an empty pipe.

Signed-off-by: Sukadev Bhattiprolu <sukadev-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
 tests/pipe.c |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/tests/pipe.c b/tests/pipe.c
index cc3cdfd..0812cb3 100644
--- a/tests/pipe.c
+++ b/tests/pipe.c
@@ -3,25 +3,49 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
+#include <sys/fcntl.h>
 
-int main()
+int main(int argc, char *argv[])
 {
 	int i = 0;
+	int rc;
 	int fds[2];
+	int c;
+	int empty;
 	char *buf = "abcdefghijklmnopqrstuvwxyz";
 
+	/*
+	 * -e: test with an empty pipe
+	 */
+	empty = 0;
+	if (argc > 1 && strcmp(argv[1], "-e") == 0)
+		empty = 1;
+
 	if (pipe(fds) < 0) {
 		perror("pipe()");
 		exit(1);
 	}
 
-	write(fds[1], buf, strlen(buf));
+	if (!empty)
+		write(fds[1], buf, strlen(buf));
 
+	if (fcntl(fds[0], F_SETFL, O_NONBLOCK) < 0) {
+		perror("fcntl()");
+		exit(1);
+	}
 	printf("Running as %d\n", getpid());
 	while (i<100) {
 		sleep(1);
-		if (i%5 == 0)
-			printf("i is %d (pid %d)\n", i, getpid());
+		if (i%5 == 0) {
+			c = errno = 0;
+			rc = read(fds[0], &c, 1);
+			if (rc != 1) {
+				perror("read() failed");
+			}
+			printf("i is %d (pid %d), c is %c\n", i, getpid(), c);
+
+		}
 		i++;
 	}
 }
-- 
1.5.2.5

             reply	other threads:[~2008-06-17 21:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-17 21:30 sukadev-r/Jw6+rmf7HQT0dZR+AlfA [this message]
     [not found] ` <20080617213040.GC11826-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-06-17 22:31   ` [RFC][PATCH][cryo] Read/print contents of fifo Serge E. Hallyn

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=20080617213040.GC11826@us.ibm.com \
    --to=sukadev-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
    --cc=serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox