From def9f9a0706a18cb1bc0f44b39d55e4e81c788ff Mon Sep 17 00:00:00 2001 From: Karl Ramm Date: Tue, 24 Aug 2010 07:08:36 +0000 Subject: stop using MAXHOSTNAMELEN in a variety of places. Also nuke-trailing-whitespace. --- clients/zctl/zctl.c | 147 ++++++++++++++-------------- clients/zshutdown_notify/zshutdown_notify.c | 13 +-- clients/zstat/zstat.c | 37 +++---- 3 files changed, 100 insertions(+), 97 deletions(-) (limited to 'clients') diff --git a/clients/zctl/zctl.c b/clients/zctl/zctl.c index 47d7628..7f420c5 100644 --- a/clients/zctl/zctl.c +++ b/clients/zctl/zctl.c @@ -7,7 +7,7 @@ * * Copyright (c) 1987,1988 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ #include @@ -15,6 +15,7 @@ #include #include #include +#include #ifndef lint static const char rcsid_zctl_c[] = "$Id$"; #endif @@ -42,7 +43,7 @@ static const char rcsid_zctl_c[] = "$Id$"; int sci_idx; char subsname[BUFSIZ]; -char ourhost[MAXHOSTNAMELEN],ourhostcanon[MAXHOSTNAMELEN]; +char ourhost[NS_MAXDNAME], ourhostcanon[NS_MAXDNAME]; extern ss_request_table zctl_cmds; @@ -76,7 +77,7 @@ main(int argc, * DISPLAY environment variable for the tty name. */ #ifndef X_DISPLAY_MISSING tty = getenv("DISPLAY"); -#endif +#endif if ((retval = ZInitLocationInfo(NULL, tty)) != ZERR_NONE) com_err(argv[0], retval, "initializing location information"); @@ -110,7 +111,7 @@ main(int argc, uname(&name); strcpy(ourhost, name.nodename); #else - if (gethostname(ourhost,MAXHOSTNAMELEN) == -1) { + if (gethostname(ourhost, sizeof(ourhost)) == -1) { com_err(argv[0],errno,"while getting host name"); exit (1); } @@ -140,12 +141,12 @@ main(int argc, fprintf (stderr, "%s: %s: %s\n", argv[0], error_message (code), ssline); exit((code != 0)); - } + } printf("ZCTL $Revision$ (Protocol %s%d.%d) - Type '?' for a list of commands.\n\n", ZVERSIONHDR, ZVERSIONMAJOR,ZVERSIONMINOR); - + ss_listen(sci_idx); exit(0); } @@ -170,7 +171,7 @@ flush_locations(int argc, char *argv[]) { int retval; - + if (argc > 1) { fprintf(stderr,"Usage: %s\n",argv[0]); return; @@ -195,7 +196,7 @@ wgc_control(int argc, fprintf(stderr,"Usage: %s\n",argv[0]); return; } - + if ((newport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while getting WindowGram port"); return; @@ -238,7 +239,7 @@ wgc_control(int argc, if ((retval = ZInitialize()) != ZERR_NONE) com_err(whoami, retval, "while reinitializing"); -} +} void hm_control(int argc, @@ -251,7 +252,7 @@ hm_control(int argc, fprintf(stderr,"Usage: %s\n",argv[0]); return; } - + (void) memset((char *)¬ice, 0, sizeof(notice)); notice.z_kind = HMCTL; notice.z_port = 0; @@ -282,7 +283,7 @@ show_var(int argc, { int i; char *value; - + if (argc < 2) { fprintf(stderr,"Usage: %s ...\n",argv[0]); return; @@ -304,7 +305,7 @@ set_var(int argc, char *argv[]) char *exp_level = NULL; char *newargv[1]; char varcat[BUFSIZ]; - + if (argc < 2) { fprintf(stderr,"Usage: %s [value]\n", argv[0]); @@ -343,7 +344,7 @@ set_var(int argc, char *argv[]) EXPOSE_NETANN); return; } - } + } if (argc == 2) retval = ZSetVariable(argv[1],""); else { @@ -351,9 +352,9 @@ set_var(int argc, char *argv[]) for (i=3;i [ ... ]\n", argv[0]); @@ -424,12 +425,12 @@ cancel_subs(int argc, if (argc != 1) { fprintf(stderr,"Usage: %s\n",argv[0]); return; - } + } if ((wgport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while finding WindowGram port"); return; - } + } if ((retval = ZCancelSubscriptions((u_short)wgport)) != ZERR_NONE) com_err(whoami, retval, "while cancelling subscriptions"); } @@ -441,27 +442,27 @@ subscribe(int argc, int retval; short wgport; ZSubscription_t sub,sub2; - + if (argc > 4 || argc < 3) { fprintf(stderr,"Usage: %s class instance [*]\n",argv[0]); return; } - + sub.zsub_class = argv[1]; sub.zsub_classinst = argv[2]; sub.zsub_recipient = (argc == 3)?ZGetSender():argv[3]; fix_macros(&sub,&sub2,1); - + if ((wgport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while finding WindowGram port"); return; - } + } retval = (*argv[0] == 's') ? ZSubscribeToSansDefaults(&sub2,1,(u_short)wgport) : ZUnsubscribeTo(&sub2,1,(u_short)wgport); - + if (retval != ZERR_NONE) com_err(whoami, retval, "while subscribing"); } @@ -497,7 +498,7 @@ sub_file(int argc, if ((wgport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while finding WindowGram port"); return; - } + } if (!strcmp(argv[0],"add")) add_file(wgport,&sub,0); @@ -531,7 +532,7 @@ add_file(short wgport, (void) sprintf(errbuf,"while opening %s for append",subsname); com_err(whoami, errno, errbuf); return; - } + } fprintf(fp,"%s%s,%s,%s\n", unsub ? "!" : "", subs->zsub_class, subs->zsub_classinst, subs->zsub_recipient); @@ -558,7 +559,7 @@ del_file(short wgport, { ZSubscription_t sub2; int retval; - + retval = purge_subs(subs, unsub ? UNSUBONLY : SUBONLY); if (retval == ERR) return; @@ -604,7 +605,7 @@ purge_subs(register ZSubscription_t *subs, (void) sprintf(errbuf,"while opening %s for read",subsname); com_err(whoami, errno, errbuf); return(ERR); - } + } (void) strcpy(backup, subsname); (void) strcat(backup, ".temp"); (void) unlink(backup); @@ -613,7 +614,7 @@ purge_subs(register ZSubscription_t *subs, com_err(whoami, errno, errbuf); (void) fclose(fp); return(ERR); - } + } for (;;) { if (!fgets(subline,sizeof subline,fp)) break; @@ -684,15 +685,15 @@ load_subs(int argc, else type = SUB; - if (type != LIST) + if (type != LIST) if ((wgport = ZGetWGPort()) == -1) { com_err(whoami, errno, "while finding WindowGram port"); return; - } + } file = (argc == 1) ? subsname : argv[1]; - + fp = fopen(file,"r"); if (fp == NULL) { @@ -700,13 +701,13 @@ load_subs(int argc, "while loading subscription file"); return; } - + #ifdef CMU_ZCTL_PUNT pind = #endif ind = unind = 0; lineno = 1; - + for (;;lineno++) { if (!fgets(subline,sizeof subline,fp)) break; @@ -727,7 +728,7 @@ load_subs(int argc, *comma = '\0'; *comma2 = '\0'; if (type == LIST) { - if (*subline == '!') + if (*subline == '!') printf("(Un-subscription) Class %s instance %s recipient %s\n", subline+1, comma+1, comma2+1); #ifdef CMU_ZCTL_PUNT @@ -780,7 +781,7 @@ load_subs(int argc, pind++; } else #endif - { + { subs[ind].zsub_class = (char *)malloc((unsigned)(strlen(subline)+1)); /* XXX check malloc return */ @@ -828,7 +829,7 @@ load_subs(int argc, free(subs[i].zsub_class); free(subs[i].zsub_classinst); free(subs[i].zsub_recipient); - } + } ind = 0; } if (unind == SUBSATONCE) { @@ -842,11 +843,11 @@ load_subs(int argc, free(unsubs[i].zsub_class); free(unsubs[i].zsub_classinst); free(unsubs[i].zsub_recipient); - } + } unind = 0; } } - + if (type != LIST) { /* even if we have no subscriptions, be sure to send an empty packet to trigger the default subscriptions */ @@ -885,12 +886,12 @@ cleanup: free(subs[i].zsub_class); free(subs[i].zsub_classinst); free(subs[i].zsub_recipient); - } + } for (i=0;i\n", punt ? "Punting" : "Unpunting", class, inst, *recip ? recip : "*"); - + memset((char *) ¬ice, 0, sizeof(ZNotice_t)); notice.z_kind = UNSAFE; notice.z_class = WG_CTL_CLASS; @@ -1134,12 +1135,12 @@ do_punt(int argc, char **argv) notice.z_port = 0; notice.z_message = msg; notice.z_message_len = strlen(class)+strlen(inst)+strlen(recip)+3; - + if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE) fprintf(stderr,"%s: while sending notice\n",whoami); - + free(msg); - + ZClosePort(); #endif return 0; @@ -1155,26 +1156,26 @@ list_punts(int argc, char **argv) u_short ourport, zwgcport; char *msg; - ourport=0; + ourport=0; retval = ZOpenPort(&ourport); if(retval != ZERR_NONE) { com_err("zctl", retval, "while opening Zephyr port."); return 1; } - + old = ZGetDestAddr(); to = old; if ((zwgcport = ZGetWGPort()) == (u_short)-1) { fprintf(stderr, "zctl: Can't find windowgram port\n"); return 1; } - + to.sin_port = (u_short) zwgcport; if ((retval = ZSetDestAddr(&to)) != ZERR_NONE) { com_err("zctl",retval,"while setting destination address"); return 1; } - + memset((char *) ¬ice, 0, sizeof(ZNotice_t)); notice.z_kind = UNSAFE; notice.z_class = WG_CTL_CLASS; @@ -1185,25 +1186,25 @@ list_punts(int argc, char **argv) notice.z_port = ourport; notice.z_message = NULL; notice.z_message_len = 0; - + if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE) com_err("zctl",retval,"while sending notice"); - + if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE) com_err("zctl",retval,"while receiving ack"); - + (void) ZFreeNotice(¬ice); - + if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE) com_err("zctl",retval,"while receiving notice"); - + notice.z_auth = ZCheckAuthentication(¬ice, &from); - + if ((retval = ZSetDestAddr(&old)) != ZERR_NONE) { com_err("zctl",retval,"while resetting destination address"); return 1; } - + msg = (char *) malloc((notice.z_message_len+1) * sizeof(char)); (void) strncpy(msg,notice.z_message, notice.z_message_len); msg[notice.z_message_len]=(char)0; @@ -1211,7 +1212,7 @@ list_punts(int argc, char **argv) (void) free(msg); (void) ZFreeNotice(¬ice); (void) ZClosePort(); - + #endif /* CMU_ZCTL_PUNT */ return 0; } diff --git a/clients/zshutdown_notify/zshutdown_notify.c b/clients/zshutdown_notify/zshutdown_notify.c index 067a813..a682abf 100644 --- a/clients/zshutdown_notify/zshutdown_notify.c +++ b/clients/zshutdown_notify/zshutdown_notify.c @@ -8,7 +8,7 @@ * * Copyright (c) 1987, 1993 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ #include @@ -17,6 +17,7 @@ #include #include +#include #ifndef lint static const char rcsid_zshutdown_notify_c[] = @@ -48,18 +49,18 @@ main(int argc, ZNotice_t notice; struct hostent *hp; int retval; - char hostname[MAXHOSTNAMELEN]; + char hostname[NS_MAXDNAME]; char msgbuff[BUFSIZ], message[Z_MAXPKTLEN], *ptr; char scratch[BUFSIZ]; char *msg[N_FIELD_CNT]; #ifdef HAVE_KRB4 char tkt_filename[MAXPATHLEN]; char rlm[REALM_SZ]; - char hn2[MAXHOSTNAMELEN]; + char hn2[NS_MAXDNAME]; char *cp; #endif - if (gethostname(hostname, MAXHOSTNAMELEN) < 0) { + if (gethostname(hostname, sizeof(hostname)) < 0) { com_err(argv[0], errno, "while finding hostname"); exit(1); } @@ -102,7 +103,7 @@ main(int argc, if ((retval = ZInitialize()) != ZERR_NONE) { com_err(argv[0], retval, "while initializing"); exit(1); - } + } ptr = message; @@ -137,6 +138,6 @@ main(int argc, if (retval != ZERR_NONE) { com_err(argv[0], retval, "while sending notice"); exit(1); - } + } return 0; } diff --git a/clients/zstat/zstat.c b/clients/zstat/zstat.c index 944c4fc..c18bb60 100644 --- a/clients/zstat/zstat.c +++ b/clients/zstat/zstat.c @@ -7,7 +7,7 @@ * * Copyright (c) 1987,1988 by the Massachusetts Institute of Technology. * For copying and distribution information, see the file - * "mit-copyright.h". + * "mit-copyright.h". */ /* There should be library interfaces for the operations in zstat; for now, @@ -17,6 +17,7 @@ #include #include #include +#include #include "zserver.h" #if !defined(lint) && !defined(SABER) @@ -36,7 +37,7 @@ const char *hm_head[] = { "Machine type:" }; #define HM_SIZE (sizeof(hm_head) / sizeof (char *)) -const char *srv_head[] = { +const char *srv_head[] = { "Current server version =", "Packets handled:", "Uptime:", @@ -65,7 +66,7 @@ main(int argc, char *argv[]) { Code_t ret; - char hostname[MAXHOSTNAMELEN]; + char hostname[NS_MAXDNAME]; int optchar; struct servent *sp; extern char *optarg; @@ -105,7 +106,7 @@ main(int argc, srv_port = (sp) ? sp->s_port : SERVER_SVC_FALLBACK; if (optind == argc) { - if (gethostname(hostname, MAXHOSTNAMELEN) < 0) { + if (gethostname(hostname, sizeof(hostname)) < 0) { com_err("zstat",errno,"while finding hostname"); exit(-1); } @@ -122,8 +123,8 @@ main(int argc, void do_stat(char *host) { - char srv_host[MAXHOSTNAMELEN]; - + char srv_host[NS_MAXDNAME]; + if (serveronly) { (void) srv_stat(host); return; @@ -149,7 +150,7 @@ hm_stat(char *host, time_t runtime; struct tm *tim; ZNotice_t notice; - + if ((inaddr.s_addr = inet_addr(host)) == (unsigned)(-1)) { if ((hp = gethostbyname(host)) == NULL) { fprintf(stderr,"Unknown host: %s\n",host); @@ -161,12 +162,12 @@ hm_stat(char *host, } else { printf("Hostmanager stats: %s\n", host); } - + if ((code = ZhmStat(&inaddr, ¬ice)) != ZERR_NONE) { com_err("zstat", code, "getting hostmanager status"); exit(-1); } - + mp = notice.z_message; for (nf=0;mp