Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Jun 1999 21:09:14 +0200 (CEST)
From:      Andre Albsmeier <andre.albsmeier@mchp.siemens.de>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/11997: Enhancement for lpr
Message-ID:  <199906021909.VAA06209@internal>

next in thread | raw e-mail | index | archive | help

>Number:         11997
>Category:       bin
>Synopsis:       Enhancement for lpr
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun  2 12:10:01 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Andre Albsmeier
>Release:        FreeBSD 3.2-STABLE i386
>Organization:
>Environment:

any lpr

>Description:

I think I have a nice enhancement for lpr in case the file to be
printed resides on the same filesystem as the lpd spooling
directory and should be deleted after printing.

That really becomes interesting in combination with samba and
pcnfs (and maybe others) since they:

a) create temporay files which are removed after printing,
b) often have their spool area on the same fs as lpd.

Normally they invoke lpr with -r. So lpr copies the (temporary)
file and deletes it. After having been printed, lpd removes its
file also.

So why do we copy the file when it is removed afterwards? Since
especially our files here being printed via samba are rather big
(20MB and more) this consumes time for copying and temporary disk
space as well.

I have made a small patch for lpr.c which tries to move the file
if being called with -r. If that failes (maybe because the file
resides on a different fs), it continues normally.

I would like if someone could look into my patch if it contains
security holes or other flaws I haven't thought about. If this isn't
the case, maybe we could commit it to the main tree. (Yes, in that
case I will change the style :-))

This code is now running here for about a year and never produced
problems. The speed for printing large samba files significally
increased as well as the fs usage was reduced.

The patch is against a recent 3.1-STABLE.

>How-To-Repeat:


>Fix:

*** usr.sbin/lpr/lpr/lpr.c.ORI	Wed Feb  3 19:13:57 1999
--- usr.sbin/lpr/lpr/lpr.c	Wed Feb  3 19:15:23 1999
***************
*** 370,375 ****
--- 370,393 ----
  		}
  		if (sflag)
  			printf("%s: %s: not linked, copying instead\n", name, arg);
+ 		if( f ) {		/* means that the file should be deleted */
+ 			seteuid(euid);	/* needed for rename() to succeed */
+ 			if( ! rename( arg, dfname ) ) {
+ 				register int i;
+ 				chmod( dfname, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
+ 				chown( dfname, userid, getgrnam("daemon")->gr_gid );
+ 				seteuid(uid);
+ 				if (format == 'p')
+ 					card('T', title ? title : arg);
+ 				for (i = 0; i < ncopies; i++)
+ 					card(format, &dfname[inchar-2]);
+ 				card('U', &dfname[inchar-2]);
+ 				card('N', arg);
+ 				nact++;
+ 				continue;
+ 			}
+ 			seteuid(uid);
+ 		}
  		if ((i = open(arg, O_RDONLY)) < 0) {
  			printf("%s: cannot open %s\n", name, arg);
  		} else {


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199906021909.VAA06209>