Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Feb 1999 20:29:26 +0100
From:      Andre Albsmeier <andre.albsmeier@mchp.siemens.de>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Enhancement for lpr (patch included)
Message-ID:  <19990203202926.B10589@internal>

next in thread | raw e-mail | index | archive | help
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 would fix my style :-))

This code is now running here for about half 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.0-STABLE but runs on 2.2.8 here.

*** 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 {


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



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