Date: Mon, 23 Oct 2006 22:04:47 -0500 (CDT) From: Sean Farley <sean-freebsd@farley.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/104731: [patch] missing newline in lpq output Message-ID: <200610240304.k9O34lOq002733@thor.farley.org> Resent-Message-ID: <200610240310.k9O3AL2o018848@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 104731 >Category: bin >Synopsis: [patch] missing newline in lpq output >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Oct 24 03:10:20 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Sean Farley >Release: FreeBSD 6.2-PRERELEASE i386 >Organization: >Environment: System: FreeBSD thor.farley.org 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #1: Sun Oct 1 12:38:47 CDT 2006 root@thor.farley.org:/usr/obj/usr/src/sys/THOR i386 >Description: When lpq outputs the status from a remote printer/lpd, it prints exactly what is given to it. With an HP 3055 that has no jobs, the output is "queue empty" without the newline. >How-To-Repeat: lpq run against a printer or lpd that does not send a closing newline. >Fix: I am providing two patches. The first simply prints a newline following a complete output from the printer. The second checks for a newline and prints one only if the last character was not a newline. I prefer the second patch, but the first is better than nothing. There is a second spot in the display code, but I am not certain that it requires the same type of patch. The patches will also be available at: http://www.farley.org/freebsd/tmp/PR/<PR #>/lpq-patch1.txt http://www.farley.org/freebsd/tmp/PR/<PR #>/lpq-patch2.txt ------ First patch ------ diff -ru /usr/src/usr.sbin/lpr/common_source/displayq.c lpr/common_source/displayq.c --- /usr/src/usr.sbin/lpr/common_source/displayq.c Thu Dec 30 18:36:28 2004 +++ lpr/common_source/displayq.c Mon Oct 23 20:44:15 2006 @@ -255,6 +255,7 @@ fatal(pp, "Lost connection"); while ((i = read(fd, line, sizeof(line))) > 0) (void) fwrite(line, 1, i, stdout); + fprintf(stdout, "\n"); (void) close(fd); } } ------ First patch ------ ------ Second patch ------ diff -ru /usr/src/usr.sbin/lpr/common_source/displayq.c lpr/common_source/displayq.c --- /usr/src/usr.sbin/lpr/common_source/displayq.c Thu Dec 30 18:36:28 2004 +++ lpr/common_source/displayq.c Mon Oct 23 20:54:32 2006 @@ -96,6 +96,7 @@ { register struct jobqueue *q; register int i, nitems, fd, ret; + int lastChar; char *cp, *endp; struct jobqueue **queue; struct stat statb; @@ -253,8 +254,13 @@ i = strlen(line); if (write(fd, line, i) != i) fatal(pp, "Lost connection"); - while ((i = read(fd, line, sizeof(line))) > 0) + lastChar = 0; + while ((i = read(fd, line, sizeof(line))) > 0) { (void) fwrite(line, 1, i, stdout); + lastChar = i - 1; + } + if (lastChar > 0 && line[lastChar] != '\n') + fprintf(stdout, "\n"); (void) close(fd); } } ------ Second patch ------ >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200610240304.k9O34lOq002733>