Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 May 2000 07:56:34 -0500 (CDT)
From:      Chris Dillon <cdillon@wolves.k12.mo.us>
To:        Dan Nelson <dnelson@emsphone.com>
Cc:        Konrad Heuer <kheuer@gwdu60.gwdg.de>, Lorenzo Iania <l.iania@sintesi.net>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: PROBLEM FOUND (sort of): Re: lpr: order of print requests
Message-ID:  <Pine.BSF.4.20.0005030746200.1907-100000@mail.wolves.k12.mo.us>
In-Reply-To: <20000502174713.A14919@dan.emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 2 May 2000, Dan Nelson wrote:

> In the last episode (May 02), Chris Dillon said:
> > On Tue, 2 May 2000, Konrad Heuer wrote:
> > > Hmm, I've never seen such a strange behaviour. Lpd should do FIFO.
> > > Could you give some more infos about your environment (os release,
> > > input filter program, printer type)?
> 
> Aha.  Yes, it _does_ do FIFO, but if you look at the source, the queue
> sorting routine simply sorts on stat(mtime) of the queue file, so jobs
> submitted in the same second will sort randomly.  A quick fix would be
> to sleep for 1 second between "lpr" calls.

That isn't the problem.  You can sleep as much as you want between
submitting the print jobs and the job order still gets munged.  Even a
job that at one time had #1 rank gets inverted and ends up with the
lowest rank.  I even modified common.c (a shot in the dark, I had no
idea what I was doing, really) to check for modtime with
st_mtimespec.tv_nsec for nsec modtime resolution, and that didn't
change the behaviour any.

It appears that qsort() is the culprit.  In fact, here is an excerpt
from the manpage:

    The functions qsort() and heapsort() are not stable, that is, if two mem-
    bers compare as equal, their order in the sorted array is undefined.  The
    function mergesort() is stable.                    

You would think that with nsec modtime resolution, the chance of two
jobs having equal sort criteria is slim to none, so most likely I
didn't do the modtime change correctly.

I wonder if we can work mergesort() in there somehow.  I also notice
that the job numbers assigned to the jobs are sequential, so maybe
that can be a sort criteria as well.  I'm just being a detective, but
I'm not a C programmer, so don't look at me. :-)


-- Chris Dillon - cdillon@wolves.k12.mo.us - cdillon@inter-linc.net
   FreeBSD: The fastest and most stable server OS on the planet.
   For Intel x86 and Alpha architectures. ( http://www.freebsd.org )




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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.20.0005030746200.1907-100000>