diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bootpd/Makefile | 14 | ||||
-rw-r--r-- | usr.sbin/bootpd/getether.c | 374 | ||||
-rw-r--r-- | usr.sbin/bootpd/hwaddr.c | 283 | ||||
-rw-r--r-- | usr.sbin/bootpef/Makefile | 15 | ||||
-rw-r--r-- | usr.sbin/bootpgw/Makefile | 14 | ||||
-rw-r--r-- | usr.sbin/bootptest/Makefile | 14 | ||||
-rw-r--r-- | usr.sbin/newsyslog/Makefile | 15 | ||||
-rw-r--r-- | usr.sbin/newsyslog/newsyslog.8 | 168 | ||||
-rw-r--r-- | usr.sbin/newsyslog/newsyslog.c | 568 | ||||
-rw-r--r-- | usr.sbin/quot/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/quot/quot.8 | 96 | ||||
-rw-r--r-- | usr.sbin/quot/quot.c | 583 | ||||
-rw-r--r-- | usr.sbin/sa/Makefile | 7 | ||||
-rw-r--r-- | usr.sbin/sa/extern.h | 100 | ||||
-rw-r--r-- | usr.sbin/sa/main.c | 542 | ||||
-rw-r--r-- | usr.sbin/sa/pathnames.h | 35 | ||||
-rw-r--r-- | usr.sbin/sa/pdb.c | 418 | ||||
-rw-r--r-- | usr.sbin/sa/sa.8 | 246 | ||||
-rw-r--r-- | usr.sbin/sa/usrdb.c | 282 | ||||
-rw-r--r-- | usr.sbin/spray/Makefile | 7 | ||||
-rw-r--r-- | usr.sbin/spray/spray.8 | 76 | ||||
-rw-r--r-- | usr.sbin/spray/spray.c | 224 |
22 files changed, 0 insertions, 4087 deletions
diff --git a/usr.sbin/bootpd/Makefile b/usr.sbin/bootpd/Makefile deleted file mode 100644 index fe2d43510306..000000000000 --- a/usr.sbin/bootpd/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# bootpd/Makefile -# $Id: Makefile,v 1.1.1.1 1994/06/27 21:25:49 gwr Exp $ - -PROG= bootpd -CFLAGS+= -DETC_ETHERS -DSYSLOG -DDEBUG -DVEND_CMU - -SRCS= bootpd.c dovend.c readfile.c hash.c dumptab.c \ - lookup.c getif.c hwaddr.c report.c tzone.c - -MAN5= bootptab.0 -MAN8= bootpd.0 -MLINKS= bootpd.8 bootpgw.8 - -.include <bsd.prog.mk> diff --git a/usr.sbin/bootpd/getether.c b/usr.sbin/bootpd/getether.c deleted file mode 100644 index d131b50f7f89..000000000000 --- a/usr.sbin/bootpd/getether.c +++ /dev/null @@ -1,374 +0,0 @@ -/* - * getether.c : get the ethernet address of an interface - * - * All of this code is quite system-specific. As you may well - * guess, it took a good bit of detective work to figure out! - * - * If you figure out how to do this on another system, - * please let me know. <gwr@mc.com> - */ - -#include <sys/types.h> -#include <sys/socket.h> - -#include <ctype.h> -#include <syslog.h> - -#include "report.h" -#define EALEN 6 - -#if defined(ultrix) || (defined(__osf__) && defined(__alpha)) -/* - * This is really easy on Ultrix! Thanks to - * Harald Lundberg <hl@tekla.fi> for this code. - * - * The code here is not specific to the Alpha, but that was the - * only symbol we could find to identify DEC's version of OSF. - * (Perhaps we should just define DEC in the Makefile... -gwr) - */ - -#include <sys/ioctl.h> -#include <net/if.h> /* struct ifdevea */ - -getether(ifname, eap) - char *ifname, *eap; -{ - int rc = -1; - int fd; - struct ifdevea phys; - bzero(&phys, sizeof(phys)); - strcpy(phys.ifr_name, ifname); - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - report(LOG_ERR, "getether: socket(INET,DGRAM) failed"); - return -1; - } - if (ioctl(fd, SIOCRPHYSADDR, &phys) < 0) { - report(LOG_ERR, "getether: ioctl SIOCRPHYSADDR failed"); - } else { - bcopy(&phys.current_pa[0], eap, EALEN); - rc = 0; - } - close(fd); - return rc; -} - -#define GETETHER -#endif /* ultrix|osf1 */ - - -#ifdef SUNOS - -#include <sys/sockio.h> -#include <sys/time.h> /* needed by net_if.h */ -#include <net/nit_if.h> /* for NIOCBIND */ -#include <net/if.h> /* for struct ifreq */ - -getether(ifname, eap) - char *ifname; /* interface name from ifconfig structure */ - char *eap; /* Ether address (output) */ -{ - int rc = -1; - - struct ifreq ifrnit; - int nit; - - bzero((char *) &ifrnit, sizeof(ifrnit)); - strncpy(&ifrnit.ifr_name[0], ifname, IFNAMSIZ); - - nit = open("/dev/nit", 0); - if (nit < 0) { - report(LOG_ERR, "getether: open /dev/nit: %s", - get_errmsg()); - return rc; - } - do { - if (ioctl(nit, NIOCBIND, &ifrnit) < 0) { - report(LOG_ERR, "getether: NIOCBIND on nit"); - break; - } - if (ioctl(nit, SIOCGIFADDR, &ifrnit) < 0) { - report(LOG_ERR, "getether: SIOCGIFADDR on nit"); - break; - } - bcopy(&ifrnit.ifr_addr.sa_data[0], eap, EALEN); - rc = 0; - } while (0); - close(nit); - return rc; -} - -#define GETETHER -#endif /* SUNOS */ - - -#if defined(__386BSD__) || defined(__NetBSD__) -/* Thanks to John Brezak <brezak@ch.hp.com> for this code. */ -#include <sys/ioctl.h> -#include <net/if.h> -#include <net/if_dl.h> -#include <net/if_types.h> - -getether(ifname, eap) - char *ifname; /* interface name from ifconfig structure */ - char *eap; /* Ether address (output) */ -{ - int fd, rc = -1; - register int n; - struct ifreq ibuf[16], ifr; - struct ifconf ifc; - register struct ifreq *ifrp, *ifend; - - /* Fetch the interface configuration */ - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - report(LOG_ERR, "getether: socket %s: %s", ifname, get_errmsg()); - return (fd); - } - ifc.ifc_len = sizeof(ibuf); - ifc.ifc_buf = (caddr_t) ibuf; - if (ioctl(fd, SIOCGIFCONF, (char *) &ifc) < 0 || - ifc.ifc_len < sizeof(struct ifreq)) { - report(LOG_ERR, "getether: SIOCGIFCONF: %s", get_errmsg); - goto out; - } - /* Search interface configuration list for link layer address. */ - ifrp = ibuf; - ifend = (struct ifreq *) ((char *) ibuf + ifc.ifc_len); - while (ifrp < ifend) { - /* Look for interface */ - if (strcmp(ifname, ifrp->ifr_name) == 0 && - ifrp->ifr_addr.sa_family == AF_LINK && - ((struct sockaddr_dl *) &ifrp->ifr_addr)->sdl_type == IFT_ETHER) { - bcopy(LLADDR((struct sockaddr_dl *) &ifrp->ifr_addr), eap, EALEN); - rc = 0; - break; - } - /* Bump interface config pointer */ - n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name); - if (n < sizeof(*ifrp)) - n = sizeof(*ifrp); - ifrp = (struct ifreq *) ((char *) ifrp + n); - } - - out: - close(fd); - return (rc); -} - -#define GETETHER -#endif /* __NetBSD__ */ - - -#ifdef SVR4 -/* - * This is for "Streams TCP/IP" by Lachman Associates. - * They sure made this cumbersome! -gwr - */ - -#include <sys/sockio.h> -#include <sys/dlpi.h> -#include <stropts.h> -#ifndef NULL -#define NULL 0 -#endif - -getether(ifname, eap) - char *ifname; /* interface name from ifconfig structure */ - char *eap; /* Ether address (output) */ -{ - int rc = -1; - char devname[32]; - char tmpbuf[sizeof(union DL_primitives) + 16]; - struct strbuf cbuf; - int fd, flags; - union DL_primitives *dlp; - char *enaddr; - int unit = -1; /* which unit to attach */ - - sprintf(devname, "/dev/%s", ifname); - fd = open(devname, 2); - if (fd < 0) { - /* Try without the trailing digit. */ - char *p = devname + 5; - while (isalpha(*p)) - p++; - if (isdigit(*p)) { - unit = *p - '0'; - *p = '\0'; - } - fd = open(devname, 2); - if (fd < 0) { - report(LOG_ERR, "getether: open %s: %s", - devname, get_errmsg()); - return rc; - } - } -#ifdef DL_ATTACH_REQ - /* - * If this is a "Style 2" DLPI, then we must "attach" first - * to tell the driver which unit (board, port) we want. - * For now, decide this based on the device name. - * (Should do "info_req" and check dl_provider_style ...) - */ - if (unit >= 0) { - memset(tmpbuf, 0, sizeof(tmpbuf)); - dlp = (union DL_primitives *) tmpbuf; - dlp->dl_primitive = DL_ATTACH_REQ; - dlp->attach_req.dl_ppa = unit; - cbuf.buf = tmpbuf; - cbuf.len = DL_ATTACH_REQ_SIZE; - if (putmsg(fd, &cbuf, NULL, 0) < 0) { - report(LOG_ERR, "getether: attach: putmsg: %s", get_errmsg()); - goto out; - } - /* Recv the ack. */ - cbuf.buf = tmpbuf; - cbuf.maxlen = sizeof(tmpbuf); - flags = 0; - if (getmsg(fd, &cbuf, NULL, &flags) < 0) { - report(LOG_ERR, "getether: attach: getmsg: %s", get_errmsg()); - goto out; - } - /* - * Check the type, etc. - */ - if (dlp->dl_primitive == DL_ERROR_ACK) { - report(LOG_ERR, "getether: attach: dlpi_errno=%d, unix_errno=%d", - dlp->error_ack.dl_errno, - dlp->error_ack.dl_unix_errno); - goto out; - } - if (dlp->dl_primitive != DL_OK_ACK) { - report(LOG_ERR, "getether: attach: not OK or ERROR"); - goto out; - } - } /* unit >= 0 */ -#endif /* DL_ATTACH_REQ */ - - /* - * Get the Ethernet address the same way the ARP module - * does when it is pushed onto a new stream (bind). - * One should instead be able just do an dl_info_req - * but many drivers do not supply the hardware address - * in the response to dl_info_req (they MUST supply it - * for dl_bind_ack because the ARP module requires it). - */ - memset(tmpbuf, 0, sizeof(tmpbuf)); - dlp = (union DL_primitives *) tmpbuf; - dlp->dl_primitive = DL_BIND_REQ; - dlp->bind_req.dl_sap = 0x8FF; /* XXX - Unused SAP */ - cbuf.buf = tmpbuf; - cbuf.len = DL_BIND_REQ_SIZE; - if (putmsg(fd, &cbuf, NULL, 0) < 0) { - report(LOG_ERR, "getether: bind: putmsg: %s", get_errmsg()); - goto out; - } - /* Recv the ack. */ - cbuf.buf = tmpbuf; - cbuf.maxlen = sizeof(tmpbuf); - flags = 0; - if (getmsg(fd, &cbuf, NULL, &flags) < 0) { - report(LOG_ERR, "getether: bind: getmsg: %s", get_errmsg()); - goto out; - } - /* - * Check the type, etc. - */ - if (dlp->dl_primitive == DL_ERROR_ACK) { - report(LOG_ERR, "getether: bind: dlpi_errno=%d, unix_errno=%d", - dlp->error_ack.dl_errno, - dlp->error_ack.dl_unix_errno); - goto out; - } - if (dlp->dl_primitive != DL_BIND_ACK) { - report(LOG_ERR, "getether: bind: not OK or ERROR"); - goto out; - } - if (dlp->bind_ack.dl_addr_offset == 0) { - report(LOG_ERR, "getether: bind: ack has no address"); - goto out; - } - if (dlp->bind_ack.dl_addr_length < EALEN) { - report(LOG_ERR, "getether: bind: ack address truncated"); - goto out; - } - /* - * Copy the Ethernet address out of the message. - */ - enaddr = tmpbuf + dlp->bind_ack.dl_addr_offset; - memcpy(eap, enaddr, EALEN); - rc = 0; - - out: - close(fd); - return rc; -} - -#define GETETHER -#endif /* SVR4 */ - - -#ifdef linux -/* - * This is really easy on Linux! This version (for linux) - * written by Nigel Metheringham <nigelm@ohm.york.ac.uk> - * - * The code is almost identical to the Ultrix code - however - * the names are different to confuse the innocent :-) - * Most of this code was stolen from the Ultrix bit above. - */ - -#include <sys/ioctl.h> -#include <net/if.h> /* struct ifreq */ - -/* In a properly configured system this should be either sys/socketio.h - or sys/sockios.h, but on my distribution these don't line up correctly */ -#include <linux/sockios.h> /* Needed for IOCTL defs */ - -getether(ifname, eap) - char *ifname, *eap; -{ - int rc = -1; - int fd; - struct ifreq phys; - bzero(&phys, sizeof(phys)); - strcpy(phys.ifr_name, ifname); - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - report(LOG_ERR, "getether: socket(INET,DGRAM) failed"); - return -1; - } - if (ioctl(fd, SIOCGIFHWADDR, &phys) < 0) { - report(LOG_ERR, "getether: ioctl SIOCGIFHWADDR failed"); - } else { - bcopy(phys.ifr_hwaddr, eap, EALEN); - rc = 0; - } - close(fd); - return rc; -} - -#define GETETHER -#endif /* linux */ - - -/* If we don't know how on this system, just return an error. */ -#ifndef GETETHER -getether(ifname, eap) - char *ifname, *eap; -{ - return -1; -} - -#endif /* !GETETHER */ - -/* - * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-argdecl-indent: 4 - * c-continued-statement-offset: 4 - * c-continued-brace-offset: -4 - * c-label-offset: -4 - * c-brace-offset: 0 - * End: - */ diff --git a/usr.sbin/bootpd/hwaddr.c b/usr.sbin/bootpd/hwaddr.c deleted file mode 100644 index ec515c40e062..000000000000 --- a/usr.sbin/bootpd/hwaddr.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * hwaddr.c - routines that deal with hardware addresses. - * (i.e. Ethernet) - */ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/ioctl.h> - -#if defined(SUNOS) || defined(SVR4) -#include <sys/sockio.h> -#endif -#ifdef SVR4 -#include <sys/stream.h> -#include <stropts.h> -#include <fcntl.h> -#endif - -#include <net/if_arp.h> -#include <netinet/in.h> -#include <stdio.h> -#ifndef NO_UNISTD -#include <unistd.h> -#endif -#include <syslog.h> - -#ifndef USE_BFUNCS -/* Yes, memcpy is OK here (no overlapped copies). */ -#include <memory.h> -#define bcopy(a,b,c) memcpy(b,a,c) -#define bzero(p,l) memset(p,0,l) -#define bcmp(a,b,c) memcmp(a,b,c) -#endif - -#include "bptypes.h" -#include "hwaddr.h" -#include "report.h" - -extern int debug; - -/* - * Hardware address lengths (in bytes) and network name based on hardware - * type code. List in order specified by Assigned Numbers RFC; Array index - * is hardware type code. Entries marked as zero are unknown to the author - * at this time. . . . - */ - -struct hwinfo hwinfolist[] = -{ - {0, "Reserved"}, /* Type 0: Reserved (don't use this) */ - {6, "Ethernet"}, /* Type 1: 10Mb Ethernet (48 bits) */ - {1, "3Mb Ethernet"}, /* Type 2: 3Mb Ethernet (8 bits) */ - {0, "AX.25"}, /* Type 3: Amateur Radio AX.25 */ - {1, "ProNET"}, /* Type 4: Proteon ProNET Token Ring */ - {0, "Chaos"}, /* Type 5: Chaos */ - {6, "IEEE 802"}, /* Type 6: IEEE 802 Networks */ - {0, "ARCNET"} /* Type 7: ARCNET */ -}; -int hwinfocnt = sizeof(hwinfolist) / sizeof(hwinfolist[0]); - - -/* - * Setup the arp cache so that IP address 'ia' will be temporarily - * bound to hardware address 'ha' of length 'len'. - */ -void -setarp(s, ia, ha, len) - int s; /* socket fd */ - struct in_addr *ia; - u_char *ha; - int len; -{ -#ifdef SIOCSARP - struct arpreq arpreq; /* Arp request ioctl block */ - struct sockaddr_in *si; -#ifdef SVR4 - int fd; - struct strioctl iocb; -#endif /* SVR4 */ - - bzero((caddr_t) & arpreq, sizeof(arpreq)); - arpreq.arp_flags = ATF_INUSE | ATF_COM; - - /* Set up the protocol address. */ - arpreq.arp_pa.sa_family = AF_INET; - si = (struct sockaddr_in *) &arpreq.arp_pa; - si->sin_addr = *ia; - - /* Set up the hardware address. */ - bcopy(ha, arpreq.arp_ha.sa_data, len); - -#ifdef SVR4 - /* - * And now the stuff for System V Rel 4.x which does not - * appear to allow SIOCxxx ioctls on a socket descriptor. - * Thanks to several people: (all sent the same fix) - * Barney Wolff <barney@databus.com>, - * bear@upsys.se (Bj|rn Sj|holm), - * Michael Kuschke <Michael.Kuschke@Materna.DE>, - */ - if ((fd=open("/dev/arp", O_RDWR)) < 0) { - report(LOG_ERR, "open /dev/arp: %s\n", get_errmsg()); - } - iocb.ic_cmd = SIOCSARP; - iocb.ic_timout = 0; - iocb.ic_dp = (char *)&arpreq; - iocb.ic_len = sizeof(arpreq); - if (ioctl(fd, I_STR, (caddr_t)&iocb) < 0) { - report(LOG_ERR, "ioctl I_STR: %s\n", get_errmsg()); - } - close (fd); - -#else /* SVR4 */ - /* - * On SunOS, the ioctl sometimes returns ENXIO, and it - * appears to happen when the ARP cache entry you tried - * to add is already in the cache. (Sigh...) - * XXX - Should this error simply be ignored? -gwr - */ - if (ioctl(s, SIOCSARP, (caddr_t) & arpreq) < 0) { - report(LOG_ERR, "ioctl SIOCSARP: %s", get_errmsg()); - } -#endif /* SVR4 */ -#else /* SIOCSARP */ - /* - * Oh well, SIOCSARP is not defined. Just run arp(8). - * XXX - Gag! - */ - char buf[256]; - int status; - - sprintf(buf, "arp -s %s %s temp", - inet_ntoa(*ia), haddrtoa(ha, len)); - if (debug > 2) - report(LOG_INFO, buf); - status = system(buf); - if (status) - report(LOG_ERR, "arp failed, exit code=0x%x", status); - return; -#endif /* SIOCSARP */ -} - - -/* - * Convert a hardware address to an ASCII string. - */ -char * -haddrtoa(haddr, hlen) - u_char *haddr; - int hlen; -{ - static char haddrbuf[3 * MAXHADDRLEN + 1]; - char *bufptr; - - if (hlen > MAXHADDRLEN) - hlen = MAXHADDRLEN; - - bufptr = haddrbuf; - while (hlen > 0) { - sprintf(bufptr, "%02X:", (unsigned) (*haddr++ & 0xFF)); - bufptr += 3; - hlen--; - } - bufptr[-1] = 0; - return (haddrbuf); -} - - -/* - * haddr_conv802() - * -------------- - * - * Converts a backwards address to a canonical address and a canonical address - * to a backwards address. - * - * INPUTS: - * adr_in - pointer to six byte string to convert (unsigned char *) - * addr_len - how many bytes to convert - * - * OUTPUTS: - * addr_out - The string is updated to contain the converted address. - * - * CALLER: - * many - * - * DATA: - * Uses conv802table to bit-reverse the address bytes. - */ - -static u_char conv802table[256] = -{ - /* 0x00 */ 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, - /* 0x08 */ 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, - /* 0x10 */ 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, - /* 0x18 */ 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, - /* 0x20 */ 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, - /* 0x28 */ 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, - /* 0x30 */ 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, - /* 0x38 */ 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, - /* 0x40 */ 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, - /* 0x48 */ 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, - /* 0x50 */ 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, - /* 0x58 */ 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, - /* 0x60 */ 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, - /* 0x68 */ 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, - /* 0x70 */ 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, - /* 0x78 */ 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, - /* 0x80 */ 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, - /* 0x88 */ 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, - /* 0x90 */ 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, - /* 0x98 */ 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, - /* 0xA0 */ 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, - /* 0xA8 */ 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, - /* 0xB0 */ 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, - /* 0xB8 */ 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, - /* 0xC0 */ 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, - /* 0xC8 */ 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, - /* 0xD0 */ 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, - /* 0xD8 */ 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, - /* 0xE0 */ 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, - /* 0xE8 */ 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, - /* 0xF0 */ 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, - /* 0xF8 */ 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF, -}; - -void -haddr_conv802(addr_in, addr_out, len) - register u_char *addr_in, *addr_out; - int len; -{ - u_char *lim; - - lim = addr_out + len; - while (addr_out < lim) - *addr_out++ = conv802table[*addr_in++]; -} - -#if 0 -/* - * For the record, here is a program to generate the - * bit-reverse table above. - */ -static int -bitrev(n) - int n; -{ - int i, r; - - r = 0; - for (i = 0; i < 8; i++) { - r <<= 1; - r |= (n & 1); - n >>= 1; - } - return r; -} - -main() -{ - int i; - for (i = 0; i <= 0xFF; i++) { - if ((i & 7) == 0) - printf("/* 0x%02X */", i); - printf(" 0x%02X,", bitrev(i)); - if ((i & 7) == 7) - printf("\n"); - } -} - -#endif - -/* - * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-argdecl-indent: 4 - * c-continued-statement-offset: 4 - * c-continued-brace-offset: -4 - * c-label-offset: -4 - * c-brace-offset: 0 - * End: - */ diff --git a/usr.sbin/bootpef/Makefile b/usr.sbin/bootpef/Makefile deleted file mode 100644 index dccbc69694f9..000000000000 --- a/usr.sbin/bootpef/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# bootpef/Makefile -# $Id: Makefile,v 1.2 1994/06/27 21:31:21 gwr Exp $ - -PROG= bootpef -SRCDIR= ${.CURDIR}/../bootpd -CFLAGS+= -DETC_ETHERS -DDEBUG -I${SRCDIR} -.PATH: ${SRCDIR} - -SRCS= bootpef.c dovend.c readfile.c hash.c dumptab.c \ - lookup.c hwaddr.c report.c tzone.c - -MAN8= bootpef.0 - -.include <bsd.prog.mk> - diff --git a/usr.sbin/bootpgw/Makefile b/usr.sbin/bootpgw/Makefile deleted file mode 100644 index 677868d5dfb6..000000000000 --- a/usr.sbin/bootpgw/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# bootpgw/Makefile -# $Id: Makefile,v 1.1.1.1 1994/06/27 21:29:46 gwr Exp $ - -PROG= bootpgw -SRCDIR= ${.CURDIR}/../bootpd -CFLAGS+= -DSYSLOG -DDEBUG -I${SRCDIR} -.PATH: ${SRCDIR} - -SRCS= bootpgw.c getif.c hwaddr.c report.c - -MAN8= - -.include <bsd.prog.mk> - diff --git a/usr.sbin/bootptest/Makefile b/usr.sbin/bootptest/Makefile deleted file mode 100644 index c47790ca2d24..000000000000 --- a/usr.sbin/bootptest/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# bootptest/Makefile -# $Id: Makefile,v 1.3 1994/08/22 22:19:04 gwr Exp $ - -PROG= bootptest -SRCDIR= ${.CURDIR}/../bootpd -CFLAGS+= -I${SRCDIR} -.PATH: ${SRCDIR} - -SRCS= bootptest.c print-bootp.c getif.c getether.c report.c - -MAN8= bootptest.0 - -.include <bsd.prog.mk> - diff --git a/usr.sbin/newsyslog/Makefile b/usr.sbin/newsyslog/Makefile deleted file mode 100644 index c04af65ac0db..000000000000 --- a/usr.sbin/newsyslog/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# $Id: Makefile,v 1.6 1994/12/22 12:30:26 cgd Exp $ - -PROG= newsyslog - -CFLAGS+= -DOSF -CFLAGS+= -DCONF=\"/etc/newsyslog.conf\" -CFLAGS+= -DPIDFILE=\"/var/run/syslog.pid\" -CFLAGS+= -DCOMPRESS=\"/usr/bin/gzip\" -CFLAGS+= -DCOMPRESS_POSTFIX=\".gz\" - -BINOWN= root - -MAN8= newsyslog.8 - -.include <bsd.prog.mk> diff --git a/usr.sbin/newsyslog/newsyslog.8 b/usr.sbin/newsyslog/newsyslog.8 deleted file mode 100644 index 72e481655db3..000000000000 --- a/usr.sbin/newsyslog/newsyslog.8 +++ /dev/null @@ -1,168 +0,0 @@ -.TH NEWSYSLOG 8 "January 12, 1989" "Project Athena" -.ns -.\" This file contains changes from the Open Software Foundation. -.\" -.\" from: @(#)newsyslog.8 -.\" $Id: newsyslog.8,v 1.6 1995/01/06 19:20:20 jtc Exp $ -.\" -.\" Copyright 1988, 1989 by the Massachusetts Institute of Technology -.\" -.\" Permission to use, copy, modify, and distribute this software -.\" and its documentation for any purpose and without fee is -.\" hereby granted, provided that the above copyright notice -.\" appear in all copies and that both that copyright notice and -.\" this permission notice appear in supporting documentation, -.\" and that the names of M.I.T. and the M.I.T. S.I.P.B. not be -.\" used in advertising or publicity pertaining to distribution -.\" of the software without specific, written prior permission. -.\" M.I.T. and the M.I.T. S.I.P.B. make no representations about -.\" the suitability of this software for any purpose. It is -.\" provided "as is" without express or implied warranty. -.\" -.sp -.SH NAME -newsyslog \- maintain system log files to manageable sizes -.SH SYNOPSIS -.B /usr/bin/newsyslog -[ -.B \-vnr -] [ -.B \-f -.I configuration file -] -.SH DESCRIPTION -.I Newsyslog -is a program that should be scheduled to run periodically by -.IR crontab . -When it is executed it archives log files if necessary. If a log file -is determined to require archiving, -.I newsyslog -rearranges the files so that ``logfile'' is empty, ``logfile.0'' has -the last period's logs in it, ``logfile.1'' has the next to last -period's logs in it, and so on, up to a user-specified number of -archived logs. Optionally the archived logs can be compressed to save -space. -.PP -A log can be archived because of two reasons. The log file can have -grown bigger than a preset size in kilobytes, or a preset number of -hours may have elapsed since the last log archive. The granularity of -.I newsyslog -is dependent on how often it is scheduled to run in crontab. Since -the program is quite fast, it may be scheduled to run every hour -without any ill effects. -.PP -When starting up, -.I newsyslog -reads in a configuration file to determine which logs should be looked -at. By default, this configuration file is -.IR /etc/newsyslog.conf . -Each line of the file contains information about a particular log file -that should be handled by -.IR newsyslog . -Each line has five mandatory fields and two optional fields, with a -whitespace separating each field. Blank lines or lines beginning with -``#'' are ignored. The fields of the configuration file are as -follows: -.br - logfile name -.br - owner.group of archives (optional) -.br - mode of logfile & archives -.br - number of archives -.br - size of archives -.br - archive interval -.br - flags (optional) -.PP -The -.I logfile name -entry is the name of the system log file to be archived. -.PP -The optional -.I owner.group -entry specifies an ownership and group for the archive file. -The "." is essential, even if the -.I owner -or -.I group -field is left blank. The -fields may be numeric, or a name which is looked up in -.I /etc/passwd -or -.IR /etc/group . -.PP -The -.I number of archives -entry specifies the number of archives to be kept besides the log file -itself. -.PP -When the size of the logfile reaches -.I size of -.IR archives , -the logfile becomes trimmed as described above. If this field is -replaced by a ``*'', then the size of the logfile is not taken into -account when determining when to trim the log file. -.PP -The -.I number of hours -entry specifies the time separation between the trimming of the log -file. If this field is replaced by a ``*'', then the number of hours -since the last time the log was trimmed will not be taken into -consideration. -.PP -The -.I flags -field specifies if the archives should have any special processing -done to the archived log files. The ``Z'' flag will make the archive -files compressed to save space using /usr/bin/gzip. The ``B'' flag -means that the file is a binary file, and so the ascii message which -.I newsyslog -inserts to indicate the fact that the logs have been turned over -should not be included. -.PP -.SH OPTIONS -The following options can be used with newsyslog: -.TP -.B \-f \fIconfig-file -instructs newsyslog to use -.I config-file -instead of /etc/newsyslog.conf for its configuration file. -.TP -.B \-v -places -.I newsyslog -in verbose mode. In this mode it will print out each log and its -reasons for either trimming that log or skipping it. -.TP -.B \-n -causes -.I newsyslog -not to trim the logs, but to print out what it would do if this option -were not specified. -.TP -.B \-r -removes the restriction that -.I newsyslog -must be running as root. Of course, -.I newsyslog -will not be able to send a HUP signal to -.IR syslogd , -so this option should only be used in debugging. -.SH FILES -/etc/newsyslog.conf -.SH BUGS -Doesn't yet automatically read the logs to find security breaches. - - -.SH AUTHOR -Theodore Ts'o, MIT Project Athena -.br -Copyright 1987, Massachusetts Institute of Technology -.SH "SEE ALSO" -syslogd(8), syslog(3), gzip(1) -.ns -.sp diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c deleted file mode 100644 index ba21b6ee84e6..000000000000 --- a/usr.sbin/newsyslog/newsyslog.c +++ /dev/null @@ -1,568 +0,0 @@ -/* - * This file contains changes from the Open Software Foundation. - */ - -/* - -Copyright 1988, 1989 by the Massachusetts Institute of Technology - -Permission to use, copy, modify, and distribute this software -and its documentation for any purpose and without fee is -hereby granted, provided that the above copyright notice -appear in all copies and that both that copyright notice and -this permission notice appear in supporting documentation, -and that the names of M.I.T. and the M.I.T. S.I.P.B. not be -used in advertising or publicity pertaining to distribution -of the software without specific, written prior permission. -M.I.T. and the M.I.T. S.I.P.B. make no representations about -the suitability of this software for any purpose. It is -provided "as is" without express or implied warranty. - -*/ - -/* - * newsyslog - roll over selected logs at the appropriate time, - * keeping the a specified number of backup files around. - * - * $Source: /a/cvsroot/src/usr.bin/newsyslog/newsyslog.c,v $ - * $Author: jtc $ - */ - -#ifndef lint -static char rcsid[] = "$Id: newsyslog.c,v 1.9 1995/01/21 21:53:46 jtc Exp $"; -#endif /* not lint */ - -#ifndef CONF -#define CONF "/etc/athena/newsyslog.conf" /* Configuration file */ -#endif -#ifndef PIDFILE -#define PIDFILE "/etc/syslog.pid" -#endif -#ifndef COMPRESS -#define COMPRESS "/usr/ucb/compress" /* File compression program */ -#endif -#ifndef COMPRESS_POSTFIX -#define COMPRESS_POSTFIX ".Z" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <signal.h> -#include <pwd.h> -#include <grp.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/stat.h> -#include <sys/param.h> -#include <sys/wait.h> - -#define kbytes(size) (((size) + 1023) >> 10) -#ifdef _IBMR2 -/* Calculates (db * DEV_BSIZE) */ -#define dbtob(db) ((unsigned)(db) << UBSHIFT) -#endif - -#define CE_COMPACT 1 /* Compact the achived log files */ -#define CE_BINARY 2 /* Logfile is in binary, don't add */ - /* status messages */ -#define NONE -1 - -struct conf_entry { - char *log; /* Name of the log */ - int uid; /* Owner of log */ - int gid; /* Group of log */ - int numlogs; /* Number of logs to keep */ - int size; /* Size cutoff to trigger trimming the log */ - int hours; /* Hours between log trimming */ - int permissions; /* File permissions on the log */ - int flags; /* Flags (CE_COMPACT & CE_BINARY) */ - struct conf_entry *next; /* Linked list pointer */ -}; - -extern int optind; -extern char *optarg; -extern char *malloc(); -extern uid_t getuid(),geteuid(); -extern time_t time(); - -char *progname; /* contains argv[0] */ -int verbose = 0; /* Print out what's going on */ -int needroot = 1; /* Root privs are necessary */ -int noaction = 0; /* Don't do anything, just show it */ -char *conf = CONF; /* Configuration file to use */ -time_t timenow; -int syslog_pid; /* read in from /etc/syslog.pid */ -#define MIN_PID 3 -#define MAX_PID 65534 -char hostname[64]; /* hostname */ -char *daytime; /* timenow in human readable form */ - - -struct conf_entry *parse_file(); -char *sob(), *son(), *strdup(), *missing_field(); - -main(argc,argv) - int argc; - char **argv; -{ - struct conf_entry *p, *q; - - PRS(argc,argv); - if (needroot && getuid() && geteuid()) { - fprintf(stderr,"%s: must have root privs\n",progname); - exit(1); - } - p = q = parse_file(); - while (p) { - do_entry(p); - p=p->next; - free((char *) q); - q=p; - } - exit(0); -} - -do_entry(ent) - struct conf_entry *ent; - -{ - int size, modtime; - - if (verbose) { - if (ent->flags & CE_COMPACT) - printf("%s <%dZ>: ",ent->log,ent->numlogs); - else - printf("%s <%d>: ",ent->log,ent->numlogs); - } - size = sizefile(ent->log); - modtime = age_old_log(ent->log); - if (size < 0) { - if (verbose) - printf("does not exist.\n"); - } else { - if (verbose && (ent->size > 0)) - printf("size (Kb): %d [%d] ", size, ent->size); - if (verbose && (ent->hours > 0)) - printf(" age (hr): %d [%d] ", modtime, ent->hours); - if (((ent->size > 0) && (size >= ent->size)) || - ((ent->hours > 0) && ((modtime >= ent->hours) - || (modtime < 0)))) { - if (verbose) - printf("--> trimming log....\n"); - if (noaction && !verbose) { - if (ent->flags & CE_COMPACT) - printf("%s <%dZ>: trimming", - ent->log,ent->numlogs); - else - printf("%s <%d>: trimming", - ent->log,ent->numlogs); - } - dotrim(ent->log, ent->numlogs, ent->flags, - ent->permissions, ent->uid, ent->gid); - } else { - if (verbose) - printf("--> skipping\n"); - } - } -} - -PRS(argc,argv) - int argc; - char **argv; -{ - int c; - FILE *f; - char line[BUFSIZ]; - char *p; - - progname = argv[0]; - timenow = time((time_t *) 0); - daytime = ctime(&timenow) + 4; - daytime[16] = '\0'; - - /* Let's find the pid of syslogd */ - syslog_pid = 0; - f = fopen(PIDFILE,"r"); - if (f && fgets(line,BUFSIZ,f)) - syslog_pid = atoi(line); - if (f) - (void)fclose(f); - - /* Let's get our hostname */ - (void) gethostname(hostname, sizeof(hostname)); - - /* Truncate domain */ - if (p = strchr(hostname, '.')) { - *p = '\0'; - } - - optind = 1; /* Start options parsing */ - while ((c=getopt(argc,argv,"nrvf:t:")) != EOF) - switch (c) { - case 'n': - noaction++; /* This implies needroot as off */ - /* fall through */ - case 'r': - needroot = 0; - break; - case 'v': - verbose++; - break; - case 'f': - conf = optarg; - break; - default: - usage(); - } - } - -usage() -{ - fprintf(stderr, - "Usage: %s <-nrv> <-f config-file>\n", progname); - exit(1); -} - -/* Parse a configuration file and return a linked list of all the logs - * to process - */ -struct conf_entry *parse_file() -{ - FILE *f; - char line[BUFSIZ], *parse, *q; - char *errline, *group; - struct conf_entry *first = NULL; - struct conf_entry *working; - struct passwd *pass; - struct group *grp; - - if (strcmp(conf,"-")) - f = fopen(conf,"r"); - else - f = stdin; - if (!f) { - (void) fprintf(stderr,"%s: ",progname); - perror(conf); - exit(1); - } - while (fgets(line,BUFSIZ,f)) { - if ((line[0]== '\n') || (line[0] == '#')) - continue; - errline = strdup(line); - if (!first) { - working = (struct conf_entry *) malloc(sizeof(struct conf_entry)); - first = working; - } else { - working->next = (struct conf_entry *) malloc(sizeof(struct conf_entry)); - working = working->next; - } - - q = parse = missing_field(sob(line),errline); - *(parse = son(line)) = '\0'; - working->log = strdup(q); - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - if ((group = strchr(q, '.')) != NULL) { - *group++ = '\0'; - if (*q) { - if (!(isnumber(*q))) { - if ((pass = getpwnam(q)) == NULL) { - fprintf(stderr, - "Error in config file; unknown user:\n"); - fputs(errline,stderr); - exit(1); - } - working->uid = pass->pw_uid; - } else - working->uid = atoi(q); - } else - working->uid = NONE; - - q = group; - if (*q) { - if (!(isnumber(*q))) { - if ((grp = getgrnam(q)) == NULL) { - fprintf(stderr, - "Error in config file; unknown group:\n"); - fputs(errline,stderr); - exit(1); - } - working->gid = grp->gr_gid; - } else - working->gid = atoi(q); - } else - working->gid = NONE; - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - } - else - working->uid = working->gid = NONE; - - if (!sscanf(q,"%o",&working->permissions)) { - fprintf(stderr, - "Error in config file; bad permissions:\n"); - fputs(errline,stderr); - exit(1); - } - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - if (!sscanf(q,"%d",&working->numlogs)) { - fprintf(stderr, - "Error in config file; bad number:\n"); - fputs(errline,stderr); - exit(1); - } - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - if (isdigit(*q)) - working->size = atoi(q); - else - working->size = -1; - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - if (isdigit(*q)) - working->hours = atoi(q); - else - working->hours = -1; - - q = parse = sob(++parse); /* Optional field */ - *(parse = son(parse)) = '\0'; - working->flags = 0; - while (q && *q && !isspace(*q)) { - if ((*q == 'Z') || (*q == 'z')) - working->flags |= CE_COMPACT; - else if ((*q == 'B') || (*q == 'b')) - working->flags |= CE_BINARY; - else { - fprintf(stderr, - "Illegal flag in config file -- %c\n", - *q); - exit(1); - } - q++; - } - - free(errline); - } - if (working) - working->next = (struct conf_entry *) NULL; - (void) fclose(f); - return(first); -} - -char *missing_field(p,errline) - char *p,*errline; -{ - if (!p || !*p) { - fprintf(stderr,"Missing field in config file:\n"); - fputs(errline,stderr); - exit(1); - } - return(p); -} - -dotrim(log,numdays,flags,perm,owner_uid,group_gid) - char *log; - int numdays; - int flags; - int perm; - int owner_uid; - int group_gid; -{ - char file1[128], file2[128]; - char zfile1[128], zfile2[128]; - int fd; - struct stat st; - -#ifdef _IBMR2 -/* AIX 3.1 has a broken fchown- if the owner_uid is -1, it will actually */ -/* change it to be owned by uid -1, instead of leaving it as is, as it is */ -/* supposed to. */ - if (owner_uid == -1) - owner_uid = geteuid(); -#endif - - /* Remove oldest log */ - (void) sprintf(file1,"%s.%d",log,numdays); - (void) strcpy(zfile1, file1); - (void) strcat(zfile1, COMPRESS_POSTFIX); - - if (noaction) { - printf("rm -f %s\n", file1); - printf("rm -f %s\n", zfile1); - } else { - (void) unlink(file1); - (void) unlink(zfile1); - } - - /* Move down log files */ - while (numdays--) { - (void) strcpy(file2,file1); - (void) sprintf(file1,"%s.%d",log,numdays); - (void) strcpy(zfile1, file1); - (void) strcpy(zfile2, file2); - if (lstat(file1, &st)) { - (void) strcat(zfile1, COMPRESS_POSTFIX); - (void) strcat(zfile2, COMPRESS_POSTFIX); - if (lstat(zfile1, &st)) continue; - } - if (noaction) { - printf("mv %s %s\n",zfile1,zfile2); - printf("chmod %o %s\n", perm, zfile2); - printf("chown %d.%d %s\n", - owner_uid, group_gid, zfile2); - } else { - (void) rename(zfile1, zfile2); - (void) chmod(zfile2, perm); - (void) chown(zfile2, owner_uid, group_gid); - } - } - if (!noaction && !(flags & CE_BINARY)) - (void) log_trim(log); /* Report the trimming to the old log */ - - if (noaction) - printf("mv %s to %s\n",log,file1); - else - (void) rename(log,file1); - if (noaction) - printf("Start new log..."); - else { - fd = creat(log,perm); - if (fd < 0) { - perror("can't start new log"); - exit(1); - } - if (fchown(fd, owner_uid, group_gid)) { - perror("can't chmod new log file"); - exit(1); - } - (void) close(fd); - if (!(flags & CE_BINARY)) - if (log_trim(log)) { /* Add status message */ - perror("can't add status message to log"); - exit(1); - } - } - if (noaction) - printf("chmod %o %s...",perm,log); - else - (void) chmod(log,perm); - if (noaction) - printf("kill -HUP %d (syslogd)\n",syslog_pid); - else - if (syslog_pid < MIN_PID || syslog_pid > MAX_PID) { - fprintf(stderr,"%s: preposterous process number: %d\n", - progname, syslog_pid); - } else if (kill(syslog_pid,SIGHUP)) { - fprintf(stderr,"%s: ",progname); - perror("warning - could not restart syslogd"); - } - if (flags & CE_COMPACT) { - if (noaction) - printf("Compress %s.0\n",log); - else - compress_log(log); - } -} - -/* Log the fact that the logs were turned over */ -log_trim(log) - char *log; -{ - FILE *f; - if ((f = fopen(log,"a")) == NULL) - return(-1); - fprintf(f,"%s %s newsyslog[%d]: logfile turned over\n", - daytime, hostname, getpid()); - if (fclose(f) == EOF) { - perror("log_trim: fclose:"); - exit(1); - } - return(0); -} - -/* Fork of /usr/ucb/compress to compress the old log file */ -compress_log(log) - char *log; -{ - int pid; - char tmp[128]; - - pid = fork(); - (void) sprintf(tmp,"%s.0",log); - if (pid < 0) { - fprintf(stderr,"%s: ",progname); - perror("fork"); - exit(1); - } else if (!pid) { - (void) execl(COMPRESS,"compress","-f",tmp,0); - fprintf(stderr,"%s: ",progname); - perror(COMPRESS); - exit(1); - } -} - -/* Return size in kilobytes of a file */ -int sizefile(file) - char *file; -{ - struct stat sb; - - if (stat(file,&sb) < 0) - return(-1); - return(kbytes(dbtob(sb.st_blocks))); -} - -/* Return the age of old log file (file.0) */ -int age_old_log(file) - char *file; -{ - struct stat sb; - char tmp[MAXPATHLEN+3]; - - (void) strcpy(tmp,file); - if (stat(strcat(tmp,".0"),&sb) < 0) - if (stat(strcat(tmp,COMPRESS_POSTFIX), &sb) < 0) - return(-1); - return( (int) (timenow - sb.st_mtime + 1800) / 3600); -} - - -#ifndef OSF -/* Duplicate a string using malloc */ - -char *strdup(strp) -register char *strp; -{ - register char *cp; - - if ((cp = malloc((unsigned) strlen(strp) + 1)) == NULL) - abort(); - return(strcpy (cp, strp)); -} -#endif - -/* Skip Over Blanks */ -char *sob(p) - register char *p; -{ - while (p && *p && isspace(*p)) - p++; - return(p); -} - -/* Skip Over Non-Blanks */ -char *son(p) - register char *p; -{ - while (p && *p && !isspace(*p)) - p++; - return(p); -} diff --git a/usr.sbin/quot/Makefile b/usr.sbin/quot/Makefile deleted file mode 100644 index aca581b820d3..000000000000 --- a/usr.sbin/quot/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $Id: Makefile,v 1.3 1994/12/22 11:39:03 cgd Exp $ - -PROG= quot -MAN= quot.8 - -.include <bsd.prog.mk> diff --git a/usr.sbin/quot/quot.8 b/usr.sbin/quot/quot.8 deleted file mode 100644 index 7b964d944c33..000000000000 --- a/usr.sbin/quot/quot.8 +++ /dev/null @@ -1,96 +0,0 @@ -.\" Copyright (C) 1994 Wolfgang Solfrank. -.\" Copyright (C) 1994 TooLs GmbH. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by TooLs GmbH. -.\" 4. The name of TooLs GmbH may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $Id: quot.8,v 1.3 1994/03/19 07:59:47 cgd Exp $ -.\" -.Dd February 8, 1994 -.Dt QUOT 8 -.Os BSD 4 -.Sh NAME -.Nm quot -.Nd display disk space occupied by each user -.Sh SYNOPSIS -.Nm quot -.Op Fl acfhknv -.Op Ar filesystem ... -.Sh DESCRIPTION -.Nm Quot -is used to gather statistics about the disk usage for each local user. -.Pp -The following options are available: -.Bl -tag -width Ds -.It Fl a -Include statistics for all mounted filesystems. -.It Fl c -Display three columns containing number of blocks per file, -number of files in this category, and aggregate total of -blocks in files with this or lower size. -.It Fl f -For each user, display count of files and space occupied. -.It Fl h -Estimate the number of blocks in each file based on its size. -Despite that this doesn't give the correct resuls (it doesn't -account for the holes in files), this option isn't any faster -and thus is discouraged. -.It Fl k -By default, all sizes are reported in 512-byte block counts. -The -.Fl k -options causes the numbers to be reported in kilobyte counts. -.It Fl n -Given a list of inodes (plus some optional data on each line) -in the standard input, for each file print out the owner (plus -the remainder of the input line). This is traditionally used -in the pipe: -.Bd -literal -offset indent -ncheck filesystem | sort +0n | quot -n filesystem -.Ed -.Pp -to get a report of files and their owners. -.It Fl v -In addition to the default output, display the number of files -not accessed within 30, 60 and 90 days. -.El -.Sh ENVIRONMENTAL VARIABLES -.Bl -tag -width BLOCKSIZE -.It Ev BLOCKSIZE -If the environmental variable -.Ev BLOCKSIZE -is set, and the -.Gl k -option is not specified, the block counts will be displayed in units of that -size block. -.El -.\".Sh BUGS -.Sh SEE ALSO -.Xr df 1 , -.Xr quota 1 , -.Xr getmntinfo 3 , -.Xr fstab 5 , -.Xr mount 8 , diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c deleted file mode 100644 index e5f2daad68c7..000000000000 --- a/usr.sbin/quot/quot.c +++ /dev/null @@ -1,583 +0,0 @@ -/* - * Copyright (C) 1991, 1994 Wolfgang Solfrank. - * Copyright (C) 1991, 1994 TooLs GmbH. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef lint -static char rcsid[] = "$Id: quot.c,v 1.6.4.1 1995/11/01 00:06:41 jtc Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/time.h> -#include <ufs/ffs/fs.h> -#include <ufs/ufs/quota.h> -#include <ufs/ufs/inode.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <pwd.h> - -/* some flags of what to do: */ -static char estimate; -static char count; -static char unused; -static int (*func)(); -static long blocksize; -static char *header; -static int headerlen; - -/* - * Original BSD quot doesn't round to number of frags/blocks, - * doesn't account for indirection blocks and gets it totally - * wrong if the size is a multiple of the blocksize. - * The new code always counts the number of 512 byte blocks - * instead of the number of kilobytes and converts them to - * kByte when done (on request). - */ -#ifdef COMPAT -#define SIZE(n) (n) -#else -#define SIZE(n) (((n) * 512 + blocksize - 1)/blocksize) -#endif - -#define INOCNT(fs) ((fs)->fs_ipg) -#define INOSZ(fs) (sizeof(struct dinode) * INOCNT(fs)) - -static struct dinode *get_inode(fd,super,ino) - struct fs *super; - ino_t ino; -{ - static struct dinode *ip; - static ino_t last; - - if (fd < 0) { /* flush cache */ - if (ip) { - free(ip); - ip = 0; - } - return 0; - } - - if (!ip || ino < last || ino >= last + INOCNT(super)) { - if (!ip - && !(ip = (struct dinode *)malloc(INOSZ(super)))) { - perror("allocate inodes"); - exit(1); - } - last = (ino / INOCNT(super)) * INOCNT(super); - if (lseek(fd,ino_to_fsba(super,last) << super->fs_fshift,0) < 0 - || read(fd,ip,INOSZ(super)) != INOSZ(super)) { - perror("read inodes"); - exit(1); - } - } - - return ip + ino % INOCNT(super); -} - -#ifdef COMPAT -#define actualblocks(super,ip) ((ip)->di_blocks/2) -#else -#define actualblocks(super,ip) ((ip)->di_blocks) -#endif - -static virtualblocks(super,ip) - struct fs *super; - struct dinode *ip; -{ - register off_t nblk, sz; - - sz = ip->di_size; -#ifdef COMPAT - if (lblkno(super,sz) >= NDADDR) { - nblk = blkroundup(super,sz); - if (sz == nblk) - nblk += super->fs_bsize; - } - - return sz / 1024; - -#else /* COMPAT */ - - if (lblkno(super,sz) >= NDADDR) { - nblk = blkroundup(super,sz); - sz = lblkno(super,nblk); - sz = (sz - NDADDR + NINDIR(super) - 1) / NINDIR(super); - while (sz > 0) { - nblk += sz * super->fs_bsize; - /* sz - 1 rounded up */ - sz = (sz - 1 + NINDIR(super) - 1) / NINDIR(super); - } - } else - nblk = fragroundup(super,sz); - - return nblk / 512; -#endif /* COMPAT */ -} - -static isfree(ip) - struct dinode *ip; -{ -#ifdef COMPAT - return (ip->di_mode&IFMT) == 0; -#else /* COMPAT */ - - switch (ip->di_mode&IFMT) { - case IFIFO: - case IFLNK: /* should check FASTSYMLINK? */ - case IFDIR: - case IFREG: - return 0; - default: - return 1; - } -#endif -} - -static struct user { - uid_t uid; - char *name; - daddr_t space; - long count; - daddr_t spc30; - daddr_t spc60; - daddr_t spc90; -} *users; -static int nusers; - -static inituser() -{ - register i; - register struct user *usr; - - if (!nusers) { - nusers = 8; - if (!(users = - (struct user *)calloc(nusers,sizeof(struct user)))) { - perror("allocate users"); - exit(1); - } - } else { - for (usr = users, i = nusers; --i >= 0; usr++) { - usr->space = usr->spc30 = usr->spc60 = usr->spc90 = 0; - usr->count = 0; - } - } -} - -static usrrehash() -{ - register i; - register struct user *usr, *usrn; - struct user *svusr; - - svusr = users; - nusers <<= 1; - if (!(users = (struct user *)calloc(nusers,sizeof(struct user)))) { - perror("allocate users"); - exit(1); - } - for (usr = svusr, i = nusers >> 1; --i >= 0; usr++) { - for (usrn = users + (usr->uid&(nusers - 1)); usrn->name; - usrn--) { - if (usrn <= users) - usrn = users + nusers; - } - *usrn = *usr; - } -} - -static struct user *user(uid) - uid_t uid; -{ - register struct user *usr; - register i; - struct passwd *pwd; - - while (1) { - for (usr = users + (uid&(nusers - 1)), i = nusers; --i >= 0; - usr--) { - if (!usr->name) { - usr->uid = uid; - - if (!(pwd = getpwuid(uid))) { - if (usr->name = (char *)malloc(7)) - sprintf(usr->name,"#%d",uid); - } else { - if (usr->name = (char *) - malloc(strlen(pwd->pw_name) + 1)) - strcpy(usr->name,pwd->pw_name); - } - if (!usr->name) { - perror("allocate users"); - exit(1); - } - - return usr; - - } else if (usr->uid == uid) - return usr; - - if (usr <= users) - usr = users + nusers; - } - usrrehash(); - } -} - -static cmpusers(u1,u2) - struct user *u1, *u2; -{ - return u2->space - u1->space; -} - -#define sortusers(users) (qsort((users),nusers,sizeof(struct user), \ - cmpusers)) - -static uses(uid,blks,act) - uid_t uid; - daddr_t blks; - time_t act; -{ - static time_t today; - register struct user *usr; - - if (!today) - time(&today); - - usr = user(uid); - usr->count++; - usr->space += blks; - - if (today - act > 90L * 24L * 60L * 60L) - usr->spc90 += blks; - if (today - act > 60L * 24L * 60L * 60L) - usr->spc60 += blks; - if (today - act > 30L * 24L * 60L * 60L) - usr->spc30 += blks; -} - -#ifdef COMPAT -#define FSZCNT 500 -#else -#define FSZCNT 512 -#endif -struct fsizes { - struct fsizes *fsz_next; - daddr_t fsz_first, fsz_last; - ino_t fsz_count[FSZCNT]; - daddr_t fsz_sz[FSZCNT]; -} *fsizes; - -static initfsizes() -{ - register struct fsizes *fp; - register i; - - for (fp = fsizes; fp; fp = fp->fsz_next) { - for (i = FSZCNT; --i >= 0;) { - fp->fsz_count[i] = 0; - fp->fsz_sz[i] = 0; - } - } -} - -static dofsizes(fd,super,name) - struct fs *super; - char *name; -{ - ino_t inode, maxino; - struct dinode *ip; - daddr_t sz, ksz; - struct fsizes *fp, **fsp; - register i; - - maxino = super->fs_ncg * super->fs_ipg - 1; -#ifdef COMPAT - if (!(fsizes = (struct fsizes *)malloc(sizeof(struct fsizes)))) { - perror("alloc fsize structure"); - exit(1); - } -#endif /* COMPAT */ - for (inode = 0; inode < maxino; inode++) { - errno = 0; - if ((ip = get_inode(fd,super,inode)) -#ifdef COMPAT - && ((ip->di_mode&IFMT) == IFREG - || (ip->di_mode&IFMT) == IFDIR) -#else /* COMPAT */ - && !isfree(ip) -#endif /* COMPAT */ - ) { - sz = estimate ? virtualblocks(super,ip) : - actualblocks(super,ip); -#ifdef COMPAT - if (sz >= FSZCNT) { - fsizes->fsz_count[FSZCNT-1]++; - fsizes->fsz_sz[FSZCNT-1] += sz; - } else { - fsizes->fsz_count[sz]++; - fsizes->fsz_sz[sz] += sz; - } -#else /* COMPAT */ - ksz = SIZE(sz); - for (fsp = &fsizes; fp = *fsp; fsp = &fp->fsz_next) { - if (ksz < fp->fsz_last) - break; - } - if (!fp || ksz < fp->fsz_first) { - if (!(fp = (struct fsizes *) - malloc(sizeof(struct fsizes)))) { - perror("alloc fsize structure"); - exit(1); - } - fp->fsz_next = *fsp; - *fsp = fp; - fp->fsz_first = (ksz / FSZCNT) * FSZCNT; - fp->fsz_last = fp->fsz_first + FSZCNT; - for (i = FSZCNT; --i >= 0;) { - fp->fsz_count[i] = 0; - fp->fsz_sz[i] = 0; - } - } - fp->fsz_count[ksz % FSZCNT]++; - fp->fsz_sz[ksz % FSZCNT] += sz; -#endif /* COMPAT */ - } else if (errno) { - perror(name); - exit(1); - } - } - sz = 0; - for (fp = fsizes; fp; fp = fp->fsz_next) { - for (i = 0; i < FSZCNT; i++) { - if (fp->fsz_count[i]) - printf("%d\t%d\t%d\n",fp->fsz_first + i, - fp->fsz_count[i], - SIZE(sz += fp->fsz_sz[i])); - } - } -} - -static douser(fd,super,name) - struct fs *super; - char *name; -{ - ino_t inode, maxino; - struct user *usr, *usrs; - struct dinode *ip; - register n; - - maxino = super->fs_ncg * super->fs_ipg - 1; - for (inode = 0; inode < maxino; inode++) { - errno = 0; - if ((ip = get_inode(fd,super,inode)) - && !isfree(ip)) - uses(ip->di_uid, - estimate ? virtualblocks(super,ip) : - actualblocks(super,ip), - ip->di_atime); - else if (errno) { - perror(name); - exit(1); - } - } - if (!(usrs = (struct user *)malloc(nusers * sizeof(struct user)))) { - perror("allocate users"); - exit(1); - } - bcopy(users,usrs,nusers * sizeof(struct user)); - sortusers(usrs); - for (usr = usrs, n = nusers; --n >= 0 && usr->count; usr++) { - printf("%5d",SIZE(usr->space)); - if (count) - printf("\t%5d",usr->count); - printf("\t%-8s",usr->name); - if (unused) - printf("\t%5d\t%5d\t%5d", - SIZE(usr->spc30), - SIZE(usr->spc60), - SIZE(usr->spc90)); - printf("\n"); - } - free(usrs); -} - -static donames(fd,super,name) - struct fs *super; - char *name; -{ - int c; - ino_t inode, inode1; - ino_t maxino; - struct dinode *ip; - - maxino = super->fs_ncg * super->fs_ipg - 1; - /* first skip the name of the filesystem */ - while ((c = getchar()) != EOF && (c < '0' || c > '9')) - while ((c = getchar()) != EOF && c != '\n'); - ungetc(c,stdin); - inode1 = -1; - while (scanf("%d",&inode) == 1) { - if (inode < 0 || inode > maxino) { - fprintf(stderr,"illegal inode %d\n",inode); - return; - } - errno = 0; - if ((ip = get_inode(fd,super,inode)) - && !isfree(ip)) { - printf("%s\t",user(ip->di_uid)->name); - /* now skip whitespace */ - while ((c = getchar()) == ' ' || c == '\t'); - /* and print out the remainder of the input line */ - while (c != EOF && c != '\n') { - putchar(c); - c = getchar(); - } - putchar('\n'); - inode1 = inode; - } else { - if (errno) { - perror(name); - exit(1); - } - /* skip this line */ - while ((c = getchar()) != EOF && c != '\n'); - } - if (c == EOF) - break; - } -} - -static usage() -{ -#ifdef COMPAT - fprintf(stderr,"Usage: quot [-nfcvha] [filesystem ...]\n"); -#else /* COMPAT */ - fprintf(stderr,"Usage: quot [ -acfhknv ] [ filesystem ... ]\n"); -#endif /* COMPAT */ - exit(1); -} - -static char superblock[SBSIZE]; - -quot(name,mp) - char *name, *mp; -{ - int fd; - - get_inode(-1); /* flush cache */ - inituser(); - initfsizes(); - if ((fd = open(name,0)) < 0 - || lseek(fd,SBOFF,0) != SBOFF - || read(fd,superblock,SBSIZE) != SBSIZE) { - perror(name); - close(fd); - return; - } - if (((struct fs *)superblock)->fs_magic != FS_MAGIC) { - fprintf(stderr,"%s: not a BSD filesystem\n",name); - close(fd); - return; - } - printf("%s:",name); - if (mp) - printf(" (%s)",mp); - putchar('\n'); - (*func)(fd,superblock,name); - close(fd); -} - -int main(argc,argv) - char **argv; -{ - int fd; - char all = 0; - FILE *fp; - struct statfs *mp; - char dev[MNAMELEN + 1]; - char *nm; - int cnt; - - func = douser; -#ifndef COMPAT - header = getbsize(&headerlen,&blocksize); -#endif - while (--argc > 0 && **++argv == '-') { - while (*++*argv) { - switch (**argv) { - case 'n': - func = donames; - break; - case 'c': - func = dofsizes; - break; - case 'a': - all = 1; - break; - case 'f': - count = 1; - break; - case 'h': - estimate = 1; - break; -#ifndef COMPAT - case 'k': - blocksize = 1024; - break; -#endif /* COMPAT */ - case 'v': - unused = 1; - break; - default: - usage(); - } - } - } - if (all) { - cnt = getmntinfo(&mp,MNT_NOWAIT); - for (; --cnt >= 0; mp++) { - if (!strncmp(mp->f_fstypename, MOUNT_FFS, MFSNAMELEN)) { - if (nm = strrchr(mp->f_mntfromname,'/')) { - sprintf(dev,"/dev/r%s",nm + 1); - nm = dev; - } else - nm = mp->f_mntfromname; - quot(nm,mp->f_mntonname); - } - } - } - while (--argc >= 0) - quot(*argv++,0); - return 0; -} diff --git a/usr.sbin/sa/Makefile b/usr.sbin/sa/Makefile deleted file mode 100644 index ee412a6e6c7d..000000000000 --- a/usr.sbin/sa/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $Id: Makefile,v 1.1 1994/03/24 18:41:48 cgd Exp $ - -PROG= sa -MAN8= sa.0 -SRCS= main.c pdb.c usrdb.c - -.include <bsd.prog.mk> diff --git a/usr.sbin/sa/extern.h b/usr.sbin/sa/extern.h deleted file mode 100644 index 6d5291458d9d..000000000000 --- a/usr.sbin/sa/extern.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $Id: extern.h,v 1.1 1994/03/24 18:41:50 cgd Exp $ - */ - -#include <sys/types.h> -#include <sys/param.h> -#include <db.h> - -/* structures */ - -struct cmdinfo { - char ci_comm[MAXCOMLEN+2]; /* command name (+ '*') */ - u_long ci_uid; /* user id */ - u_quad_t ci_calls; /* number of calls */ - u_quad_t ci_etime; /* elapsed time */ - u_quad_t ci_utime; /* user time */ - u_quad_t ci_stime; /* system time */ - u_quad_t ci_mem; /* memory use */ - u_quad_t ci_io; /* number of disk i/o ops */ - u_int ci_flags; /* flags; see below */ -}; -#define CI_UNPRINTABLE 0x0001 /* unprintable chars in name */ - -struct userinfo { - u_long ui_uid; /* user id; for consistency */ - u_quad_t ui_calls; /* number of invocations */ - u_quad_t ui_utime; /* user time */ - u_quad_t ui_stime; /* system time */ - u_quad_t ui_mem; /* memory use */ - u_quad_t ui_io; /* number of disk i/o ops */ -}; - -/* typedefs */ - -typedef int (*cmpf_t) __P((const DBT *, const DBT *)); - -/* external functions in sa.c */ -int main __P((int, char **)); - -/* external functions in pdb.c */ -int pacct_init __P((void)); -void pacct_destroy __P((void)); -int pacct_add __P((const struct cmdinfo *)); -int pacct_update __P((void)); -void pacct_print __P((void)); - -/* external functions in usrdb.c */ -int usracct_init __P((void)); -void usracct_destroy __P((void)); -int usracct_add __P((const struct cmdinfo *)); -int usracct_update __P((void)); -void usracct_print __P((void)); - -/* variables */ - -extern int aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag; -extern int Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag; -extern int cutoff; -extern cmpf_t sa_cmp; - -/* some #defines to help with db's stupidity */ - -#define DB_CLOSE(db) \ - ((*(db)->close)(db)) -#define DB_GET(db, key, data, flags) \ - ((*(db)->get)((db), (key), (data), (flags))) -#define DB_PUT(db, key, data, flags) \ - ((*(db)->put)((db), (key), (data), (flags))) -#define DB_SYNC(db, flags) \ - ((*(db)->sync)((db), (flags))) -#define DB_SEQ(db, key, data, flags) \ - ((*(db)->seq)((db), (key), (data), (flags))) diff --git a/usr.sbin/sa/main.c b/usr.sbin/sa/main.c deleted file mode 100644 index dac27240c4f5..000000000000 --- a/usr.sbin/sa/main.c +++ /dev/null @@ -1,542 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef LINT -static char copright[] = -"@(#) Copyright (c) 1994 Christopher G. Demetriou\n\ - All rights reserved.\n"; - -static char rcsid[] = "$Id: main.c,v 1.1 1994/03/24 18:41:51 cgd Exp $"; -#endif - -/* - * sa: system accounting - */ - -#include <sys/types.h> -#include <sys/acct.h> -#include <ctype.h> -#include <err.h> -#include <fcntl.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include "extern.h" -#include "pathnames.h" - -static int acct_load __P((char *, int)); -static u_quad_t decode_comp_t __P((comp_t)); -static int cmp_comm __P((const char *, const char *)); -static int cmp_usrsys __P((const DBT *, const DBT *)); -static int cmp_avgusrsys __P((const DBT *, const DBT *)); -static int cmp_dkio __P((const DBT *, const DBT *)); -static int cmp_avgdkio __P((const DBT *, const DBT *)); -static int cmp_cpumem __P((const DBT *, const DBT *)); -static int cmp_avgcpumem __P((const DBT *, const DBT *)); -static int cmp_calls __P((const DBT *, const DBT *)); - -int aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag; -int Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag; -int cutoff = 1; - -static char *dfltargv[] = { _PATH_ACCT }; -static int dfltargc = (sizeof dfltargv/sizeof(char *)); - -/* default to comparing by sum of user + system time */ -cmpf_t sa_cmp = cmp_usrsys; - -int -main(argc, argv) - int argc; - char **argv; -{ - char ch; - int error; - - while ((ch = getopt(argc, argv, "abcdDfijkKlmnqrstuv:")) != -1) - switch (ch) { - case 'a': - /* print all commands */ - aflag = 1; - break; - case 'b': - /* sort by per-call user/system time average */ - bflag = 1; - sa_cmp = cmp_avgusrsys; - break; - case 'c': - /* print percentage total time */ - cflag = 1; - break; - case 'd': - /* sort by averge number of disk I/O ops */ - dflag = 1; - sa_cmp = cmp_avgdkio; - break; - case 'D': - /* print and sort by total disk I/O ops */ - Dflag = 1; - sa_cmp = cmp_dkio; - break; - case 'f': - /* force no interactive threshold comprison */ - fflag = 1; - break; - case 'i': - /* do not read in summary file */ - iflag = 1; - break; - case 'j': - /* instead of total minutes, give sec/call */ - jflag = 1; - break; - case 'k': - /* sort by cpu-time average memory usage */ - kflag = 1; - sa_cmp = cmp_avgcpumem; - break; - case 'K': - /* print and sort by cpu-storage integral */ - sa_cmp = cmp_cpumem; - Kflag = 1; - break; - case 'l': - /* seperate system and user time */ - lflag = 1; - break; - case 'm': - /* print procs and time per-user */ - mflag = 1; - break; - case 'n': - /* sort by number of calls */ - sa_cmp = cmp_calls; - break; - case 'q': - /* quiet; error messages only */ - qflag = 1; - break; - case 'r': - /* reverse order of sort */ - rflag = 1; - break; - case 's': - /* merge accounting file into summaries */ - sflag = 1; - break; - case 't': - /* report ratio of user and system times */ - tflag = 1; - break; - case 'u': - /* first, print uid and command name */ - uflag = 1; - break; - case 'v': - /* cull junk */ - vflag = 1; - cutoff = atoi(optarg); - break; - case '?': - default: - (void)fprintf(stderr, - "usage: sa [-abcdDfijkKlmnqrstu] [-v cutoff] [file ...]\n"); - exit(1); - } - - argc -= optind; - argv += optind; - - /* various argument checking */ - if (fflag && !vflag) - errx(1, "only one of -f requires -v"); - if (fflag && aflag) - errx(1, "only one of -a and -v may be specified"); - /* XXX need more argument checking */ - - if (!uflag) { - /* initialize tables */ - if ((sflag || (!mflag && !qflag)) && pacct_init() != 0) - errx(1, "process accounting initialization failed"); - if ((sflag || (mflag && !qflag)) && usracct_init() != 0) - errx(1, "user accounting initialization failed"); - } - - if (argc == 0) { - argc = dfltargc; - argv = dfltargv; - } - - /* for each file specified */ - for (; argc > 0; argc--, argv++) { - int fd; - - /* - * load the accounting data from the file. - * if it fails, go on to the next file. - */ - fd = acct_load(argv[0], sflag); - if (fd < 0) - continue; - - if (!uflag && sflag) { -#ifndef DEBUG - sigset_t nmask, omask; - int unmask = 1; - - /* - * block most signals so we aren't interrupted during - * the update. - */ - if (sigfillset(&nmask) == -1) { - warn("sigfillset"); - unmask = 0; - error = 1; - } - if (unmask && - (sigprocmask(SIG_BLOCK, &nmask, &omask) == -1)) { - warn("couldn't set signal mask "); - unmask = 0; - error = 1; - } -#endif /* DEBUG */ - - /* - * truncate the accounting data file ASAP, to avoid - * losing data. don't worry about errors in updating - * the saved stats; better to underbill than overbill, - * but we want every accounting record intact. - */ - if (ftruncate(fd, 0) == -1) { - warn("couldn't truncate %s", argv); - error = 1; - } - - /* - * update saved user and process accounting data. - * note errors for later. - */ - if (pacct_update() != 0 || usracct_update() != 0) - error = 1; - -#ifndef DEBUG - /* - * restore signals - */ - if (unmask && - (sigprocmask(SIG_SETMASK, &omask, NULL) == -1)) { - warn("couldn't restore signal mask"); - error = 1; - } -#endif /* DEBUG */ - } - - /* - * close the opened accounting file - */ - if (close(fd) == -1) { - warn("close %s", argv); - error = 1; - } - } - - if (!uflag && !qflag) { - /* print any results we may have obtained. */ - if (!mflag) - pacct_print(); - else - usracct_print(); - } - - if (!uflag) { - /* finally, deallocate databases */ - if (sflag || (!mflag && !qflag)) - pacct_destroy(); - if (sflag || (mflag && !qflag)) - usracct_destroy(); - } - - exit(error); -} - -static int -acct_load(pn, wr) - char *pn; - int wr; -{ - struct acct ac; - struct cmdinfo ci; - ssize_t rv; - int fd, i; - - /* - * open the file - */ - fd = open(pn, wr ? O_RDWR : O_RDONLY, 0); - if (fd == -1) { - warn("open %s %s", pn, wr ? "for read/write" : "read-only"); - return (-1); - } - - /* - * read all we can; don't stat and open because more processes - * could exit, and we'd miss them - */ - while (1) { - /* get one accounting entry and punt if there's an error */ - rv = read(fd, &ac, sizeof(struct acct)); - if (rv == -1) - warn("error reading %s", pn); - else if (rv > 0 && rv < sizeof(struct acct)) - warnx("short read of accounting data in %s", pn); - if (rv != sizeof(struct acct)) - break; - - /* decode it */ - ci.ci_calls = 1; - for (i = 0; i < sizeof ac.ac_comm && ac.ac_comm[i] != '\0'; - i++) { - char c = ac.ac_comm[i]; - - if (!isascii(c) || iscntrl(c)) { - ci.ci_comm[i] = '?'; - ci.ci_flags |= CI_UNPRINTABLE; - } else - ci.ci_comm[i] = c; - } - if (ac.ac_flag & AFORK) - ci.ci_comm[i++] = '*'; - ci.ci_comm[i++] = '\0'; - ci.ci_etime = decode_comp_t(ac.ac_etime); - ci.ci_utime = decode_comp_t(ac.ac_utime); - ci.ci_stime = decode_comp_t(ac.ac_stime); - ci.ci_uid = ac.ac_uid; - ci.ci_mem = ac.ac_mem; - ci.ci_io = decode_comp_t(ac.ac_io) / AHZ; - - if (!uflag) { - /* and enter it into the usracct and pacct databases */ - if (sflag || (!mflag && !qflag)) - pacct_add(&ci); - if (sflag || (mflag && !qflag)) - usracct_add(&ci); - } else if (!qflag) - printf("%6u %12.2lf cpu %12quk mem %12qu io %s\n", - ci.ci_uid, - (ci.ci_utime + ci.ci_stime) / (double) AHZ, - ci.ci_mem, ci.ci_io, ci.ci_comm); - } - - /* finally, return the file descriptor for possible truncation */ - return (fd); -} - -static u_quad_t -decode_comp_t(comp) - comp_t comp; -{ - u_quad_t rv; - - /* - * for more info on the comp_t format, see: - * /usr/src/sys/kern/kern_acct.c - * /usr/src/sys/sys/acct.h - * /usr/src/usr.bin/lastcomm/lastcomm.c - */ - rv = comp & 0x1fff; /* 13 bit fraction */ - comp >>= 13; /* 3 bit base-8 exponent */ - while (comp--) - rv <<= 3; - - return (rv); -} - -/* sort commands, doing the right thing in terms of reversals */ -static int -cmp_comm(s1, s2) - const char *s1, *s2; -{ - int rv; - - rv = strcmp(s1, s2); - if (rv == 0) - rv = -1; - return (rflag ? rv : -rv); -} - -/* sort by total user and system time */ -static int -cmp_usrsys(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - u_quad_t t1, t2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - t1 = c1->ci_utime + c1->ci_stime; - t2 = c2->ci_utime + c2->ci_stime; - - if (t1 < t2) - return -1; - else if (t1 == t2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by average user and system time */ -static int -cmp_avgusrsys(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - double t1, t2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - t1 = c1->ci_utime + c1->ci_stime; - t1 /= (double) (c1->ci_calls ? c1->ci_calls : 1); - - t2 = c2->ci_utime + c2->ci_stime; - t2 /= (double) (c2->ci_calls ? c2->ci_calls : 1); - - if (t1 < t2) - return -1; - else if (t1 == t2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by total number of disk I/O operations */ -static int -cmp_dkio(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - if (c1->ci_io < c2->ci_io) - return -1; - else if (c1->ci_io == c2->ci_io) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by average number of disk I/O operations */ -static int -cmp_avgdkio(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - double n1, n2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - n1 = (double) c1->ci_io / (double) (c1->ci_calls ? c1->ci_calls : 1); - n2 = (double) c2->ci_io / (double) (c2->ci_calls ? c2->ci_calls : 1); - - if (n1 < n2) - return -1; - else if (n1 == n2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by the cpu-storage integral */ -static int -cmp_cpumem(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - if (c1->ci_mem < c2->ci_mem) - return -1; - else if (c1->ci_mem == c2->ci_mem) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by the cpu-time average memory usage */ -static int -cmp_avgcpumem(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - u_quad_t t1, t2; - double n1, n2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - t1 = c1->ci_utime + c1->ci_stime; - t2 = c2->ci_utime + c2->ci_stime; - - n1 = (double) c1->ci_mem / (double) (t1 ? t1 : 1); - n2 = (double) c2->ci_mem / (double) (t2 ? t2 : 1); - - if (n1 < n2) - return -1; - else if (n1 == n2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by the number of invocations */ -static int -cmp_calls(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - if (c1->ci_calls < c2->ci_calls) - return -1; - else if (c1->ci_calls == c2->ci_calls) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} diff --git a/usr.sbin/sa/pathnames.h b/usr.sbin/sa/pathnames.h deleted file mode 100644 index 31721c25fcd2..000000000000 --- a/usr.sbin/sa/pathnames.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $Id: pathnames.h,v 1.1 1994/03/24 18:41:53 cgd Exp $ - */ - -#define _PATH_ACCT "/var/account/acct" -#define _PATH_SAVACCT "/var/account/savacct" -#define _PATH_USRACCT "/var/account/usracct" diff --git a/usr.sbin/sa/pdb.c b/usr.sbin/sa/pdb.c deleted file mode 100644 index 083f9daa87da..000000000000 --- a/usr.sbin/sa/pdb.c +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef LINT -static char rcsid[] = "$Id: pdb.c,v 1.1 1994/03/24 18:41:54 cgd Exp $"; -#endif - -#include <sys/types.h> -#include <sys/acct.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include "extern.h" -#include "pathnames.h" - -static int check_junk __P((struct cmdinfo *)); -static void add_ci __P((const struct cmdinfo *, struct cmdinfo *)); -static void print_ci __P((const struct cmdinfo *, const struct cmdinfo *)); - -static DB *pacct_db; - -int -pacct_init() -{ - DB *saved_pacct_db; - int error; - - pacct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL); - if (pacct_db == NULL) - return (-1); - - error = 0; - if (!iflag) { - DBT key, data; - int serr, nerr; - - saved_pacct_db = dbopen(_PATH_SAVACCT, O_RDONLY, 0, DB_BTREE, - NULL); - if (saved_pacct_db == NULL) { - error = errno == ENOENT ? 0 : -1; - if (error) - warn("retrieving process accounting summary"); - goto out; - } - - serr = DB_SEQ(saved_pacct_db, &key, &data, R_FIRST); - if (serr < 0) { - warn("retrieving process accounting summary"); - error = -1; - goto closeout; - } - while (serr == 0) { - nerr = DB_PUT(pacct_db, &key, &data, 0); - if (nerr < 0) { - warn("initializing process accounting stats"); - error = -1; - break; - } - - serr = DB_SEQ(saved_pacct_db, &key, &data, R_NEXT); - if (serr < 0) { - warn("retrieving process accounting summary"); - error = -1; - break; - } - } - -closeout: if (DB_CLOSE(saved_pacct_db) < 0) { - warn("closing process accounting summary"); - error = -1; - } - } - -out: if (error != 0) - pacct_destroy(); - return (error); -} - -void -pacct_destroy() -{ - if (DB_CLOSE(pacct_db) < 0) - warn("destroying process accounting stats"); -} - -int -pacct_add(ci) - const struct cmdinfo *ci; -{ - DBT key, data; - struct cmdinfo newci; - char keydata[sizeof ci->ci_comm]; - int rv; - - bcopy(ci->ci_comm, &keydata, sizeof keydata); - key.data = &keydata; - key.size = strlen(keydata); - - rv = DB_GET(pacct_db, &key, &data, 0); - if (rv < 0) { - warn("get key %s from process accounting stats", ci->ci_comm); - return (-1); - } else if (rv == 0) { /* it's there; copy whole thing */ - /* XXX compare size if paranoid */ - /* add the old data to the new data */ - bcopy(data.data, &newci, data.size); - } else { /* it's not there; zero it and copy the key */ - bzero(&newci, sizeof newci); - bcopy(key.data, newci.ci_comm, key.size); - } - - add_ci(ci, &newci); - - data.data = &newci; - data.size = sizeof newci; - rv = DB_PUT(pacct_db, &key, &data, 0); - if (rv < 0) { - warn("add key %s to process accounting stats", ci->ci_comm); - return (-1); - } else if (rv == 1) { - warnx("duplicate key %s in process accounting stats", - ci->ci_comm); - return (-1); - } - - return (0); -} - -int -pacct_update() -{ - DB *saved_pacct_db; - DBT key, data; - int error, serr, nerr; - - saved_pacct_db = dbopen(_PATH_SAVACCT, O_RDWR|O_CREAT|O_TRUNC, 0644, - DB_BTREE, NULL); - if (saved_pacct_db == NULL) { - warn("creating process accounting summary"); - return (-1); - } - - error = 0; - - serr = DB_SEQ(pacct_db, &key, &data, R_FIRST); - if (serr < 0) { - warn("retrieving process accounting stats"); - error = -1; - } - while (serr == 0) { - nerr = DB_PUT(saved_pacct_db, &key, &data, 0); - if (nerr < 0) { - warn("saving process accounting summary"); - error = -1; - break; - } - - serr = DB_SEQ(pacct_db, &key, &data, R_NEXT); - if (serr < 0) { - warn("retrieving process accounting stats"); - error = -1; - break; - } - } - - if (DB_SYNC(saved_pacct_db, 0) < 0) { - warn("syncing process accounting summary"); - error = -1; - } - if (DB_CLOSE(saved_pacct_db) < 0) { - warn("closing process accounting summary"); - error = -1; - } - return error; -} - -void -pacct_print() -{ - BTREEINFO bti; - DBT key, data, ndata; - DB *output_pacct_db; - struct cmdinfo *cip, ci, ci_total, ci_other, ci_junk; - int rv; - - bzero(&ci_total, sizeof ci_total); - strcpy(ci_total.ci_comm, ""); - bzero(&ci_other, sizeof ci_other); - strcpy(ci_other.ci_comm, "***other"); - bzero(&ci_junk, sizeof ci_junk); - strcpy(ci_junk.ci_comm, "**junk**"); - - /* - * Retrieve them into new DB, sorted by appropriate key. - * At the same time, cull 'other' and 'junk' - */ - bzero(&bti, sizeof bti); - bti.compare = sa_cmp; - output_pacct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, &bti); - if (output_pacct_db == NULL) { - warn("couldn't sort process accounting stats"); - return; - } - - ndata.data = NULL; - ndata.size = 0; - rv = DB_SEQ(pacct_db, &key, &data, R_FIRST); - if (rv < 0) - warn("retrieving process accounting stats"); - while (rv == 0) { - cip = (struct cmdinfo *) data.data; - bcopy(cip, &ci, sizeof ci); - - /* add to total */ - add_ci(&ci, &ci_total); - - if (vflag && ci.ci_calls <= cutoff && - (fflag || check_junk(&ci))) { - /* put it into **junk** */ - add_ci(&ci, &ci_junk); - goto next; - } - if (!aflag && - ((ci.ci_flags & CI_UNPRINTABLE) != 0 || ci.ci_calls <= 1)) { - /* put into ***other */ - add_ci(&ci, &ci_other); - goto next; - } - rv = DB_PUT(output_pacct_db, &data, &ndata, 0); - if (rv < 0) - warn("sorting process accounting stats"); - -next: rv = DB_SEQ(pacct_db, &key, &data, R_NEXT); - if (rv < 0) - warn("retrieving process accounting stats"); - } - - /* insert **junk** and ***other */ - if (ci_junk.ci_calls != 0) { - data.data = &ci_junk; - data.size = sizeof ci_junk; - rv = DB_PUT(output_pacct_db, &data, &ndata, 0); - if (rv < 0) - warn("sorting process accounting stats"); - } - if (ci_other.ci_calls != 0) { - data.data = &ci_other; - data.size = sizeof ci_other; - rv = DB_PUT(output_pacct_db, &data, &ndata, 0); - if (rv < 0) - warn("sorting process accounting stats"); - } - - /* print out the total */ - print_ci(&ci_total, &ci_total); - - /* print out; if reversed, print first (smallest) first */ - rv = DB_SEQ(output_pacct_db, &data, &ndata, rflag ? R_FIRST : R_LAST); - if (rv < 0) - warn("retrieving process accounting report"); - while (rv == 0) { - cip = (struct cmdinfo *) data.data; - bcopy(cip, &ci, sizeof ci); - - print_ci(&ci, &ci_total); - - rv = DB_SEQ(output_pacct_db, &data, &ndata, - rflag ? R_NEXT : R_PREV); - if (rv < 0) - warn("retrieving process accounting report"); - } - DB_CLOSE(output_pacct_db); -} - -static int -check_junk(cip) - struct cmdinfo *cip; -{ - char *cp; - size_t len; - - fprintf(stderr, "%s (%qu) -- ", cip->ci_comm, cip->ci_calls); - cp = fgetln(stdin, &len); - - return (cp && (cp[0] == 'y' || cp[0] == 'Y')) ? 1 : 0; -} - -static void -add_ci(fromcip, tocip) - const struct cmdinfo *fromcip; - struct cmdinfo *tocip; -{ - tocip->ci_calls += fromcip->ci_calls; - tocip->ci_etime += fromcip->ci_etime; - tocip->ci_utime += fromcip->ci_utime; - tocip->ci_stime += fromcip->ci_stime; - tocip->ci_mem += fromcip->ci_mem; - tocip->ci_io += fromcip->ci_io; -} - -static void -print_ci(cip, totalcip) - const struct cmdinfo *cip, *totalcip; -{ - double t, c; - int uflow; - - c = cip->ci_calls ? cip->ci_calls : 1; - t = (cip->ci_utime + cip->ci_stime) / (double) AHZ; - if (t < 0.01) { - t = 0.01; - uflow = 1; - } else - uflow = 0; - - printf("%8qu ", cip->ci_calls); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", - cip->ci_calls / (double) totalcip->ci_calls); - else - printf(" %4s ", ""); - } - - if (jflag) - printf("%11.2fre ", cip->ci_etime / (double) (AHZ * c)); - else - printf("%11.2fre ", cip->ci_etime / (60.0 * AHZ)); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", - cip->ci_etime / (double) totalcip->ci_etime); - else - printf(" %4s ", ""); - } - - if (!lflag) { - if (jflag) - printf("%11.2fcp ", t / (double) cip->ci_calls); - else - printf("%11.2fcp ", t / 60.0); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", - (cip->ci_utime + cip->ci_stime) / (double) - (totalcip->ci_utime + totalcip->ci_stime)); - else - printf(" %4s ", ""); - } - } else { - if (jflag) - printf("%11.2fu ", cip->ci_utime / (double) (AHZ * c)); - else - printf("%11.2fu ", cip->ci_utime / (60.0 * AHZ)); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", cip->ci_utime / (double) totalcip->ci_utime); - else - printf(" %4s ", ""); - } - if (jflag) - printf("%11.2fs ", cip->ci_stime / (double) (AHZ * c)); - else - printf("%11.2fs ", cip->ci_stime / (60.0 * AHZ)); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", cip->ci_stime / (double) totalcip->ci_stime); - else - printf(" %4s ", ""); - } - } - - if (tflag) - if (!uflow) - printf("%8.2fre/cp ", cip->ci_etime / (double) (cip->ci_utime + cip->ci_stime)); - else - printf("%8 ", "*ignore*"); - - if (Dflag) - printf("%10qutio ", cip->ci_io); - else - printf("%8.0favio ", cip->ci_io / c); - - if (Kflag) - printf("%10quk*sec ", cip->ci_mem); - else - printf("%8.0fk ", cip->ci_mem / t); - - printf(" %s\n", cip->ci_comm); -} diff --git a/usr.sbin/sa/sa.8 b/usr.sbin/sa/sa.8 deleted file mode 100644 index 83ec1f4aacbf..000000000000 --- a/usr.sbin/sa/sa.8 +++ /dev/null @@ -1,246 +0,0 @@ -.\" -.\" Copyright (c) 1994 Christopher G. Demetriou -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Christopher G. Demetriou. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $Id: sa.8,v 1.1 1994/03/24 18:41:59 cgd Exp $ -.\" -.Dd February 25, 1994 -.Dt SA 8 -.Os NetBSD 0.9a -.Sh NAME -.Nm sa -.Nd print system accounting statistics -.Sh SYNOPSIS -.Nm sa -.Op Fl abcdDfijkKlmnqrstu -.Op Fl v Ar cutoff -.Op Ar -.Sh DESCRIPTION -The -.Nm sa -utility reports on, cleans up, -and generally maintains system -accounting files. -.Pp -.Nm Sa -is able to condense the the information in -.Pa /var/account/acct -into the summary files -.Pa /var/account/savacct -and -.Pa /var/account/usracct , -which contain system statistics according -to command name and login id, respectively. -This condensation is desirable because on a -large system, -.Pa /var/account/acct -can grow by hundreds of blocks per day. -The summary files are normally read before -the accounting file, so that reports include -all available information. -.Pp -If file names are supplied, they are read instead of -.Pa /var/account/account . -After each file is read, if the summary -files are being updated, an updated summary will -be saved to disk. Only one report is printed, -after the last file is processed. -.Pp -The labels used in the output indicate the following, except -where otherwise specified by individual options: -.Bl -tag -width k*sec -.It Dv avio -Average number of I/O operations per execution -.It Dv cp -Sum of user and system time, in minutes -.It Dv cpu -Same as -.Dv cp -.It Dv k -CPU-time averaged core usage, in 1k units -.It Dv k*sec -CPU storage integral, in 1k-core seconds -.It Dv re -Real time, in minutes -.It Dv s -System time, in minutes -.It Dv tio -Total number of I/O operations -.It Dv u -User time, in minutes -.El -.Pp -The options to -.Nm sa -are: -.Bl -tag -width Ds -.It Fl a -List all command names, including those containing unprintable -characters and those used only once. By default, -.Nm sa -places all names containing unprintable characters and -those used only once under the name ``***other''. -.It Fl b -If printing command statistics, sort output by the sum of user and system -time divided by number of calls. -.It Fl c -In addition to the number of calls and the user, system and real times -for each command, print their percentage of the total over all commands. -.It Fl d -If printing command statistics, sort by the average number of disk -I/O operations. If printing user statistics, print the average number of -disk I/O operations per user. -.It Fl D -If printing command statistics, sort and print by the total number -of disk I/O operations. -.It Fl f -Force no interactive threshold comparison with the -.Fl v -option. -.It Fl i -Do not read in the summary files. -.It Fl j -Instead of the total minutes per category, give seconds per call. -.It Fl k -If printing command statistics, sort by the cpu-time average memory -usage. If printing user statistics, print the cpu-time average -memory usage. -.It Fl K -If printing command statistics, print and sort by the cpu-storage integral. -.It Fl l -Separate system and user time; normally they are combined. -.It Fl m -Print per-user statistics rather than per-command statistics. -.It Fl n -Sort by number of calls. -.It Fl q -Create no output other than error messages. -.It Fl r -Reverse order of sort. -.It Fl s -Truncate the accounting files when done and merge their data -into the summary files. -.It Fl t -For each command, report the ratio of real time to the sum -of user and system cpu times. -If the cpu time is too small to report, ``*ignore*'' appears in -this field. -.It Fl u -Superseding all other flags, for each entry -in the accounting file, print the user ID, total seconds of cpu usage, -total memory usage, number of I/O operations performed, and -command name. -.It Fl v Ar cutoff -For each command used -.Ar cutoff -times or fewer, print the command name and await a reply -from the terminal. If the reply begins with ``y'', add -the command to the category ``**junk**''. This flag is -used to strip garbage from the report. -.El -.Pp -By default, per-command statistics will be printed. The number of -calls, the total elapsed time in minutes, total cpu and user time -in minutes, average number of I/O operations, and CPU-time -averaged core usage will be printed. If the -.Fl m -option is specified, per-user statistics will be printed, including -the user name, the number of commands invoked, total cpu time used -(in minutes), total number of I/O operations, and CPU storage integral -for each user. If the -.Fl u -option is specified, the uid, user and system time (in seconds), -CPU storage integral, I/O usage, and command name will be printed -for each entry in the accounting data file. -.Pp -If the -.Fl u -flag is specified, all flags other than -.Fl q -are ignored. If the -.Fl m -flag is specified, only the -.Fl b , -.Fl d , -.Fl i , -.Fl k , -.Fl q , -and -.Fl s -flags are honored. -.Pp -The -.Nm sa -utility exits 0 on success, and >0 if an error occurs. -.Sh FILES -.Bl -tag -width /var/account/usracct -compact -.It Pa /var/account/acct -raw accounting data file -.It Pa /var/account/savacct -per-command accounting summary database -.It Pa /var/account/usracct -per-user accounting summary database -.El -.Sh SEE ALSO -.Xr ac 8 , -.Xr acct 5 , -.Xr accton 8 , -.Xr lastcomm 1 -.Sh BUGS -The number of options to this program is absurd, especially considering -that there's not much logic behind their lettering. -.Pp -The field labels should be more consistent. -.Pp -NetBSD's VM system does not record the CPU storage integral. -.Sh CAVEATS -While the behavior of the options in this version of -.Nm sa -was modeled after the original version, there are some intentional -differences and undoubtedly some unintentional ones as well. In -particular, the -.Fl q -option has been added, and the -.Fl m -option now understands more options than it used to. -.Pp -The formats of the summary files created by this version of -.Nm sa -are very different than the those used by the original version. -This is not considered a problem, however, because the accounting record -format has changed as well (since user ids are now 32 bits). -.Sh HISTORY -.Nm Sa -was written for -.Nx 0.9a -from the specification provided by various systems' manual pages. -Its date of origin is unknown to the author. -.Sh AUTHOR -.Bl -tag -Chris G. Demetriou, cgd@postgres.berkeley.edu -.El diff --git a/usr.sbin/sa/usrdb.c b/usr.sbin/sa/usrdb.c deleted file mode 100644 index af7d0fdbad40..000000000000 --- a/usr.sbin/sa/usrdb.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef LINT -static char rcsid[] = "$Id: usrdb.c,v 1.1 1994/03/24 18:42:01 cgd Exp $"; -#endif - -#include <sys/types.h> -#include <sys/acct.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include "extern.h" -#include "pathnames.h" - -static int uid_compare __P((const DBT *, const DBT *)); - -static DB *usracct_db; - -int -usracct_init() -{ - DB *saved_usracct_db; - BTREEINFO bti; - int error; - - bzero(&bti, sizeof bti); - bti.compare = uid_compare; - - usracct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, &bti); - if (usracct_db == NULL) - return (-1); - - error = 0; - if (!iflag) { - DBT key, data; - int serr, nerr; - - saved_usracct_db = dbopen(_PATH_USRACCT, O_RDONLY, 0, DB_BTREE, - &bti); - if (saved_usracct_db == NULL) { - error = (errno == ENOENT) ? 0 : -1; - if (error) - warn("retrieving user accounting summary"); - goto out; - } - - serr = DB_SEQ(saved_usracct_db, &key, &data, R_FIRST); - if (serr < 0) { - warn("retrieving user accounting summary"); - error = -1; - goto closeout; - } - while (serr == 0) { - nerr = DB_PUT(usracct_db, &key, &data, 0); - if (nerr < 0) { - warn("initializing user accounting stats"); - error = -1; - break; - } - - serr = DB_SEQ(saved_usracct_db, &key, &data, R_NEXT); - if (serr < 0) { - warn("retrieving user accounting summary"); - error = -1; - break; - } - } - -closeout: - if (DB_CLOSE(saved_usracct_db) < 0) { - warn("closing user accounting summary"); - error = -1; - } - } - -out: - if (error != 0) - usracct_destroy(); - return (error); -} - -void -usracct_destroy() -{ - if (DB_CLOSE(usracct_db) < 0) - warn("destroying user accounting stats"); -} - -int -usracct_add(ci) - const struct cmdinfo *ci; -{ - DBT key, data; - struct userinfo newui; - u_long uid; - int rv; - - uid = ci->ci_uid; - key.data = &uid; - key.size = sizeof uid; - - rv = DB_GET(usracct_db, &key, &data, 0); - if (rv < 0) { - warn("get key %d from user accounting stats", uid); - return (-1); - } else if (rv == 0) { /* it's there; copy whole thing */ - /* add the old data to the new data */ - bcopy(data.data, &newui, data.size); - if (newui.ui_uid != uid) { - warnx("key %d != expected record number %d", - newui.ui_uid, uid); - warnx("inconsistent user accounting stats"); - return (-1); - } - } else { /* it's not there; zero it and copy the key */ - bzero(&newui, sizeof newui); - newui.ui_uid = ci->ci_uid; - } - - newui.ui_calls += ci->ci_calls; - newui.ui_utime += ci->ci_utime; - newui.ui_stime += ci->ci_stime; - newui.ui_mem += ci->ci_mem; - newui.ui_io += ci->ci_io; - - data.data = &newui; - data.size = sizeof newui; - rv = DB_PUT(usracct_db, &key, &data, 0); - if (rv < 0) { - warn("add key %d to user accounting stats", uid); - return (-1); - } else if (rv != 0) { - warnx("DB_PUT returned 1"); - return (-1); - } - - return (0); -} - -int -usracct_update() -{ - DB *saved_usracct_db; - DBT key, data; - BTREEINFO bti; - u_long uid; - int error, serr, nerr; - - bzero(&bti, sizeof bti); - bti.compare = uid_compare; - - saved_usracct_db = dbopen(_PATH_USRACCT, O_RDWR|O_CREAT|O_TRUNC, 0644, - DB_BTREE, &bti); - if (saved_usracct_db == NULL) { - warn("creating user accounting summary"); - return (-1); - } - - error = 0; - - serr = DB_SEQ(usracct_db, &key, &data, R_FIRST); - if (serr < 0) { - warn("retrieving user accounting stats"); - error = -1; - } - while (serr == 0) { - nerr = DB_PUT(saved_usracct_db, &key, &data, 0); - if (nerr < 0) { - warn("saving user accounting summary"); - error = -1; - break; - } - - serr = DB_SEQ(usracct_db, &key, &data, R_NEXT); - if (serr < 0) { - warn("retrieving user accounting stats"); - error = -1; - break; - } - } - - if (DB_SYNC(saved_usracct_db, 0) < 0) { - warn("syncing process accounting summary"); - error = -1; - } -out: - if (DB_CLOSE(saved_usracct_db) < 0) { - warn("closing process accounting summary"); - error = -1; - } - return error; -} - -void -usracct_print() -{ - DBT key, data; - struct userinfo *ui; - double t; - int rv; - - rv = DB_SEQ(usracct_db, &key, &data, R_FIRST); - if (rv < 0) - warn("retrieving user accounting stats"); - - while (rv == 0) { - ui = (struct userinfo *) data.data; - - printf("%-8s %9qu ", - user_from_uid(ui->ui_uid, 0), ui->ui_calls); - - t = (double) (ui->ui_utime + ui->ui_stime) / - (double) AHZ; - if (t < 0.0001) /* kill divide by zero */ - t = 0.0001; - - printf("%12.2lf%s ", t / 60.0, "cpu"); - - /* ui->ui_calls is always != 0 */ - if (dflag) - printf("%12qu%s", ui->ui_io / ui->ui_calls, "avio"); - else - printf("%12qu%s", ui->ui_io, "tio"); - - /* t is always >= 0.0001; see above */ - if (kflag) - printf("%12qu%s", ui->ui_mem / t, "k"); - else - printf("%12qu%s", ui->ui_mem, "k*sec"); - - printf("\n"); - - rv = DB_SEQ(usracct_db, &key, &data, R_NEXT); - if (rv < 0) - warn("retrieving user accounting stats"); - } -} - -static int -uid_compare(k1, k2) - const DBT *k1, *k2; -{ - u_long d1, d2; - - bcopy(k1->data, &d1, sizeof d1); - bcopy(k2->data, &d2, sizeof d2); - - if (d1 < d2) - return -1; - else if (d1 == d2) - return 0; - else - return 1; -} diff --git a/usr.sbin/spray/Makefile b/usr.sbin/spray/Makefile deleted file mode 100644 index 5ecd1c5be0e9..000000000000 --- a/usr.sbin/spray/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $Id: Makefile,v 1.2 1995/07/11 01:18:05 jtc Exp $ - -PROG= spray -MAN8= spray.8 -LDADD= -lrpcsvc - -.include <bsd.prog.mk> diff --git a/usr.sbin/spray/spray.8 b/usr.sbin/spray/spray.8 deleted file mode 100644 index a47c899ed841..000000000000 --- a/usr.sbin/spray/spray.8 +++ /dev/null @@ -1,76 +0,0 @@ -.\" -.\" Copyright (c) 1994 James A. Jegers -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd July 10, 1995 -.Dt SPRAY 8 -.Os FreeBSD -.Sh NAME -.Nm spray -.Nd send many packets to host -.Sh SYNOPSIS -.Nm spray -.Op Fl c Ar count -.Op Fl d Ar delay -.Op Fl l Ar length -.Ar host -\&... -.Ek -.Sh DESCRIPTION -.Nm Spray -sends multiple RPC packets to -.Ar host -and records how many of them were correctly received and how long it took. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl c Ar count -Send -.Ar count -packets. -.It Fl d Ar delay -Pause -.Ar delay -microseconds between sending each packet. -.It Fl l Ar length -Set the length of the packet that holds the RPC call message to -.Ar length -bytes. -Not all values of -.Ar length -are possible because RPC data is encoded using XDR. -.Nm Spray -rounds up to the nearest possible value. -.El -.Pp -.Nm Spray -is intended for use in network testing, measurement, and management. -This command -.Bf -emphasis -can be very hard on a network and should be used with caution. -.Ef -.Pp -.Sh SEE ALSO -.Xr netstat 1 , -.Xr ifconfig 8 , -.Xr ping 8 , -.Xr rpc.sprayd 8 diff --git a/usr.sbin/spray/spray.c b/usr.sbin/spray/spray.c deleted file mode 100644 index 607abc15b3fa..000000000000 --- a/usr.sbin/spray/spray.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 1993 Winning Strategies, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $Id: spray.c,v 1.3 1994/12/23 16:42:47 cgd Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include <rpc/rpc.h> -#include <rpcsvc/spray.h> - -#ifndef SPRAYOVERHEAD -#define SPRAYOVERHEAD 86 -#endif - -void usage (); -void print_xferstats (); - -/* spray buffer */ -char spray_buffer[SPRAYMAX]; - -/* RPC timeouts */ -struct timeval NO_DEFAULT = { -1, -1 }; -struct timeval ONE_WAY = { 0, 0 }; -struct timeval TIMEOUT = { 25, 0 }; - -int -main(argc, argv) - int argc; - char **argv; -{ - char *progname; - spraycumul host_stats; - sprayarr host_array; - CLIENT *cl; - int c; - int i; - int count = 0; - int delay = 0; - int length = 0; - double xmit_time; /* time to receive data */ - - progname = *argv; - while ((c = getopt(argc, argv, "c:d:l:")) != -1) { - switch (c) { - case 'c': - count = atoi(optarg); - break; - case 'd': - delay = atoi(optarg); - break; - case 'l': - length = atoi(optarg); - break; - default: - usage(); - /* NOTREACHED */ - } - } - argc -= optind; - argv += optind; - - if (argc != 1) { - usage(); - /* NOTREACHED */ - } - - - /* Correct packet length. */ - if (length > SPRAYMAX) { - length = SPRAYMAX; - } else if (length < SPRAYOVERHEAD) { - length = SPRAYOVERHEAD; - } else { - /* The RPC portion of the packet is a multiple of 32 bits. */ - length -= SPRAYOVERHEAD - 3; - length &= ~3; - length += SPRAYOVERHEAD; - } - - - /* - * The default value of count is the number of packets required - * to make the total stream size 100000 bytes. - */ - if (!count) { - count = 100000 / length; - } - - /* Initialize spray argument */ - host_array.sprayarr_len = length - SPRAYOVERHEAD; - host_array.sprayarr_val = spray_buffer; - - - /* create connection with server */ - cl = clnt_create(*argv, SPRAYPROG, SPRAYVERS, "udp"); - if (cl == NULL) { - clnt_pcreateerror(progname); - exit(1); - } - - - /* - * For some strange reason, RPC 4.0 sets the default timeout, - * thus timeouts specified in clnt_call() are always ignored. - * - * The following (undocumented) hack resets the internal state - * of the client handle. - */ - clnt_control(cl, CLSET_TIMEOUT, (caddr_t)&NO_DEFAULT); - - - /* Clear server statistics */ - if (clnt_call(cl, SPRAYPROC_CLEAR, xdr_void, NULL, xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) { - clnt_perror(cl, progname); - exit(1); - } - - - /* Spray server with packets */ - printf ("sending %d packets of lnth %d to %s ...", count, length, *argv); - fflush (stdout); - - for (i = 0; i < count; i++) { - clnt_call(cl, SPRAYPROC_SPRAY, xdr_sprayarr, &host_array, xdr_void, NULL, ONE_WAY); - - if (delay) { - usleep(delay); - } - } - - - /* Collect statistics from server */ - if (clnt_call(cl, SPRAYPROC_GET, xdr_void, NULL, xdr_spraycumul, &host_stats, TIMEOUT) != RPC_SUCCESS) { - clnt_perror(cl, progname); - exit(1); - } - - xmit_time = host_stats.clock.sec + - (host_stats.clock.usec / 1000000.0); - - printf ("\n\tin %.2f seconds elapsed time\n", xmit_time); - - - /* report dropped packets */ - if (host_stats.counter != count) { - int packets_dropped = count - host_stats.counter; - - printf("\t%d packets (%.2f%%) dropped\n", - packets_dropped, - 100.0 * packets_dropped / count ); - } else { - printf("\tno packets dropped\n"); - } - - printf("Sent:"); - print_xferstats(count, length, xmit_time); - - printf("Rcvd:"); - print_xferstats(host_stats.counter, length, xmit_time); - - exit (0); -} - - -void -print_xferstats(packets, packetlen, xfertime) - int packets; - int packetlen; - double xfertime; -{ - int datalen; - double pps; /* packets per second */ - double bps; /* bytes per second */ - - datalen = packets * packetlen; - pps = packets / xfertime; - bps = datalen / xfertime; - - printf("\t%.0f packets/sec, ", pps); - - if (bps >= 1024) - printf ("%.1fK ", bps / 1024); - else - printf ("%.0f ", bps); - - printf("bytes/sec\n"); -} - - -void -usage () -{ - fprintf(stderr, "usage: spray [-c count] [-l length] [-d delay] host\n"); - exit(1); -} |