r2225 - alfs-POC/src

jhuntwork at linuxfromscratch.org jhuntwork at linuxfromscratch.org
Sat Nov 26 11:35:11 PST 2005


Author: jhuntwork
Date: 2005-11-26 12:35:10 -0700 (Sat, 26 Nov 2005)
New Revision: 2225

Modified:
   alfs-POC/src/alfs.c
   alfs-POC/src/alfsd.c
Log:
Playing with pipes

Modified: alfs-POC/src/alfs.c
===================================================================
--- alfs-POC/src/alfs.c	2005-11-26 17:56:32 UTC (rev 2224)
+++ alfs-POC/src/alfs.c	2005-11-26 19:35:10 UTC (rev 2225)
@@ -55,7 +55,6 @@
 	fgets(input, sizeof(input), stdin);
 	fflush(stdin);
 	len = strlen(input);
-	printf("You entered: %s\n", input);
 
 	/* Send the input to the server */
 	send(sockfd, input, len, 0);

Modified: alfs-POC/src/alfsd.c
===================================================================
--- alfs-POC/src/alfsd.c	2005-11-26 17:56:32 UTC (rev 2224)
+++ alfs-POC/src/alfsd.c	2005-11-26 19:35:10 UTC (rev 2225)
@@ -14,7 +14,7 @@
 	#define PORT 1234
 	#define SA struct sockaddr
 
-	int listenfd, connfd, syscmd;
+	int listenfd, connfd, syscmd, pair[2];
 	struct sockaddr_in servaddr;
 	char buff[MAXLINE];
 	
@@ -43,7 +43,13 @@
 		   three-way handshake*/
 	    connfd = accept(listenfd, (SA *) NULL, NULL);
 
+	    /* Set up pipe from stdout to an empty descriptor */
+	    if (pipe(pair) == -1)
+		perror("pipe");
 
+	    if (dup2(pair[1],1) == -1)
+		perror("dup2");
+
             if (!fork()) { /* this is the child process */
 
 		/* read a string from the socket into a buffer */
@@ -56,16 +62,17 @@
 		syscmd = system(buff);
 
 		if (syscmd == 0)
-		  	snprintf(buff, 29, "CLIENT: Command successful!\n");
+		{
+			/* read the empty descriptor (redirected stdout) into the buffer */
+			read(pair[0], buff, MAXLINE);
+		}
 
 		if (syscmd == 32512)
 		    	snprintf(buff, 25, "CLIENT: Command failed!\n");
 
 		if (syscmd == -1)
 			perror("system");
-		
-		
-		printf("Exit status of command was: %d\n", syscmd);
+	
 		write(connfd, buff, strlen(buff));
 		close(connfd);
                 exit(0);




More information about the alfs-log mailing list