OpenVZ Forum


Home » Mailing lists » Devel » [RFC][PATCH][cryo] Read/print contents of fifo
[RFC][PATCH][cryo] Read/print contents of fifo [message #31080] Tue, 17 June 2008 21:30 Go to next message
Sukadev Bhattiprolu is currently offline  Sukadev Bhattiprolu
Messages: 413
Registered: August 2006
Senior Member
>From 0f5b3ea20238e0704a71252a3d495ca0db61e1dc Mon Sep 17 00:00:00 2001
From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
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@us.ibm.com>
---
 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

_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [RFC][PATCH][cryo] Read/print contents of fifo [message #31083 is a reply to message #31080] Tue, 17 June 2008 22:31 Go to previous message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
Quoting sukadev@us.ibm.com (sukadev@us.ibm.com):
> 
> >From 0f5b3ea20238e0704a71252a3d495ca0db61e1dc Mon Sep 17 00:00:00 2001
> From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
> 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@us.ibm.com>

Thanks, will apply to the git tree tonight.

-serge

> ---
>  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
_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Previous Topic: [RFC][PATCH] Restore fd flags in restarted process
Next Topic: OpenVZ and SELinux
Goto Forum:
  


Current Time: Thu Jul 10 01:10:36 GMT 2025

Total time taken to generate the page: 0.03256 seconds