home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.unix
- From: paul@vix.com (Paul Vixie)
- Subject: v26i277: uulocks - print status summary of UUCP locks, Part01/01
- Sender: unix-sources-moderator@gw.home.vix.com
- Approved: vixie@gw.home.vix.com
-
- Submitted-By: paul@vix.com (Paul Vixie)
- Posting-Number: Volume 26, Issue 277
- Archive-Name: uulocks/part01
-
- NAME
- uulocks - print status summary of UUCP locks
-
- SYNOPSIS
- uulocks [ -h ] [ -p [ -a psargs ] ]
-
- DESCRIPTION
- Uulocks searches the various directories which can contain
- UUCP-style ``lock'' files. These files are used by UUCP
- to prevent multiple connections to the same remote neigh-
- bor, and also to control access to the outgoing modems.
- On some systems, tip(1), kermit(1), and even getty(8) use
- these same locks, thus permitting the outbound modems to
- be shared between all modem applications.
-
- Paul Vixie <paul@vix.com>
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: README Makefile uulocks.1 uulocks.c
- # Wrapped by vixie@gw.home.vix.com on Thu Jul 1 13:17:24 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(1376 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XUULOCKS(1) UULOCKS(1)
- X
- XNAME
- X uulocks - print status summary of UUCP locks
- X
- XSYNOPSIS
- X uulocks [ -h ] [ -p [ -a psargs ] ]
- X
- XDESCRIPTION
- X Uulocks searches the various directories which can contain
- X UUCP-style ``lock'' files. These files are used by UUCP
- X to prevent multiple connections to the same remote neigh-
- X bor, and also to control access to the outgoing modems.
- X On some systems, tip(1), kermit(1), and even getty(8) use
- X these same locks, thus permitting the outbound modems to
- X be shared between all modem applications.
- X
- X If the -h option is given, no header will be printed for
- X the report. This is useful if you intend to post-process
- X the output with perl(1) or awk(1).
- X
- X If the -p option is given, then a ps(1) command will be
- X executed for each process seen to have an active lock.
- X This can be followed by the -a option, which specifies the
- X output format to be given to ps(1). The default for newer
- X systems is -o user,tt,ucomm,state,start, and for older
- X systems it is simply u.
- X
- XSEE ALSO
- X ps(1), tip(1), kermit(1), getty(8)
- X
- XFILES
- X /var/spool/uucp/LCK..*
- X /var/run/LCK..*
- X
- XAUTHOR
- X Paul Vixie <paul@vix.com>
- X
- X$Id: README,v 1.1 1993/07/01 20:17:02 vixie Exp $
- END_OF_FILE
- if test 1376 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(649 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# $Id: Makefile,v 1.1 1993/07/01 20:17:02 vixie Exp $
- X
- XDESTROOT =
- XBINDIR = /usr/local/bin
- XCATDIR = /usr/share/man/cat1
- X
- XCC = cc
- XCDEBUG = -g
- XCFLAGS = $(CDEBUG)
- XLDFLAGS =
- XMANROFF = nroff -man
- XSHAR = cshar
- X
- XSOURCES = README Makefile uulocks.1 uulocks.c
- XALL = uulocks uulocks.0
- X
- Xall: $(ALL)
- X
- Xuulocks: uulocks.o Makefile
- X $(CC) $(CDEBUG) $(LDFLAGS) -o $@ uulocks.o
- X
- Xuulocks.0: uulocks.1 Makefile
- X $(MANROFF) <uulocks.1 >$@
- X
- Xclean:
- X rm -f $(ALL) kit
- X rm -f *.o *~ *.BAK *.CKP core
- X
- Xinstall: $(ALL)
- X install -c -m 555 uulocks $(DESTROOT)$(BINDIR)/uulocks
- X install -c -m 444 uulocks.0 $(DESTROOT)$(CATDIR)/uulocks.0
- X
- Xkit: $(SOURCES)
- X $(SHAR) $(SOURCES) >$@
- END_OF_FILE
- if test 649 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'uulocks.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uulocks.1'\"
- else
- echo shar: Extracting \"'uulocks.1'\" \(2124 characters\)
- sed "s/^X//" >'uulocks.1' <<'END_OF_FILE'
- X.\" $Id: uulocks.1,v 1.1 1993/07/01 20:17:02 vixie Exp $
- X.\"
- X.\"/* Copyright 1993 by Paul Vixie
- X.\" * All rights reserved
- X.\" *
- X.\" * Distribute freely, except: don't remove my name from the source or
- X.\" * documentation (don't take credit for my work), mark your changes (don't
- X.\" * get me blamed for your possible bugs), don't alter or remove this
- X.\" * notice. May be sold if buildable source is provided to buyer. No
- X.\" * warrantee of any kind, express or implied, is included with this
- X.\" * software; use at your own risk, responsibility for damages (if any) to
- X.\" * anyone resulting from the use of this software rests entirely with the
- X.\" * user.
- X.\" *
- X.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
- X.\" * I'll try to keep a version up to date. I can be reached as follows:
- X.\" * Paul Vixie <paul@vix.com> || {hoptoad,pacbell,decwrl,crash}!vixie!paul
- X.\" */
- X.TH UULOCKS 1 "1 July 1993"
- X.UC 4
- X.SH NAME
- Xuulocks \- print status summary of UUCP locks
- X.SH SYNOPSIS
- Xuulocks [ \-h ] [ \-p [ \-a psargs ] ]
- X.SH DESCRIPTION
- X.I Uulocks
- Xsearches the various directories which can contain UUCP-style ``lock'' files.
- XThese files are used by UUCP to prevent multiple connections to the same
- Xremote neighbor, and also to control access to the outgoing modems. On some
- Xsystems,
- X.IR tip (1),
- X.IR kermit (1),
- Xand even
- X.IR getty (8)
- Xuse these same locks, thus permitting the outbound modems to be shared
- Xbetween all modem applications.
- X.PP
- XIf the
- X.I \-h
- Xoption is given, no header will be printed for the report. This is useful
- Xif you intend to post-process the output with
- X.IR perl (1)
- Xor
- X.IR awk (1).
- X.PP
- XIf the
- X.I \-p
- Xoption is given, then a
- X.IR ps (1)
- Xcommand will be executed for each process seen to have an active lock. This
- Xcan be followed by the
- X.I \-a
- Xoption, which specifies the output format to be given to
- X.IR ps (1).
- XThe default for newer systems is
- X.IR "\-o user,tt,ucomm,state,start" ,
- Xand for older systems it is simply
- X.IR u .
- X.SH "SEE ALSO"
- Xps(1), tip(1), kermit(1), getty(8)
- X.SH FILES
- X.nf
- X/var/spool/uucp/LCK..*
- X/var/run/LCK..*
- X.fi
- X.SH AUTHOR
- X.nf
- XPaul Vixie <paul@vix.com>
- END_OF_FILE
- if test 2124 -ne `wc -c <'uulocks.1'`; then
- echo shar: \"'uulocks.1'\" unpacked with wrong size!
- fi
- # end of 'uulocks.1'
- fi
- if test -f 'uulocks.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uulocks.c'\"
- else
- echo shar: Extracting \"'uulocks.c'\" \(3412 characters\)
- sed "s/^X//" >'uulocks.c' <<'END_OF_FILE'
- X/* uulocks - show status of UUCP ("modem") locks
- X * vixie 30jun93 [original]
- X *
- X * $Id: uulocks.c,v 1.1 1993/07/01 20:17:02 vixie Exp $
- X */
- X
- X#include <sys/param.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <dirent.h>
- X#include <stdio.h>
- X#include <errno.h>
- X#include <string.h>
- X
- Xstatic char LckPre[] = "LCK..";
- Xstatic int LPLen = (sizeof LckPre) - 1;
- Xstatic int BadExit = 1, GoodExit = 0;
- Xstatic int PS = 0, Fix = 0, NoHdr = 0;
- X#if (BSD >= 199103)
- Xstatic char *PScmd = "ps %s -p %d";
- Xstatic char *PSarg = "-o user,tt,ucomm,state,start";
- X#else
- Xstatic char *PScmd = "ps %s%d";
- Xstatic char *PSarg = "u";
- X#endif
- Xstatic char AsciiBS = 0x08;
- Xstatic time_t Now;
- X
- Xmain(argc, argv)
- X int argc;
- X char *argv[];
- X{
- X time(&Now);
- X args(argc, argv);
- X do_hdr();
- X do_dir("/var/spool/uucp");
- X do_dir("/var/run");
- X exit(GoodExit);
- X}
- X
- Xusage() {
- X fprintf(stderr, "usage: uulocks [-h] [-p] [-a psargs] [-f]\n");
- X exit(BadExit);
- X}
- X
- Xargs(argc, argv)
- X int argc;
- X char *argv[];
- X{
- X extern char *optarg;
- X char ch;
- X
- X while ((ch = getopt(argc, argv, "hpa:f")) != EOF) {
- X switch (ch) {
- X case 'h': NoHdr++; break;
- X case 'p': PS++; break;
- X case 'a': PSarg = optarg; break;
- X case 'f': Fix++; break;
- X default: usage(); break;
- X }
- X }
- X}
- X
- Xdo_hdr() {
- X if (!NoHdr) {
- X fputs("\
- XResource PID Lock Age PStat\
- X" , stdout);
- X if (PS) {
- X fputs( " (PS Result)", stdout);
- X }
- X/*
- Xttya1 23321 001+00:35:51 alive (root 23321 ?? getty IE Wed12PM)
- X*/
- X putchar('\n');
- X }
- X}
- X
- Xdo_dir(path)
- X char *path;
- X{
- X DIR *dir;
- X struct dirent *dp;
- X
- X if (chdir(path) < 0) {
- X perror(path);
- X exit(BadExit);
- X }
- X if (!(dir = opendir("."))) {
- X perror(path);
- X exit(BadExit);
- X }
- X while (dp = readdir(dir)) {
- X FILE *lck;
- X pid_t pid;
- X struct stat sb;
- X time_t age;
- X char timbuf[(sizeof "000+00:00:00")];
- X int j;
- X
- X if ((dp->d_namlen < LPLen)
- X || strncmp("LCK..", dp->d_name, LPLen))
- X continue;
- X if (!(lck = fopen(dp->d_name, "r"))) {
- X perror(dp->d_name);
- X continue;
- X }
- X if (fstat(fileno(lck), &sb)) {
- X perror(dp->d_name);
- X continue;
- X }
- X pid = (pid_t) getw(lck);
- X fclose(lck);
- X age = Now - sb.st_mtime;
- X strftime(timbuf, sizeof timbuf, "%j+%H:%M:%S", gmtime(&age));
- X sprintf(timbuf, "%03d", atoi(timbuf)-1);
- X timbuf[3] = '+'; /* ugly */
- X if (kill(pid, 0) >= 0)
- X j = 1;
- X else
- X j = (errno != ESRCH);
- X printf("%-12s%10d %s %-5s",
- X dp->d_name+LPLen, pid, timbuf,
- X j ?"alive" :"dead");
- X if (Fix && !j) {
- X printf(" [unlink: %s]",
- X (unlink(dp->d_name)>=0) ?"ok" :strerror(errno));
- X }
- X if (PS && j) {
- X char cmdbuf[100]; /* ugly */
- X FILE *ps;
- X
- X sprintf(cmdbuf, PScmd, PSarg, pid);
- X if (!(ps = popen(cmdbuf, "r"))) {
- X printf(" [ps: %s]", strerror(errno));
- X } else {
- X char ch, last_ch;
- X
- X /* eat header */
- X while (((ch = getc(ps)) != '\n')
- X && (ch != EOF)
- X )
- X ;
- X /* get first line, compress multiple blanks */
- X if ((last_ch = ch) != EOF) {
- X fputs(" (", stdout);
- X while (((ch = getc(ps)) != '\n')
- X && (ch != EOF)
- X ) {
- X if (ch == ' '
- X && last_ch == ' '
- X ) {
- X continue;
- X }
- X putchar(ch);
- X last_ch = ch;
- X }
- X if (last_ch == ' ') {
- X putchar(AsciiBS); /* ugly */
- X }
- X putchar(')');
- X }
- X /* run it out */
- X while (ch != EOF) {
- X last_ch = ch;
- X ch = getc(ps);
- X }
- X }
- X pclose(ps);
- X }
- X putchar('\n');
- X }
- X closedir(dir);
- X}
- END_OF_FILE
- if test 3412 -ne `wc -c <'uulocks.c'`; then
- echo shar: \"'uulocks.c'\" unpacked with wrong size!
- fi
- # end of 'uulocks.c'
- fi
- echo shar: End of shell archive.
- exit 0
-