Previously, Greg Laird wrote in qdn.public.qnx4:
Hello Andrew,
I have looked at the example that you suggested. The solution of
using both lpsrvr and lpd seems complex to me. I have also not found
anything in the docs about writing to a /dev/spool device to
automatically spool a file (that doesn’t mean it’s not there).
I agree this seems complex, but it also makes a strange kind of
sense. lpd doesn’t offer a local /dev/ because it assumes you
will be printing using lpr. lpsrvr doesn’t offer TCP networked access
because it assumes you will be using QNX networking. If you hook the
/dev/ capability of lpsrvr to the TCP printing capability of
lpd, then you get the exact behaviour you are looking for. This is
consistent with the “UNIX Way” of concatenating simple specialized
applications in various ways to achieve complex behaviour. In this
case I don’t think that using two print spoolers will have any more
impact on stability than any other solution you are considering, and
it means you don’t have to write a line of code.
I was hoping to find an elegant method of letting lpd know that there
is a file to be printed (e.g. storing it in a directory and sending a
message to lpd, or some such thing).
Well, I would actually call anything but invoking lpr to be klugy.
You can safely kill lpd, copy a file into the appropriate spool
directory, create a “cf” file for it, and then restart lpd. I don’t
think that’s very efficient, though.
The system call to invoke lpr
seems sort of klugy to me (firing up both the shell & lpr),
The shell is almost definitely already in memory, so the startup is
pretty cheap, and uses very little extra memory. You have no real
choice but to call lpr, so that startup and memory are a foregone
conclusion. If you really don’t want to run the shell, use spawn() or
qnx_spawn(). At least you don’t have to fiddle with pipes.
Personally, I would write it to spawn() or system() a shell script,
and have the script call lpd. That way I could modify the printing
behaviour without recompiling my program. The difference in time and
memory is pretty minimal unless you are running pretty close to the
limit.
Maybe a file is stored in a directory and a signal gets sent to
lpd???
Not that I’m aware of. lpr creates a control file as well as a spool
file, and it’s reasonable to assume that you aren’t going to reproduce
the behaviour of lpr more reliably than lpr does. If you think you
can get away with a small subset of the lpr behaviour, the source is
available from RedHat, so you can see what you minimally need.
Good luck,
Andrew