NetBSD Problem Report #9996
Received: (qmail 20933 invoked from network); 27 Apr 2000 21:14:19 -0000
Message-Id: <200004271546.KAA00570@bstark.siemens-psc.com>
Date: Thu, 27 Apr 2000 10:46:48 -0500 (CDT)
From: bstark@siemens-psc.com
Reply-To: bstark@siemens-psc.com
To: gnats-bugs@gnats.netbsd.org
Subject: Program pac does not process accounting file correctly.
X-Send-Pr-Version: 3.95
>Number: 9996
>Category: bin
>Synopsis: Program pac does not process accounting file correctly.
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: jdolecek
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Apr 27 21:15:00 +0000 2000
>Closed-Date: Sun Oct 01 19:46:22 +0000 2000
>Last-Modified: Sun Oct 01 19:46:22 +0000 2000
>Originator: Brian Stark
>Release: 1.4X
>Organization:
Siemens Power Transmission and Distribution
Power Systems Control Division
>Environment:
System: NetBSD palomino.siemens-psc.com 1.4X NetBSD 1.4X (PALOMINO) #10: Sat Apr 22 10:49:53 CDT 2000 bstark@palomino.siemens-psc.com:/usr/src/sys/arch/i386/compile/PALOMINO i386
>Description:
The program pac does not process printer accounting files correctly. If you
take a look at the code in pac.c there is a function called account().
This code is responsible for reading the printer accounting file and
expects data in the file to be in the following format:
whitespace
a float value to indicate number of feet/pages
whitespace
an integer to indicate the number of copies
whitespace
hostname
a semi-colon
username
(NOTE: These fields would be on one line, and not spread over multiple
lines -- the above was done for readability)
There are several processing problems in the code. Namely, the integer
for the number of copies is only one character [0..9], and the hostname
and username are not processed correctly at all.
Although I have written some other problem reports on pac, I have not
noticed this problem until now because I have been using the unix-lpr.sh
script that comes with Ghostscript to create my accounting files, and
I have always assumed that the unix-lpr.sh script was doing the write thing.
Now that I have seen how the code works in pac.c, I know that the unix-lpr.sh
script is not putting all of the data that it should in the printer
accounting file.
To illustrate this, here is a sample accounting file with a slight
variation between the first and second lines for comparison in the
output:
palomino:{root}# cat acct
1.00 2 palomino.siemens-psc.com:root
2.00 4palomino.siemens-psc.com:bstark
palomino:{root}# pac -P lp
pages/feet runs price host name and login
---------- ---- -------- ----------------------
1.00 1 $ 0.02 2
2.00 1 $ 0.04 4palomino.siemens-psc.com:bstark
---------- ---- -------- ----------------------
Sum: 3.00 2 $ 0.06
palomino:{root}#
As you can see, the count field is not being processed correctly. Because
of this, the conditional check on variable 'ic' will always fail at the
end of account() and the value for hp->h_count will only be incremented
by 1. This results in incorrect "runs" total on each line.
A side effect of this, is that the price total on each line and the price
summary is not calculated correctly.
>How-To-Repeat:
Create a printer accounting file like the one I created above and execute
pac -P XXX, where XXX is the printer name on your system that has the
printer accounting file defined for it that you just created.
>Fix:
Install my source code changes to the pac.c file. My changes can be
summarized as follows:
* correct processing in function account()
* correct processing in function dumpit()
* remove function any() since it is no longer needed.
In addition, I would like to see some type of comments either in pac.c
itself or in the man page for pac describing the format of the printer
accounting file. This will help others who may try to use the
printer accounting files to understand the correct format of the file.
Once my changes are installed, pac will report the correct information.
Here is a sample run using a larger printer accounting file:
palomino:{root}# pac -P lp
pages/feet runs price host name and login
---------- ---- -------- ----------------------
141.00 142 $ 400.44 palomino.siemens-psc.com:bstark
28.00 29 $ 16.24 palomino.siemens-psc.com:root
---------- ---- -------- ----------------------
Sum: 169.00 171 $ 577.98
palomino:{root}# pac -P lp -m
pages/feet runs price login
---------- ---- -------- ----------------------
141.00 142 $ 400.44 bstark
28.00 29 $ 16.24 root
---------- ---- -------- ----------------------
Sum: 169.00 171 $ 577.98
palomino:{root}# pac -P lp -m -p 0.01
pages/feet runs price login
---------- ---- -------- ----------------------
141.00 142 $ 200.22 bstark
28.00 29 $ 8.12 root
---------- ---- -------- ----------------------
Sum: 169.00 171 $ 288.99
palomino:{root}#
And now, here are the source code changes:
Replace the existing function account() with this one:
static void
account(acct)
FILE *acct;
{
const char *delimiters1 = " \t";
const char *delimiters2 = ":";
/*
* buffer needs to be able to hold a hostname!
*/
char linebuf[MAXHOSTNAMELEN+BUFSIZ+1];
double t;
char *cp, *cp2;
struct hent *hp;
int ic;
memset(&linebuf,'\0',sizeof(linebuf));
while (fgets(linebuf, BUFSIZ, acct) != NULL) {
cp = strtok(linebuf,delimiters1);
t = atof(cp);
cp = strtok(NULL,delimiters1);
ic = atoi(cp);
cp = strtok(NULL,delimiters1);
if (mflag) {
cp = strtok(cp,delimiters2);
cp = strtok(NULL,delimiters2);
}
cp2 = strchr(cp,'\n');
if (cp2)
(*cp2) = '\0';
hp = lookup(cp);
if (hp == NULL) {
if (!allflag)
continue;
hp = enter(cp);
}
hp->h_feetpages += t;
if (ic)
hp->h_count += ic;
else
hp->h_count++;
}
}
Replace the existing dumpit() function with this one:
static void
dumpit()
{
struct hent **base;
struct hent *hp, **ap;
int hno, c, runs;
float feet;
hp = hashtab[0];
hno = 1;
base = (struct hent **) calloc(sizeof hp, hcount);
if (base == NULL)
err(1, "calloc");
for (ap = base, c = hcount; c--; ap++) {
while (hp == NULL)
hp = hashtab[hno++];
*ap = hp;
hp = hp->h_link;
}
qsort(base, hcount, sizeof hp, qucmp);
printf(" pages/feet runs price %s\n",
(mflag ? "login" : "host name and login"));
printf(" ---------- ---- -------- ----------------------\n");
feet = 0.0;
runs = 0;
for (ap = base, c = hcount; c--; ap++) {
hp = *ap;
runs += hp->h_count;
feet += hp->h_feetpages;
printf(" %7.2f %4d $%7.2f %s\n",
hp->h_feetpages, hp->h_count,
hp->h_feetpages * price * hp->h_count,
hp->h_name);
}
if (allflag) {
printf(" ---------- ---- -------- ----------------------\n");
printf("Sum:%7.2f %4d $%7.2f\n", feet, runs,
feet * price * runs);
}
}
Remove function any(), and its prototype since it is no longer needed.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback
State-Changed-By: itojun
State-Changed-When: Thu Apr 27 23:21:24 PDT 2000
State-Changed-Why:
i think i'm done
State-Changed-From-To: feedback->open
State-Changed-By: itojun
State-Changed-When: Thu Apr 27 23:22:12 PDT 2000
State-Changed-Why:
sorry i made change to wrong PR
Responsible-Changed-From-To: bin-bug-people->jdolecek
Responsible-Changed-By: jdolecek
Responsible-Changed-When: Tue May 9 05:24:21 PDT 2000
Responsible-Changed-Why:
I'll take care of this one.
State-Changed-From-To: open->feedback
State-Changed-By: jdolecek
State-Changed-When: Sun Jul 16 14:34:33 PDT 2000
State-Changed-Why:
Slighly different change has been comitted on -current, pullup to 1.5 branch
should follow shortly. I'll send you the patch for test in separate
e-mail.
From: Jaromír Doleček <dolecek@ibis.cz>
To: bstark@siemens-psc.com, gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/9996: Program pac does not process accounting file correctly.
Date: Sun, 16 Jul 2000 23:44:01 +0200 (CEST)
Hi,
I've committed the suggested change on -current. Since I've
implemented the change slighly different way, it would be great if
you would be able to test my change on your data to ensure I've
not screwed something. As soon as you confirm the change is okay,
it will be pulled to 1.5 branch and this PR closed.
Thanks.
Best regards
Jaromir
The patch:
XXXXX
Index: pac.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/lpr/pac/pac.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- pac.c 2000/04/27 13:40:18 1.14
+++ pac.c 2000/07/16 21:33:26 1.15
@@ -1,4 +1,4 @@
-/* $NetBSD: pac.c,v 1.14 2000/04/27 13:40:18 msaitoh Exp $ */
+/* $NetBSD: pac.c,v 1.15 2000/07/16 21:33:26 jdolecek Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)pac.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: pac.c,v 1.14 2000/04/27 13:40:18 msaitoh Exp $");
+__RCSID("$NetBSD: pac.c,v 1.15 2000/07/16 21:33:26 jdolecek Exp $");
#endif
#endif /* not lint */
@@ -95,7 +95,6 @@
static struct hent *hashtab[HSHSIZE]; /* Hash table proper */
static void account __P((FILE *));
-static int any __P((int, const char *));
static int chkprinter __P((const char *));
static void dumpit __P((void));
static int hash __P((const char *));
@@ -205,33 +204,36 @@
* is set, then just gather the facts on everyone.
* Note that we must accomodate both the active and summary file
* formats here.
+ * Format of accounting file is
+ * feet_per_page [runs_count] [hostname:]username
+ * Some software relies on whitespace between runs_count and hostname:username
+ * being optional (such as Ghostscript's unix-lpr.sh).
+ *
* Host names are ignored if the -m flag is present.
*/
static void
account(acct)
FILE *acct;
{
+ char who[BUFSIZ];
char linebuf[BUFSIZ];
- double t;
+ float t;
char *cp, *cp2;
struct hent *hp;
int ic;
while (fgets(linebuf, BUFSIZ, acct) != NULL) {
- cp = linebuf;
- while (any(*cp, " \t"))
- cp++;
- t = atof(cp);
- while (any(*cp, ".0123456789"))
- cp++;
- while (any(*cp, " \t"))
- cp++;
- for (cp2 = cp; !any(*cp2, " \t\n"); cp2++)
- ;
- ic = atoi(cp2);
- *cp2 = '\0';
- if (mflag && strchr(cp, ':'))
- cp = strchr(cp, ':') + 1;
+ if (sscanf(linebuf, "%f %d%s", &t, &ic, who) == 0) {
+ sscanf(linebuf, "%f %s", &t, who);
+ ic = 1;
+ }
+
+ /* if -m was specified, don't use the hostname part */
+ if (mflag && (cp2 = strchr(who, ':')))
+ cp = cp2 + 1;
+ else
+ cp = who;
+
hp = lookup(cp);
if (hp == NULL) {
if (!allflag)
@@ -280,12 +282,14 @@
runs += hp->h_count;
feet += hp->h_feetpages;
printf(" %7.2f %4d $%7.2f %s\n",
- hp->h_feetpages, hp->h_count, hp->h_feetpages * price,
+ hp->h_feetpages, hp->h_count,
+ hp->h_feetpages * price * hp->h_count,
hp->h_name);
}
if (allflag) {
printf(" ---------- ---- -------- ----------------------\n");
- printf("Sum:%7.2f %4d $%7.2f\n", feet, runs, feet * price);
+ printf("Sum:%7.2f %4d $%7.2f\n", feet, runs,
+ feet * price * runs);
}
}
@@ -389,23 +393,6 @@
for (cp = name, h = 0; *cp; h = (h << 2) + *cp++)
;
return((h & 0x7fffffff) % HSHSIZE);
-}
-
-/*
- * Other stuff
- */
-static int
-any(ch, str)
- int ch;
- const char *str;
-{
- int c = ch;
- const char *cp = str;
-
- while (*cp)
- if (*cp++ == c)
- return(1);
- return(0);
}
/*
XXXXX
--
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.ics.muni.cz/~dolecek/
@@@@ Wanna a real operating system ? Go and get NetBSD, damn! @@@@
From: Brian Stark <bstark@siemens-psc.com>
To: =?ISO-8859-1?Q?Jarom=EDr_Dole=E8ek?= <dolecek@ibis.cz>
Cc: gnats-bugs@netbsd.org
Subject: Re: bin/9996: Program pac does not process accounting file correctly.
Date: Sun, 20 Aug 2000 14:32:08 -0500 (CDT)
On Sun, 16 Jul 2000, Jaromír Doleček wrote:
> Hi,
> I've committed the suggested change on -current. Since I've
> implemented the change slighly different way, it would be great if
> you would be able to test my change on your data to ensure I've
> not screwed something. As soon as you confirm the change is okay,
> it will be pulled to 1.5 branch and this PR closed.
>
> Thanks.
>
> Best regards
>
> Jaromir
Hi Jaromir,
Again, sorry it has taken so long to respond to this. I have tested your
patch today and it appears to work fine.
However, there is one issue, but that will probably have to be addressed
in a separate problem-report. That issue is that the script creating the
accounting file entries needs to be create those entries correctly.
As I stated in bin/9996 I hadn't noticed the problem about the number
of runs being processed incorrectly until I actually looked at the code
because I have been using the unix-lpr.sh script that comes with
Ghostscript. The unix-lpr.sh script from the Ghostscript package creates
entries in the accounting file but doesn't include the number of copies.
To solve that problem, I suspect a new version of the unix-lpr.sh script
should be created and then possibly provided in /usr/share/ghostscript
as a reference for those that want to use the Ghostscript software
(whether it be the packaged version or a separately compiled version...).
Of course, this gets more complex as the filter scripts (both input and
output) are usually site specific, and the input filter is called N times
for the specified N copies, and the output filter is only called once.
I'll take a look at this issue a bit more and try to see what approach
will work best and if necessary, submit a pr for it.
Regards,
Brian
bstark@siemens-psc.com / bstark@uswest.net
From: Brian Stark <bstark@uswest.net>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/9996
Date: Thu, 28 Sep 2000 23:57:35 -0500 (CDT)
This problem report has been in feedback state since Sunday August
20, 2000. According to Jaromir's comment, this was going to be put into
the 1.5 branch. Has this happened?
Brian
bstark@uswest.net / bstark@siemens-psc.com
State-Changed-From-To: feedback->closed
State-Changed-By: jdolecek
State-Changed-When: Sun Oct 1 12:45:39 PDT 2000
State-Changed-Why:
Fixed, pullup to 1.5 branch is pending and will be reloved soon.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.