diff options
author | John Kohl <jtkohl@mit.edu> | 1987-07-14 14:18:54 +0000 |
---|---|---|
committer | John Kohl <jtkohl@mit.edu> | 1987-07-14 14:18:54 +0000 |
commit | 65dfa2f94c5599960dbd1f8de9efc84f187eb2fa (patch) | |
tree | 2197eab485a3bb1f7968c1a13f2cad7acbcc7065 /server/bdump.c | |
parent | 8190c9e5e869d122eb0da874e440e99819ce2696 (diff) |
lint cleanup, and function order rearrangement (all globals at front)
Diffstat (limited to 'server/bdump.c')
-rw-r--r-- | server/bdump.c | 237 |
1 files changed, 89 insertions, 148 deletions
diff --git a/server/bdump.c b/server/bdump.c index 01b2eb3..6d4a9e5 100644 --- a/server/bdump.c +++ b/server/bdump.c @@ -25,8 +25,7 @@ static char rcsid_brain_dump_c[] = "$Header$"; static void close_bdump(), bdump_ask_for(), bdump_recv_loop(); static void bdump_send_loop(), gbd_loop(), sbd_loop(); static void send_host_register(), send_subs(), send_done(), send_locations(); -static void send_normal(), send_list(); -static void send_normal_tcp(); +static void send_list(), send_normal_tcp(); static Code_t get_packet(), extract_sin(); static timer bdump_timer; @@ -66,10 +65,6 @@ void offer_brain_dump(who) struct sockaddr_in *who; { - ZNotice_t notice; - register ZNotice_t *pnotice; /* speed hack */ - ZPacket_t pack; - int packlen; Code_t retval; char buf[512], *addr, *lyst[2]; @@ -103,7 +98,7 @@ struct sockaddr_in *who; addr = inet_ntoa(bdump_sin.sin_addr); - sprintf(buf, "%d", ntohs(bdump_sin.sin_port)); + (void) sprintf(buf, "%d", ntohs(bdump_sin.sin_port)); lyst[0] = addr; lyst[1] = buf; @@ -120,20 +115,6 @@ struct sockaddr_in *who; return; } - -#ifdef DEBUG -static char *bdpktypes[] = { - "UNSAFE", - "UNACKED", - "ACKED", - "HMACK", - "HMCTL", - "SERVACK", - "SERVNAK", - "CLIENTACK" -}; -#endif DEBUG - /* * Accept a connection, and send the brain dump to the other server */ @@ -142,7 +123,7 @@ void send_brain_dump() { int sock; - struct sockaddr_in from, bogusfrom; + struct sockaddr_in from; ZServerDesc_t *server; int fromlen = sizeof(from); @@ -175,8 +156,8 @@ send_brain_dump() /* mutually authenticate */ #endif notdef - sbd_loop(sock, &from); - gbd_loop(sock, server); + sbd_loop(&from); + gbd_loop(server); zdbug((LOG_DEBUG, "sbd finished")); if (server != limbo_server) @@ -220,25 +201,78 @@ ZServerDesc_t *server; TCP connection. This will work since recvfrom and sendto work even on TCP connections, but the sockaddr_in addresses are ignored */ - ZSetFD(sock); + (void) ZSetFD(sock); #ifdef notdef /* send the authenticator over */ /* and receive mutual authent */ #endif notdef - gbd_loop(sock, server); - sbd_loop(sock, &target); + gbd_loop(server); + sbd_loop(&target); - ZSetFD(srv_socket); + (void) ZSetFD(srv_socket); (void) close(sock); zdbug((LOG_DEBUG, "gbd done")); server->zs_state = SERV_UP; return; } +/* + * Send a list off as the specified notice + */ + +void +bdump_send_list_tcp(kind, port, class, inst, opcode, sender, recip, lyst, num) +ZNotice_Kind_t kind; +u_short port; +char *class, *inst, *opcode, *sender, *recip; +char *lyst[]; +int num; +{ + ZNotice_t notice; + register ZNotice_t *pnotice; /* speed hack */ + ZPacket_t pack; + int packlen, count; + Code_t retval; + u_short length; + + pnotice = ¬ice; + + pnotice->z_kind = kind; + + pnotice->z_port = port; + pnotice->z_class = class; + pnotice->z_class_inst = inst; + pnotice->z_opcode = opcode; + pnotice->z_sender = sender; + pnotice->z_recipient = recip; + + packlen = sizeof(pack); + + if ((retval = ZFormatNoticeList(pnotice, lyst, num, pack, packlen, &packlen, ZNOAUTH)) != ZERR_NONE) { + syslog(LOG_WARNING, "sl format: %s", error_message(retval)); + return; + } + + length = htons((u_short) packlen); + + if ((count = write(ZGetFD(), (caddr_t) &length, sizeof(length))) != sizeof(length)) { + if (count < 0) + syslog(LOG_WARNING, "slt xmit/len: %m"); + else + syslog(LOG_WARNING, "slt xmit: %d vs %d",sizeof(length),count); + } + + if ((count = write(ZGetFD(), pack, packlen)) != packlen) + if (count < 0) + syslog(LOG_WARNING, "slt xmit: %m"); + else + syslog(LOG_WARNING, "slt xmit: %d vs %d",packlen, count); + return; +} + static void -sbd_loop(sock, from) -int sock; +sbd_loop(from) struct sockaddr_in *from; { ZNotice_t bd_notice; @@ -264,7 +298,7 @@ struct sockaddr_in *from; char buf[4096]; (void) sprintf(buf, "disp:%s '%s' '%s' '%s' '%s' '%s'", - bdpktypes[(int) bd_notice.z_kind], + pktypes[(int) bd_notice.z_kind], bd_notice.z_class, bd_notice.z_class_inst, bd_notice.z_opcode, @@ -276,12 +310,12 @@ struct sockaddr_in *from; if (!strcmp(bd_notice.z_class_inst, ADMIN_LIMBO)) { /* he wants limbo */ zdbug((LOG_DEBUG, "limbo req")); - bdump_send_loop(limbo_server, sock); + bdump_send_loop(limbo_server); continue; } else if (!strcmp(bd_notice.z_class_inst, ADMIN_YOU)) { /* he wants my state */ zdbug((LOG_DEBUG, "my state req")); - bdump_send_loop(me_server,sock); + bdump_send_loop(me_server); break; } else if (!strcmp(bd_notice.z_class_inst, ADMIN_DONE)) { break; @@ -295,8 +329,7 @@ struct sockaddr_in *from; } static void -gbd_loop(sock, server) -int sock; +gbd_loop(server) ZServerDesc_t *server; { struct sockaddr_in target; @@ -305,11 +338,11 @@ ZServerDesc_t *server; ask for the other server to send us the limbo state. */ if (otherservers[limbo_server_idx()].zs_hosts->q_forw == otherservers[limbo_server_idx()].zs_hosts) { - bdump_ask_for("LIMBO", sock); + bdump_ask_for("LIMBO"); bdump_recv_loop(&otherservers[limbo_server_idx()], &target); } - bdump_ask_for("YOUR_STATE", sock); + bdump_ask_for("YOUR_STATE"); bdump_recv_loop(server, &target); } /* @@ -339,13 +372,12 @@ caddr_t arg; */ static void -bdump_ask_for(inst, fd) +bdump_ask_for(inst) char *inst; -int fd; { /* myname is the hostname */ send_normal_tcp(ACKED, bdump_sin.sin_port, ZEPHYR_ADMIN_CLASS, - inst, ADMIN_BDUMP, myname, "", NULL, 0); + inst, ADMIN_BDUMP, myname, "", (char *) NULL, 0); return; } @@ -363,7 +395,6 @@ struct sockaddr_in *target; ZPacket_t packet; int len, auth; Code_t retval; - ZHostList_t *current_host = NULLZHLT; ZClient_t *client = NULLZCNT; struct sockaddr_in current_who; int who_valid = 0; @@ -389,7 +420,7 @@ struct sockaddr_in *target; char buf[4096]; (void) sprintf(buf, "disp:%s '%s' '%s' '%s' '%s' '%s'", - bdpktypes[(int) notice.z_kind], + pktypes[(int) notice.z_kind], notice.z_class, notice.z_class_inst, notice.z_opcode, @@ -420,7 +451,7 @@ struct sockaddr_in *target; ulogin_dispatch(¬ice, 1, ¤t_who, server); } else if (!strcmp(notice.z_opcode, ADMIN_NEWCLT)) { /* register a new client */ - notice.z_port = ntohs(atoi(notice.z_message)); + notice.z_port = ntohs((u_short)atoi(notice.z_message)); if ((retval = client_register(¬ice, ¤t_who, &client, @@ -433,7 +464,7 @@ struct sockaddr_in *target; /* a C_Block is there */ cp = notice.z_message + strlen(notice.z_message) + 1; - if (ZReadAscii(cp,strlen(cp),client->zct_cblock) != ZERR_NONE) + if (ZReadAscii(cp,strlen(cp),client->zct_cblock,sizeof(C_Block)) != ZERR_NONE) bzero((caddr_t) client->zct_cblock, sizeof(C_Block)); } @@ -459,13 +490,11 @@ struct sockaddr_in *target; */ static void -bdump_send_loop(server, sock) +bdump_send_loop(server) register ZServerDesc_t *server; -int sock; { register ZHostList_t *host; register ZClientList_t *clist; - register ZSubscr_t *sub; zdbug((LOG_DEBUG, "bdump send loop")); @@ -473,7 +502,7 @@ int sock; host != server->zs_hosts; host = host->q_forw) { /* for each host */ - send_host_register(server, host, sock); + send_host_register(host); uloc_send_locations(host); if (!host->zh_clients) continue; @@ -494,16 +523,14 @@ int sock; */ static void -send_host_register(server, host, sock) -ZServerDesc_t *server; +send_host_register(host) ZHostList_t *host; -int sock; { char buf[512], *addr, *lyst[2]; zdbug((LOG_DEBUG, "bdump_host_register")); addr = inet_ntoa(host->zh_addr.sin_addr); - sprintf(buf, "%d", ntohs(host->zh_addr.sin_port)); + (void) sprintf(buf, "%d", ntohs(host->zh_addr.sin_port)); lyst[0] = addr; lyst[1] = buf; @@ -523,7 +550,7 @@ send_done() { zdbug((LOG_DEBUG, "send_done")); send_normal_tcp(SERVACK, bdump_sin.sin_port, ZEPHYR_ADMIN_CLASS, - "", ADMIN_DONE, myname, "", NULL, 0); + "", ADMIN_DONE, myname, "", (char *) NULL, 0); return; } @@ -545,7 +572,6 @@ int num; ZPacket_t pack; int packlen; Code_t retval; - u_short length; pnotice = ¬ice; @@ -571,97 +597,6 @@ int num; } /* - * Send a list off as the specified notice - */ - -void -bdump_send_list_tcp(kind, port, class, inst, opcode, sender, recip, lyst, num) -ZNotice_Kind_t kind; -u_short port; -char *class, *inst, *opcode, *sender, *recip; -char *lyst[]; -int num; -{ - ZNotice_t notice; - register ZNotice_t *pnotice; /* speed hack */ - ZPacket_t pack; - int packlen, count; - Code_t retval; - u_short length; - - pnotice = ¬ice; - - pnotice->z_kind = kind; - - pnotice->z_port = port; - pnotice->z_class = class; - pnotice->z_class_inst = inst; - pnotice->z_opcode = opcode; - pnotice->z_sender = sender; - pnotice->z_recipient = recip; - - packlen = sizeof(pack); - - if ((retval = ZFormatNoticeList(pnotice, lyst, num, pack, packlen, &packlen, ZNOAUTH)) != ZERR_NONE) { - syslog(LOG_WARNING, "sl format: %s", error_message(retval)); - return; - } - - length = htons((u_short) packlen); - - write(ZGetFD(), &length, sizeof(length)); - if ((count = write(ZGetFD(), pack, packlen)) != packlen) - if (count < 0) - syslog(LOG_WARNING, "slt xmit: %m"); - else - syslog(LOG_WARNING, "slt xmit: %d vs %d",packlen, count); - return; -} - -/* - * Send a message off as the specified notice - */ - -static void -send_normal(kind, port, class, inst, opcode, sender, recip, message, len) -ZNotice_Kind_t kind; -u_short port; -char *class, *inst, *opcode, *sender, *recip; -char *message; -int len; -{ - ZNotice_t notice; - register ZNotice_t *pnotice; /* speed hack */ - ZPacket_t pack; - int packlen; - Code_t retval; - - pnotice = ¬ice; - - pnotice->z_kind = kind; - - pnotice->z_port = port; - pnotice->z_class = class; - pnotice->z_class_inst = inst; - pnotice->z_opcode = opcode; - pnotice->z_sender = sender; - pnotice->z_recipient = recip; - pnotice->z_message = message; - pnotice->z_message_len = len; - - packlen = sizeof(pack); - - if ((retval = ZFormatNotice(pnotice, pack, packlen, &packlen, ZNOAUTH)) != ZERR_NONE) { - syslog(LOG_WARNING, "sn format: %s", error_message(retval)); - return; - } - if ((retval = ZSendPacket(pack, packlen)) != ZERR_NONE) { - syslog(LOG_WARNING, "sn xmit: %s", error_message(retval)); - return; - } -} - -/* * Send a message off as the specified notice, via TCP */ @@ -702,7 +637,13 @@ int len; length = htons((u_short) packlen); - write(ZGetFD(), &length, sizeof(length)); + if ((count = write(ZGetFD(), (caddr_t) &length, sizeof(length))) != sizeof(length)) { + if (count < 0) + syslog(LOG_WARNING, "snt xmit/len: %m"); + else + syslog(LOG_WARNING, "snt xmit: %d vs %d",sizeof(length),count); + } + if ((count = write(ZGetFD(), pack, packlen)) != packlen) if (count < 0) syslog(LOG_WARNING, "snt xmit: %m"); @@ -724,7 +665,7 @@ int *retlen; /* RETURN */ u_short length; int result; - if ((result = read(ZGetFD(), &length, sizeof(u_short))) < sizeof(short)) { + if ((result = read(ZGetFD(), (caddr_t) &length, sizeof(u_short))) < sizeof(short)) { if (result < 0) return(errno); else { @@ -736,7 +677,7 @@ int *retlen; /* RETURN */ length = ntohs(length); if (len < length) return(ZSRV_BUFSHORT); - if ((result = read(ZGetFD(), packet, length)) < length) { + if ((result = read(ZGetFD(), packet, (int) length)) < length) { if (result < 0) return(errno); else { |