On Friday 28 March 2008 11:25, Michele Sanges wrote:
> Patch for the today tarball.
> 
> > [line 387]
> > if (fifo_filename)
> >     fp = xfopen_stdin(fifo_filename);
> 
> 'xfopen_stdin' blocks on open so, using the fifo it isn't showed any
> image until the first command is received.
> I modified it and the old way of parsing the commands.

Old way of parsing commands has two bugs, and thus is not acceptable.

1. { echo 11; echo 88; } | { sleep 1; fbsplash -f - ...; }
   will display 11% bar, not 88%.
   (actually, it will not work at all, because you killed
   "dash means stdin" feature...
2. It will hog CPU on EOF, as I explained and had shown with example.

> Denys, can you try this patch and, if it is correct, add it to svn.

Applied apart from the part which you can see in attachment. Thanks.
--
vda
diff -d -urpN busybox.1/miscutils/fbsplash.c busybox.2/miscutils/fbsplash.c
--- busybox.1/miscutils/fbsplash.c	2008-03-28 12:04:59.000000000 +0100
+++ busybox.2/miscutils/fbsplash.c	2008-03-28 12:07:18.000000000 +0100
@@ -359,7 +359,7 @@ int fbsplash_main(int argc, char **argv)
 int fbsplash_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 	const char *fb_device, *cfg_filename, *fifo_filename;
-	FILE *fp = fp; // for compiler
+	int fp = fp; // for compiler
 	bool bCursorOff;
 
 	INIT_G();
@@ -379,6 +379,9 @@ int fbsplash_main(int argc ATTRIBUTE_UNU
 	if (!G.image_filename)
 		bb_show_usage();
 
+	if (fifo_filename)
+		fp = xopen(fifo_filename, O_RDWR);
+
 	fb_open(fb_device);
 
 	if (fifo_filename && bCursorOff) {
@@ -388,32 +391,32 @@ int fbsplash_main(int argc ATTRIBUTE_UNU
 
 	fb_drawimage();
 
-	if (!fifo_filename)
-		return EXIT_SUCCESS;
-
-	fp = xfopen_stdin(fifo_filename);
-
-	while (1) {
-		struct stat statbuf;
+	if (fifo_filename) {
 		unsigned num;
-		char *num_buf;
+		char num_buf[64];
+		int len;
 
 		fb_drawprogressbar(0);
 		// Block on read, waiting for some input.
-		// Use of <stdio.h> style I/O allows to correctly
-		// handle a case when we have many buffered lines
-		// already in the pipe
-		while ((num_buf = xmalloc_fgetline(fp)) != NULL) {
+		while (1) {
+			len = read(fp, num_buf, 64);
+			if (len == -1) {
+#if DEBUG
+				DEBUG_MESSAGE("error reading the fifo");
+#endif
+				break;
+			}
+ 			num_buf[len] = '\0';
+
 			if (strncmp(num_buf, "exit", 4) == 0) {
+#if DEBUG
 				DEBUG_MESSAGE("exit");
- exit_cmd:
-				if (bCursorOff) {
-					// restore cursor
-					full_write(STDOUT_FILENO, "\x1b" "[?25h", 6);
-				}
-				return EXIT_SUCCESS;
+#endif
+				break;
 			}
+
 			num = atoi(num_buf);
+			
 			if (isdigit(num_buf[0]) && (num <= 100)) {
 #if DEBUG
 				char strVal[10];
@@ -422,30 +425,16 @@ int fbsplash_main(int argc ATTRIBUTE_UNU
 #endif
 				fb_drawprogressbar(num);
 			}
-			free(num_buf);
-		}
-		// We got EOF/error on fp
-		if (ferror(fp))
-			goto exit_cmd;
-		fclose(fp);
-		if (LONE_DASH(fifo_filename)
-		 || stat(fifo_filename, &statbuf) != 0
-		 || !S_ISFIFO(statbuf.st_mode)
-		) {
-			goto exit_cmd;
+		}	// end of while (1)
+
+		if (bCursorOff) {
+			// restore cursor
+			full_write(STDOUT_FILENO, "\x1b" "[?25h", 6);
 		}
-		// It's really a named pipe!
-		// For named pipes, we want to support this:
-		//  mkfifo cmd_pipe
-		//  fbsplash -f cmd_pipe .... &
-		//  ...
-		//  echo 33 >cmd_pipe
-		//  ...
-		//  echo 66 >cmd_pipe
-		// This means that on EOF, we need to close/open cmd_pipe
-		// (just reading again works too, but it hogs CPU)
-		fp = xfopen_stdin(fifo_filename); // blocks on open
-	} // end of while (1)
+
+		if (ENABLE_FEATURE_CLEAN_UP)
+			close(fp);
+	} 
 
 	return EXIT_SUCCESS;
 }
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to