November 1997: UniBasic Erroneous Printer Lock Errors

We have discovered an incompatibility between SCO UNIX versions3.2 and SCO OpenServer Release 5 (3.2v5) which may cause UniBasic to incorrectly report a “File is in use and locked” error while attempting to open a printer after its first use.The recommended workaround is to modify the printer script as described in Table I. Please note that the only change is to add the third line in Table I.

The lock problem occurs when the number of a printer script is greater than 65535. This problem occurs with printer scripts that use UniBasic type printer locking, hence lpt.bits users will not experience this problem.

For those readers who like to know the internal details, the remainder of this article explains why this problem occurs. You may skip this section if you just want a solution.

On OpenServer 5, inode numbers have been changed from 16-bit to 32-bit values. UniBasic is compiled on version 3.2v4.2 for backwards compatibility, which means only the lower 16 bits of the inode value are returned to UniBasic. Thus, a 32-bit value is interpreted as a 16-bit inode value. For example, if the inode value of a printer script is 65538,then the lower 16 bits equal 2. Uni-Basic looks for the presence of theprinter lock file as /tmp/lk.2. Initially, the /tmp/lk.2 lock file does not existand UniBasic succeeds on opening the printer. The printer script uses all 32-bits and attempts to remove the lock file /tmp/lk.65538. Thus, the printer lock file is not removed by the script and UniBasic detects the lock file/tmp/lk.2 on subsequent opens and reports a “File is in use and locked” error.

A printer script’s inode number can be found by issuing a “ls -i printer-script” shell command. UniBasic will not encounter erroneous “File is inuse and locked” errors if the inode is a 16-bit value. However, it is difficult and error prone to ensure that printer scripts have 16-bit values. Since UniBasic checks for the existence of the printer lock file using a 16-bit inode number, it is imperative that the printer script also removes a lock file using a 16-bit inode value. This can be easily accomplished in the printer script by using the modulo operator to convert the 32-bit inode value to a 16-bit value. Therefore, the locked problem can be resolved by adding the intalicized line below as shown to the printer script to get a 16-bit inode value.

Table 1
Original Modified
INODE=`ls -i $0`
INODE=`expr "$INODE" : ` *\([0-9]*\)'`
INODE=`ls -i $0`
INODE=`expr "$INODE" : ’ *\([0-9]*\)'`
INODE=`expr "$INODE" % 65536`

If your printer outputs directly to a printer device rather than spooling, then the first five characters in the printer script must be “#lock” so that locking is employed to guarantee single user access to the printer. Please refer to the UniBasic manual under Configuring Printer Drivers” (page 47) for a detailed discussion of locking options.


support@dynamic.com
800.822.2742
949.215.1200