Main Menu

KB#00572-Advantage article regarding the chklck script

Title:

Advantage article regarding the chklck script

Description:

Q: When we have multiple terminals printing to the system spooled printer at the same time, the output gets mixed together. How can we avoid this?

Resolution:

A: If all of your output is going through the spooler, then there is no possibility of mixed printouts unless the system spooler is malfunctioning If you are using direct output along with spooled output, then you must instruct BBx to abide by the "spooler lock file" mechanism. The ALIAS line for a direct printer (in config.bbx) should have the 'lock=' clause. Fore example: 

        alias P0 /dev/lp0 "Direct Printer" cr,lock=/tmp/lp0.lck 
        alias LP ">lp -s -sprinter 2>/dev/null" "Spooled printer - no 'lock=' needed" cr 

The lock file given for the direct printer should be the same lock file that is used by the system spooler. When using lock files, you must not be running as root because root will always override such mechanisms, defeating the lock. A lock file is necessary because most XENIX and UNIX operating systems allow multiple users to open the printer at the same time. For example, the SCO XENIX spooler does not use lock files the way BBx requires. So, you have to modify the appropriate spooler interface files to test for the presence of the lock file, or create the file with the appropriate permissions (r-r-r-). 

The spooler interface files for SCO XENIX are located in the directory /usr/spool/lp/interface/. The WYSE 5000 UNIX operating system, the UNIX operating system, and SCO UNIX 3.2.4 spooler interface files are located in the directory /usr/spool/lp/admins/lp/interfaces/. SCO UNIX may also require relaxed security and configuring the kernel parameter SECSTOPIO to 0 for OFF. 

A printer definition similar to the line below should appear near the top of the interface program: 

        Printer='basename $0' 

Where:         basename         Returns the base name of the current program 
        $0                  name of the current program. That's a zero, not the letter O. 

This assigns the name of the printer device (without any directory names) to the shell variable, printer. You will need to add the following lines to the interface programs for the spoolers you will be using. Place these lines near the top of the interface program, but after the printer definition: 

        /usr/spool/lp/interface/chklck wait $printer 
        trap "/usr/spool/lp/interface/chklck erase $printer;exit 0" 0 2 9 15 

Where:         $printer         Name of the tty device (e.g., lp0 or tty012). 

The ".lck" extension is added in the "chklck" script below. You will need to edit this script using an ASCII editor such as vi. 

# *********************beginning of chklck script******************** 
# !/bin/sh 
# Routine to handle spooler lock files 
# 5/5/88 Scott Amspoker 

# usage: 
# to set lock: chklck wait <printer> 
# to remove lock: chklck erase <printer> 

# This uses the standard technique of creating a file with r--r--r-- permissions. If such a file 
# already exists, the create will fail. This provides an uninterruptible 'test-and-set' type of 
# operation essential for semaphores. 

Printer=/tmp/$2.lck 

# umask is used to force r--r--r-- permissions on the create 

umask 333 
case $1 in 
wait) 

# use sub-shell to redirect error message 

( until > $printer 
do 
        sleep 1 
done ) 2> /dev/null;; 
erase) 
rm -f $printer 2>/dev/null ;; 
esac 

********************end of script******************** 



Last Modified: 07/26/1999 Product: PRO/5 Operating System: Unix

BASIS structures five components of their technology into the BBx Generations.

  Google+ View BASIS LinkedIN ProfileVisit our Twitter Feed Check out our Facebook Public Profile Click to View the BASIS youTube channel