Hello all,
last week i got a patch from Vladimir Dronnikov to get the printutils
(lpd, lpr, lpq) working properly. This patch is not available on the
Busybox-Homepage yet. So it is not official. NO WARRANTY ;-)

I installed it on a Blackfin 548 Evaluation-board running uClinux and
uClib. I use this lpr to print over network on a remote lpd (not
Busybox).

This patch changes this:
lpr does transfer the printing-file completely, but the server does not
print it, because of a missing acknowledge.


-  
Best regards

Klaus Hachmeister
Research & Development

diff -d -urpN busybox.9/printutils/lpd.c busybox.a/printutils/lpd.c
--- busybox.9/printutils/lpd.c	2008-07-21 23:40:37.000000000 +0200
+++ busybox.a/printutils/lpd.c	2008-07-22 20:48:34.000000000 +0200
@@ -236,6 +236,9 @@ int lpd_main(int argc UNUSED_PARAM, char
 				fd = xopen(queue, O_RDWR | O_APPEND);
 		}
 
+		// signal OK
+		safe_write(STDOUT_FILENO, "", 1);
+
 		// copy the file
 		real_len = bb_copyfd_size(STDIN_FILENO, fd, expected_len);
 		if (real_len != expected_len) {
@@ -243,7 +246,7 @@ int lpd_main(int argc UNUSED_PARAM, char
 				expected_len, real_len);
 			goto err_exit;
 		}
-		// get ACK and see whether it is NUL (ok)
+		// get EOF indicator, see whether it is NUL (ok)
 		// (and don't trash s[0]!)
 		if (safe_read(STDIN_FILENO, &s[1], 1) != 1 || s[1] != 0) {
 			// don't send error msg to peer - it obviously
@@ -262,6 +265,9 @@ int lpd_main(int argc UNUSED_PARAM, char
 
 		free(s);
 		close(fd); // NB: can do close(-1). Who cares?
+
+		// NB: don't do "signal OK" write here, it will be done
+		// at the top of the loop
 	} // while (1)
 
  err_exit:
diff -d -urpN busybox.9/printutils/lpr.c busybox.a/printutils/lpr.c
--- busybox.9/printutils/lpr.c	2008-07-21 23:40:37.000000000 +0200
+++ busybox.a/printutils/lpr.c	2008-07-22 20:54:13.000000000 +0200
@@ -149,6 +149,7 @@ int lpqr_main(int argc UNUSED_PARAM, cha
 
 	// process files
 	do {
+		unsigned cflen;
 		int dfd;
 		struct stat st;
 		char *c;
@@ -194,23 +195,30 @@ int lpqr_main(int argc UNUSED_PARAM, cha
 		);
 		// delete possible "\nX\n" patterns
 		c = controlfile;
+		cflen = (unsigned)strlen(controlfile);
 		while ((c = strchr(c, '\n')) != NULL) {
-			c++;
-			while (c[0] && c[1] == '\n')
-				memmove(c, c+2, strlen(c+1)); /* strlen(c+1) == strlen(c+2) + 1 */
+			if (c[1] && c[2] == '\n') {
+				/* can't use strcpy, results are undefined */
+				memmove(c, c+2, cflen - (c-controlfile) - 1);
+				cflen -= 2;
+			} else {
+				c++;
+			}
 		}
 
 		// send control file
 		if (opts & LPR_V)
 			bb_error_msg("sending control file");
+		/* "Acknowledgement processing must occur as usual
+		 * after the command is sent." */
+		fdprintf(fd, "\x2" "%u c%s\n", cflen, remote_filename);
+		get_response_or_say_and_die(fd, "sending control file");
 		/* "Once all of the contents have
 		 * been delivered, an octet of zero bits is sent as
 		 * an indication that the file being sent is complete.
 		 * A second level of acknowledgement processing
 		 * must occur at this point." */
-		fdprintf(fd, "\x2" "%u c%s\n" "%s" "%c",
-				(unsigned)strlen(controlfile),
-				remote_filename, controlfile, '\0');
+		full_write(fd, controlfile, cflen + 1); /* writes NUL byte too */
 		get_response_or_say_and_die(fd, "sending control file");
 
 		// send data file, with name "dfaXXX"
@@ -219,6 +227,7 @@ int lpqr_main(int argc UNUSED_PARAM, cha
 		st.st_size = 0; /* paranoia: fstat may theoretically fail */
 		fstat(dfd, &st);
 		fdprintf(fd, "\x3" "%"OFF_FMT"u d%s\n", st.st_size, remote_filename);
+		get_response_or_say_and_die(fd, "sending data file");
 		if (bb_copyfd_size(dfd, fd, st.st_size) != st.st_size) {
 			// We're screwed. We sent less bytes than we advertised.
 			bb_error_msg_and_die("local file changed size?!");
--
ptxdist mailing list
[email protected]

Reply via email to