diff options
Diffstat (limited to 'clients/zstat')
-rw-r--r-- | clients/zstat/Imakefile | 15 | ||||
-rw-r--r-- | clients/zstat/Makefile.in | 47 | ||||
-rw-r--r-- | clients/zstat/zserver.h | 4 | ||||
-rw-r--r-- | clients/zstat/zstat.c | 143 |
4 files changed, 85 insertions, 124 deletions
diff --git a/clients/zstat/Imakefile b/clients/zstat/Imakefile deleted file mode 100644 index 9ffd2ac..0000000 --- a/clients/zstat/Imakefile +++ /dev/null @@ -1,15 +0,0 @@ -/**/# Copyright 1988 Massachusetts Institute of Technology. -/**/# -/**/# For copying and distribution information, see the file -/**/# "mit-copyright.h". -/**/# -/**/# $Source$ -/**/# $Author$ -/**/# $Id$ -/**/# - -SRCS = zstat.c -OBJS = zstat.o - -zprogram(zstat,) -install_man(zstat.8,zstat.8) diff --git a/clients/zstat/Makefile.in b/clients/zstat/Makefile.in new file mode 100644 index 0000000..11b2f92 --- /dev/null +++ b/clients/zstat/Makefile.in @@ -0,0 +1,47 @@ +SHELL = /bin/sh + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +datadir=@datadir@ +confdir=@confdir@ +sbindir=@sbindir@ +lsbindir=@lsbindir@ + +includedir=${prefix}/include +mandir=${prefix}/man +libdir=${exec_prefix}/lib +bindir=${exec_prefix}/bin + +srcdir=@srcdir@ +top_srcdir=@top_srcdir@ +BUILDTOP=../.. +VPATH=@srcdir@ +CC=@CC@ +INSTALL=@INSTALL@ + +DEBUG=-O +CFLAGS=${DEBUG} -I${top_srcdir}/h -I${BUILDTOP}/h @CPPFLAGS@ +LDFLAGS=${DEBUG} -L${BUILDTOP}/lib/zephyr @ET_LDFLAGS@ @LDFLAGS@ +LIBS=-lzephyr @LIBS@ -lcom_err + +OBJS= zstat.o + +all: zstat + +zstat: ${OBJS} ${BUILDTOP}/lib/zephyr/libzephyr.a @ETDEP@ + ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LIBS} + +check: + +install: zstat + ${INSTALL} -m 755 -s zstat ${DESTDIR}${bindir} + ${INSTALL} -m 644 ${srcdir}/zstat.8 ${DESTDIR}${mandir}/man8 + +clean: + rm -f ${OBJS} zstat + +${OBJS}: zserver.h ${top_srcdir}/h/sysdep.h ${BUILDTOP}/h/config.h +${OBJS}: ${BUILDTOP}/h/zephyr/zephyr.h ${BUILDTOP}/h/zephyr/zephyr_err.h + +.PHONY: all check install clean + diff --git a/clients/zstat/zserver.h b/clients/zstat/zserver.h index 9528840..467b41f 100644 --- a/clients/zstat/zserver.h +++ b/clients/zstat/zserver.h @@ -25,8 +25,4 @@ #define ADMIN_KILL_CLT "KILL_CLIENT" /* Opcode: client is dead, remove */ #define ADMIN_STATUS "STATUS" /* Opcode: please send status */ -#define ADMIN_LIMBO "LIMBO" /* Class inst: please send limbo info*/ -#define ADMIN_YOU "YOUR_STATE" /* Class inst: please send your state*/ -#define ADMIN_ME "MY_STATE" /* Class inst: please send my info */ - #endif /* !__ZSERVER_H__ */ diff --git a/clients/zstat/zstat.c b/clients/zstat/zstat.c index 10204b4..798baf0 100644 --- a/clients/zstat/zstat.c +++ b/clients/zstat/zstat.c @@ -11,58 +11,47 @@ * "mit-copyright.h". */ -#include <zephyr/zephyr.h> -#include <sys/param.h> +/* There should be library interfaces for the operations in zstat; for now, + * however, zstat is more or less internal to the Zephyr system. */ +#include <internal.h> + #include <sys/socket.h> -#include <netdb.h> -#include <stdio.h> -#include <string.h> -#include <signal.h> /* BSD includes this from <sys/param.h>, - but AIX does not. */ #include "zserver.h" #if !defined(lint) && !defined(SABER) -static char rcsid_zstat_c[] = "$Id$"; +static const char rcsid_zstat_c[] = "$Id$"; #endif -#ifdef __STDC__ -const -#endif - char *hm_head[] = { "Current server =", - "Items in queue:", - "Client packets received:", - "Server packets received:", - "Server changes:", - "Version:", - "Looking for a new server:", - "Time running:", - "Size:", - "Machine type:" +const char *hm_head[] = { + "Current server =", + "Items in queue:", + "Client packets received:", + "Server packets received:", + "Server changes:", + "Version:", + "Looking for a new server:", + "Time running:", + "Size:", + "Machine type:" }; #define HM_SIZE (sizeof(hm_head) / sizeof (char *)) -#ifdef __STDC__ -const -#endif - char *srv_head[] = { - "Current server version =", - "Packets handled:", - "Uptime:", - "Server states:", +const char *srv_head[] = { + "Current server version =", + "Packets handled:", + "Uptime:", + "Server states:", }; #define SRV_SIZE (sizeof(srv_head) / sizeof (char *)) int outoftime = 0; -#if defined(ultrix) || defined(POSIX) -void -#endif -timeout() +RETSIGTYPE timeout() { outoftime = 1; } int serveronly = 0,hmonly = 0; -u_short hm_port,srv_port; +u_short srv_port; main(argc, argv) int argc; @@ -105,19 +94,8 @@ main(argc, argv) exit(1); } - if (!(sp = getservbyname(HM_SVCNAME,"udp"))) { - fprintf(stderr,"%s/udp: unknown service\n", HM_SVCNAME); - exit(-1); - } - - hm_port = sp->s_port; - - if (!(sp = getservbyname(SERVER_SVCNAME,"udp"))) { - fprintf(stderr,"%s/udp: unknown service\n",SERVER_SVCNAME); - exit(-1); - } - - srv_port = sp->s_port; + sp = getservbyname(SERVER_SVCNAME,"udp"); + srv_port = (sp) ? sp->s_port : SERVER_SVC_FALLBACK; if (optind == argc) { if (gethostname(hostname, MAXHOSTNAMELEN) < 0) { @@ -154,79 +132,34 @@ do_stat(host) hm_stat(host,server) char *host,*server; { + struct in_addr inaddr; + Code_t code; + char *line[20],*mp; int sock,i,nf,ret; struct hostent *hp; - struct sockaddr_in sin; - long runtime; + time_t runtime; struct tm *tim; ZNotice_t notice; -#ifdef POSIX +#ifdef _POSIX_VERSION struct sigaction sa; #endif - (void) memset((char *)&sin, 0, sizeof(struct sockaddr_in)); - - sin.sin_port = hm_port; - - if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { - perror("socket:"); - exit(-1); - } - - sin.sin_family = AF_INET; - - if ((sin.sin_addr.s_addr = inet_addr(host)) == (unsigned)(-1)) { + if ((inaddr.s_addr = inet_addr(host)) == (unsigned)(-1)) { if ((hp = gethostbyname(host)) == NULL) { fprintf(stderr,"Unknown host: %s\n",host); exit(-1); } - (void) memcpy((char *) &sin.sin_addr, hp->h_addr, hp->h_length); + (void) memcpy((char *) &inaddr, hp->h_addr, hp->h_length); printf("Hostmanager stats: %s\n", hp->h_name); } else { printf("Hostmanager stats: %s\n", host); } - (void) memset((char *)¬ice, 0, sizeof(notice)); - notice.z_kind = STAT; - notice.z_port = 0; - notice.z_class = HM_STAT_CLASS; - notice.z_class_inst = HM_STAT_CLIENT; - notice.z_opcode = HM_GIMMESTATS; - notice.z_sender = ""; - notice.z_recipient = ""; - notice.z_default_format = ""; - notice.z_message_len = 0; - - if ((ret = ZSetDestAddr(&sin)) != ZERR_NONE) { - com_err("zstat", ret, "setting destination"); - exit(-1); - } - if ((ret = ZSendNotice(¬ice, ZNOAUTH)) != ZERR_NONE) { - com_err("zstat", ret, "sending notice"); - exit(-1); - } -#ifdef POSIX - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sa.sa_handler = timeout; - (void) sigaction(SIGALRM, &sa, (struct sigaction *)0); -#else - (void) signal(SIGALRM,timeout); -#endif - outoftime = 0; - (void) alarm(10); - if (((ret = ZReceiveNotice(¬ice, (struct sockaddr_in *) 0)) - != ZERR_NONE) && - ret != EINTR) { - com_err("zstat", ret, "receiving notice"); - return (1); - } - (void) alarm(0); - if (outoftime) { - fprintf(stderr,"No response after 10 seconds.\n"); - return (1); + if ((code = ZhmStat(&inaddr, ¬ice)) != ZERR_NONE) { + com_err("zstat", ret, "getting hostmanager status"); + exit(-1); } mp = notice.z_message; @@ -268,9 +201,9 @@ srv_stat(host) struct hostent *hp; struct sockaddr_in sin; ZNotice_t notice; - long runtime; + time_t runtime; struct tm *tim; -#ifdef POSIX +#ifdef _POSIX_VERSION struct sigaction sa; #endif @@ -317,7 +250,7 @@ srv_stat(host) exit(-1); } -#ifdef POSIX +#ifdef _POSIX_VERSION sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = timeout; |