bin/160295: ypserv -P [bin/109494] breaks tcp
Dylan Alex Simon
dylan at dylex.net
Tue Aug 30 16:50:11 UTC 2011
The following reply was made to PR bin/160295; it has been noted by GNATS.
From: Dylan Alex Simon <dylan at dylex.net>
To: bug-followup at FreeBSD.org
Cc:
Subject: Re: bin/160295: ypserv -P [bin/109494] breaks tcp
Date: Tue, 30 Aug 2011 12:15:19 -0400
--6TrnltStXW4iwmi0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Attached is a patch that seems to work. However, there seems to be another
bug using ypserv -d where it exits ypproc_all_2_svc at the end even though it
hasn't forked (PR #10970 collateral?), so I can't test completely. (I'm
trying to get automount maps in linux to pull from FreeBSD NIS, which still
isn't working.)
--6TrnltStXW4iwmi0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="yp_main.c.diff"
--- yp_main.c.orig 2011-08-30 11:15:33.595224119 -0400
+++ yp_main.c 2011-08-30 11:15:21.375092957 -0400
@@ -84,16 +84,6 @@
int do_dns = 0;
int resfd;
-struct socktype {
- const char *st_name;
- int st_type;
-};
-static struct socktype stlist[] = {
- { "tcp", SOCK_STREAM },
- { "udp", SOCK_DGRAM },
- { NULL, 0 }
-};
-
static
void _msgout(char* msg)
{
@@ -235,14 +225,13 @@
main(int argc, char *argv[])
{
register SVCXPRT *transp = NULL;
- int sock;
+ int sock_udp = -1, sock_tcp = -1;
int proto = 0;
struct sockaddr_in saddr;
socklen_t asize = sizeof (saddr);
int ch;
in_port_t yp_port = 0;
char *errstr;
- struct socktype *st;
while ((ch = getopt(argc, argv, "hdnp:P:")) != -1) {
switch (ch) {
@@ -282,7 +271,10 @@
if (getsockopt(0, SOL_SOCKET, SO_TYPE,
(char *)&_rpcfdtype, &ssize) == -1)
exit(1);
- sock = 0;
+ if (_rpcfdtype == SOCK_DGRAM)
+ sock_udp = 0;
+ else if (_rpcfdtype == SOCK_STREAM)
+ sock_tcp = 0;
_rpcpmstart = 1;
proto = 0;
openlog("ypserv", LOG_PID, LOG_DAEMON);
@@ -293,46 +285,49 @@
}
openlog("ypserv", LOG_PID, LOG_DAEMON);
}
- sock = RPC_ANYSOCK;
+ sock_udp = sock_tcp = RPC_ANYSOCK;
(void) pmap_unset(YPPROG, YPVERS);
(void) pmap_unset(YPPROG, 1);
}
/*
* Initialize TCP/UDP sockets.
+ * Really should only do this if !_rpcpmstart.
*/
- memset((char *)&saddr, 0, sizeof(saddr));
- saddr.sin_family = AF_INET;
- saddr.sin_addr.s_addr = htonl(INADDR_ANY);
- saddr.sin_port = htons(yp_port);
- for (st = stlist; st->st_name != NULL; st++) {
- /* Do not bind the socket if the user didn't specify a port */
- if (yp_port == 0)
- break;
+ if (yp_port)
+ {
+ memset((char *)&saddr, 0, sizeof(saddr));
+ saddr.sin_family = AF_INET;
+ saddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ saddr.sin_port = htons(yp_port);
+
+ sock_udp = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock_udp == -1) {
+ _msgout("cannot create a udp socket");
+ exit(1);
+ }
- sock = socket(AF_INET, st->st_type, 0);
- if (sock == -1) {
- if ((asprintf(&errstr, "cannot create a %s socket",
- st->st_name)) == -1)
- err(1, "unexpected failure in asprintf()");
- _msgout(errstr);
- free((void *)errstr);
+ if (bind(sock_udp, (struct sockaddr *) &saddr, sizeof(saddr))
+ == -1) {
+ _msgout("cannot bind udp socket");
exit(1);
}
- if (bind(sock, (struct sockaddr *) &saddr, sizeof(saddr))
+
+ sock_tcp = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock_tcp == -1) {
+ _msgout("cannot create a tcp socket");
+ exit(1);
+ }
+
+ if (bind(sock_tcp, (struct sockaddr *) &saddr, sizeof(saddr))
== -1) {
- if ((asprintf(&errstr, "cannot bind %s socket",
- st->st_name)) == -1)
- err(1, "unexpected failure in asprintf()");
- _msgout(errstr);
- free((void *)errstr);
+ _msgout("cannot bind tcp socket");
exit(1);
}
- errstr = NULL;
}
if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
- transp = svcudp_create(sock);
+ transp = svcudp_create(sock_udp);
if (transp == NULL) {
_msgout("cannot create udp service");
exit(1);
@@ -350,7 +345,7 @@
}
if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) {
- transp = svctcp_create(sock, 0, 0);
+ transp = svctcp_create(sock_tcp, 0, 0);
if (transp == NULL) {
_msgout("cannot create tcp service");
exit(1);
--6TrnltStXW4iwmi0--
More information about the freebsd-bugs
mailing list