[7194] in Athena Bugs
rt 7.2R: portmap
daemon@ATHENA.MIT.EDU (daemon@ATHENA.MIT.EDU)
Wed Feb 27 09:41:24 1991
Date: Wed, 27 Feb 91 09:40:59 -0500
From: "Jonathan I. Kamens" <jik@pit-manager.MIT.EDU>
To: bugs@ATHENA.MIT.EDU
System name: pit-manager
Type and version: RTPC-ROMPC 7.2R
Display type: apa16
megapel
What were you trying to do?
Figure out why portmap keeps dying on portnoy.
What's wrong:
It sends its error messages to stderr rather than logging
them, despite the fact that this means that in most cases, no
one will see them. Furthermore, it doesn't notice malloc
failures.
What should have happened:
It should notice malloc failures and retry. It should log
errors so that it can be monitored effectively.
Please describe any relevant documentation references:
Patch below.
jik
*** /source/bsd-4.3/common/etc/portmap/portmap.c Thu Jul 16 13:11:46 1987
--- portmap.c Wed Feb 27 09:34:24 1991
***************
*** 41,46 ****
--- 41,47 ----
* Mountain View, California 94043
*/
+ #include <syslog.h>
#include <rpc/rpc.h>
#include <rpc/pmap_prot.h>
#include <stdio.h>
***************
*** 60,69 ****
struct sockaddr_in addr;
int len = sizeof(struct sockaddr_in);
#ifndef DEBUG
pid = fork();
if (pid < 0) {
! perror("portmap: fork");
exit(1);
}
if (pid != 0)
--- 61,74 ----
struct sockaddr_in addr;
int len = sizeof(struct sockaddr_in);
+ openlog("portmap", LOG_PID | LOG_CONS, LOG_DAEMON);
+
+ syslog(LOG_NOTICE, "starting");
+
#ifndef DEBUG
pid = fork();
if (pid < 0) {
! syslog(LOG_ERR, "fork: %m");
exit(1);
}
if (pid != 0)
***************
*** 80,86 ****
}
#endif
if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
! perror("portmap cannot create socket");
exit(1);
}
--- 85,91 ----
}
#endif
if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
! syslog(LOG_ERR, "socket: %m");
exit(1);
}
***************
*** 92,123 ****
addr.sin_family = AF_INET;
addr.sin_port = htons(PMAPPORT);
if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
! perror("portmap cannot bind");
exit(1);
}
if ((xprt = svcudp_create(sock)) == (SVCXPRT *)NULL) {
! fprintf(stderr, "couldn't do udp_create\n");
exit(1);
}
if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
! perror("portmap cannot create socket");
exit(1);
}
if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
! perror("portmap cannot bind");
exit(1);
}
if ((xprt = svctcp_create(sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE))
== (SVCXPRT *)NULL) {
! fprintf(stderr, "couldn't do tcp_create\n");
exit(1);
}
(void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE);
svc_run();
! fprintf(stderr, "run_svc returned unexpectedly\n");
abort();
}
--- 97,128 ----
addr.sin_family = AF_INET;
addr.sin_port = htons(PMAPPORT);
if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
! syslog(LOG_ERR, "bind: %m");
exit(1);
}
if ((xprt = svcudp_create(sock)) == (SVCXPRT *)NULL) {
! syslog(LOG_ERR, "error in svcudp_create");
exit(1);
}
if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
! syslog(LOG_ERR, "socket: %m");
exit(1);
}
if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
! syslog(LOG_ERR, "bind: %m");
exit(1);
}
if ((xprt = svctcp_create(sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE))
== (SVCXPRT *)NULL) {
! syslog(LOG_ERR, "error in svctcp_create");
exit(1);
}
(void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE);
svc_run();
! syslog(LOG_ERR, "svc_run returned unexpectedly, aborting");
abort();
}
***************
*** 164,169 ****
--- 169,175 ----
* Null proc call
*/
if ((!svc_sendreply(xprt, xdr_void, NULL)) && debugging) {
+ fprintf(stderr, "error in svc_sendreply, aborting");
abort();
}
break;
***************
*** 191,201 ****
goto done;
}
} else {
/*
* add to END of list
*/
! pml = (struct pmaplist *)
! malloc((u_int)sizeof(struct pmaplist));
pml->pml_map = reg;
pml->pml_next = 0;
if (pmaplist == 0) {
--- 197,221 ----
goto done;
}
} else {
+ int retry_count = 0;
/*
* add to END of list
*/
! do {
! retry_count++;
! pml = (struct pmaplist *)
! malloc((u_int)sizeof(struct pmaplist));
! if (! pml) {
! syslog(LOG_WARNING,
! "null return from malloc, sleeping");
! sleep(15);
! }
! } while ((! pml) && (retry_count < 40));
! if (! pml) {
! syslog(LOG_ERR,
! "couldn't malloc and retry count exceeded, aborting");
! abort();
! }
pml->pml_map = reg;
pml->pml_next = 0;
if (pmaplist == 0) {