a uucp unlock program

William E. Davidsen Jr davidsen at steinmetz.steinmetz.UUCP
Tue Feb 9 06:59:54 AEST 1988


Some systems to which I connect have a habit of doing a wierd disconnect
which leaves the lock (LCK..) files in /usr/spool/uucp, and prevents
using the lines, etc. This tiny program reads the lock files, gets the
processes id of the program asserting the lock, and if the process is
gone clears the lock.

Call via cron, "unlock /usr/spool/uucp/LCK*" as often as you feel is
needed. I used to do it every ten minutes, but now every hour, due to
better behavior on the part of calling systems.

		"DisClamer = TRUE;"

:
#!/bin/sh
# shar+ created from directory /usr2/davidsen/tmp
# 15:57 on Mon Feb 08, 1988 by davidsen
echo 'x - unlock.c (text)'
sed << 'E!O!F' 's/^X//' > unlock.c
X/*****************************************************************
X |  unlock.c - remove lock files no longer in use
X |----------------------------------------------------------------
X |  This routine is given a list of lock file (such as uucp and
X |  kermit use), and check each to be sure it is still in use.
X |  It reads the process id from each file, and if the process
X |  no longer exists it deletes the file.
X ****************************************************************/
X
X#include <stdio.h>
X#include <errno.h>
X
X#define DEBUG(f,v) if (debug) printf(f, v)
X
Xextern int  errno;
X
Xint     debug = 0;
X
Xmain (argc, argv)
Xint     argc;
Xchar   *argv[];
X{
X    FILE   *fp,
X           *fopen ();
X    short   pid,		/* process id */
X	    kstat,		/* kill status */
X            argnum;
X
X /* see if debug option */
X    if (strcmp (argv[1], "-d") == 0)
X    { /* set debug */
X	debug = 1;
X	argv++;
X	argc--;
X    }
X
X    for (argnum = 1; argnum < argc; argnum++)
X    { /* try to open the file */
X	DEBUG ("Opening file %s...", argv[argnum]);
X	fp = fopen (argv[argnum], "rb");
X    /* don't generate error messages, ignore all problems */
X	if (fp == NULL)
X	{ /* can't open, may be gone due to timeing 
X				*/
X	    DEBUG ("can't open\n", 0);
X	    continue;
X	}
X
X    /* read a value and always close the file */
X	fread (&pid, sizeof pid, 1, fp);
X	DEBUG("pid %d...", pid);
X	fclose (fp);
X
X    /* if the process exists, ignore this file */
X	if ((kstat = kill (pid, 0)) == 0 || errno != ESRCH)
X	{ /* still active */
X	    DEBUG ("active to process %d\n", pid);
X	    continue;
X	}
X	DEBUG("kstat %d ", kstat);
X	DEBUG("errno %d ", errno);
X	unlink (argv[argnum]);
X	DEBUG ("unlinked\n", 0);
X    }
X}
E!O!F
newsize=`wc -c < unlock.c`
if [ $newsize -ne 1670 ]
then echo "File unlock.c was $newsize bytes, 1670 expected"
fi
exit 0
-- 
	bill davidsen		(wedu at ge-crd.arpa)
  {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.unix.xenix mailing list