From d93c194ca393697cd053d63ed7546d48735a6990 Mon Sep 17 00:00:00 2001 From: Kaleb Keithley Date: Mon, 17 Nov 2003 19:03:42 +0000 Subject: merge XFree86 4.3.0.1 to -CURRENT --- Xtrans.c | 457 ++++++++++------------- Xtrans.h | 123 +++---- Xtransdnet.c | 208 ++++------- Xtransint.h | 172 +++++---- Xtranslcl.c | 1165 +++++++++++++++++++++++++++++----------------------------- Xtranssock.c | 594 ++++++++++++++++-------------- Xtranstli.c | 446 ++++++++++------------ Xtransutil.c | 186 ++++++---- transport.c | 14 +- 9 files changed, 1625 insertions(+), 1740 deletions(-) diff --git a/Xtrans.c b/Xtrans.c index 3a1cacf..4ca668e 100644 --- a/Xtrans.c +++ b/Xtrans.c @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/xtrans/Xtrans.c,v 3.28 2002/11/20 23:00:36 dawes Exp $ */ /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * @@ -77,43 +78,43 @@ from The Open Group. #define TRANS_LOCAL_NAMED_INDEX 11 #define TRANS_LOCAL_ISC_INDEX 12 #define TRANS_LOCAL_SCO_INDEX 13 -#define TRANS_AMOEBA_INDEX 14 static Xtransport_table Xtransports[] = { #if defined(STREAMSCONN) - &TRANS(TLITCPFuncs), TRANS_TLI_TCP_INDEX, - &TRANS(TLIINETFuncs), TRANS_TLI_INET_INDEX, - &TRANS(TLITLIFuncs), TRANS_TLI_TLI_INDEX, + { &TRANS(TLITCPFuncs), TRANS_TLI_TCP_INDEX }, + { &TRANS(TLIINETFuncs), TRANS_TLI_INET_INDEX }, + { &TRANS(TLITLIFuncs), TRANS_TLI_TLI_INDEX }, #endif /* STREAMSCONN */ #if defined(TCPCONN) - &TRANS(SocketTCPFuncs), TRANS_SOCKET_TCP_INDEX, - &TRANS(SocketINETFuncs), TRANS_SOCKET_INET_INDEX, + { &TRANS(SocketTCPFuncs), TRANS_SOCKET_TCP_INDEX }, + { &TRANS(SocketINETFuncs), TRANS_SOCKET_INET_INDEX }, #endif /* TCPCONN */ #if defined(DNETCONN) - &TRANS(DNETFuncs), TRANS_DNET_INDEX, + { &TRANS(DNETFuncs), TRANS_DNET_INDEX }, #endif /* DNETCONN */ #if defined(UNIXCONN) #if !defined(LOCALCONN) - &TRANS(SocketLocalFuncs), TRANS_SOCKET_LOCAL_INDEX, + { &TRANS(SocketLocalFuncs), TRANS_SOCKET_LOCAL_INDEX }, #endif /* !LOCALCONN */ - &TRANS(SocketUNIXFuncs), TRANS_SOCKET_UNIX_INDEX, + { &TRANS(SocketUNIXFuncs), TRANS_SOCKET_UNIX_INDEX }, #endif /* UNIXCONN */ #if defined(LOCALCONN) - &TRANS(LocalFuncs), TRANS_LOCAL_LOCAL_INDEX, + { &TRANS(LocalFuncs), TRANS_LOCAL_LOCAL_INDEX }, #ifndef sun - &TRANS(PTSFuncs), TRANS_LOCAL_PTS_INDEX, + { &TRANS(PTSFuncs), TRANS_LOCAL_PTS_INDEX }, #endif /* sun */ - &TRANS(NAMEDFuncs), TRANS_LOCAL_NAMED_INDEX, +#ifdef SVR4 + { &TRANS(NAMEDFuncs), TRANS_LOCAL_NAMED_INDEX }, +#endif #ifndef sun - &TRANS(ISCFuncs), TRANS_LOCAL_ISC_INDEX, - &TRANS(SCOFuncs), TRANS_LOCAL_SCO_INDEX, +#ifndef SCO325 + { &TRANS(ISCFuncs), TRANS_LOCAL_ISC_INDEX }, +#endif + { &TRANS(SCOFuncs), TRANS_LOCAL_SCO_INDEX }, #endif /* sun */ #endif /* LOCALCONN */ -#if defined(AMRPCCONN) || defined(AMTCPCONN) - &TRANS(AmConnFuncs), TRANS_AMOEBA_INDEX, -#endif /* AMRPCCONN || AMTCPCONN */ }; #define NUMTRANS (sizeof(Xtransports)/sizeof(Xtransport_table)) @@ -130,45 +131,41 @@ Xtransport_table Xtransports[] = { */ void -TRANS(FreeConnInfo) (ciptr) - -XtransConnInfo ciptr; +TRANS(FreeConnInfo) (XtransConnInfo ciptr) { - PRMSG (3,"TRANS(FreeConnInfo) (%x)\n", ciptr, 0, 0); + PRMSG (3,"FreeConnInfo(%x)\n", ciptr, 0, 0); if (ciptr->addr) - free (ciptr->addr); + xfree (ciptr->addr); if (ciptr->peeraddr) - free (ciptr->peeraddr); + xfree (ciptr->peeraddr); if (ciptr->port) - free (ciptr->port); + xfree (ciptr->port); - free ((char *) ciptr); + xfree ((char *) ciptr); } #define PROTOBUFSIZE 20 static Xtransport * -TRANS(SelectTransport) (protocol) - -char *protocol; +TRANS(SelectTransport) (char *protocol) { char protobuf[PROTOBUFSIZE]; int i; - PRMSG (3,"TRANS(SelectTransport) (%s)\n", protocol, 0, 0); + PRMSG (3,"SelectTransport(%s)\n", protocol, 0, 0); /* * Force Protocol to be lowercase as a way of doing * a case insensitive match. */ - strncpy (protobuf, protocol, PROTOBUFSIZE); + strncpy (protobuf, protocol, PROTOBUFSIZE - 1); for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++) if (isupper (protobuf[i])) @@ -189,12 +186,7 @@ char *protocol; static #endif /* TEST_t */ int -TRANS(ParseAddress) (address, protocol, host, port) - -char *address; -char **protocol; -char **host; -char **port; +TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port) { /* @@ -215,11 +207,11 @@ char **port; char *_protocol, *_host, *_port; char hostnamebuf[256]; - PRMSG (3,"TRANS(ParseAddress) (%s)\n", address, 0, 0); + PRMSG (3,"ParseAddress(%s)\n", address, 0, 0); /* Copy the string so it can be changed */ - tmpptr = mybuf = (char *) malloc (strlen (address) + 1); + tmpptr = mybuf = (char *) xalloc (strlen (address) + 1); strcpy (mybuf, address); /* Parse the string to get each component */ @@ -234,7 +226,7 @@ char **port; *protocol = NULL; *host = NULL; *port = NULL; - free (tmpptr); + xfree (tmpptr); return 0; } @@ -284,7 +276,7 @@ char **port; *protocol = NULL; *host = NULL; *port = NULL; - free (tmpptr); + xfree (tmpptr); return 0; } @@ -306,8 +298,6 @@ char **port; /* Get the port */ -get_port: - _port = mybuf; #if defined(FONT_t) || defined(FS_t) @@ -330,46 +320,46 @@ get_port: * string space for them. */ - if ((*protocol = (char *) malloc(strlen (_protocol) + 1)) == NULL) + if ((*protocol = (char *) xalloc(strlen (_protocol) + 1)) == NULL) { /* Malloc failed */ *port = NULL; *host = NULL; *protocol = NULL; - free (tmpptr); + xfree (tmpptr); return 0; } else strcpy (*protocol, _protocol); - if ((*host = (char *) malloc (strlen (_host) + 1)) == NULL) + if ((*host = (char *) xalloc (strlen (_host) + 1)) == NULL) { /* Malloc failed */ *port = NULL; *host = NULL; - free (*protocol); + xfree (*protocol); *protocol = NULL; - free (tmpptr); + xfree (tmpptr); return 0; } else strcpy (*host, _host); - if ((*port = (char *) malloc (strlen (_port) + 1)) == NULL) + if ((*port = (char *) xalloc (strlen (_port) + 1)) == NULL) { /* Malloc failed */ *port = NULL; - free (*host); + xfree (*host); *host = NULL; - free (*protocol); + xfree (*protocol); *protocol = NULL; - free (tmpptr); + xfree (tmpptr); return 0; } else strcpy (*port, _port); - free (tmpptr); + xfree (tmpptr); return 1; } @@ -382,22 +372,19 @@ get_port: */ static XtransConnInfo -TRANS(Open) (type, address) - -int type; -char *address; +TRANS(Open) (int type, char *address) { char *protocol = NULL, *host = NULL, *port = NULL; XtransConnInfo ciptr = NULL; Xtransport *thistrans; - PRMSG (2,"TRANS(Open) (%d,%s)\n", type, address, 0); + PRMSG (2,"Open(%d,%s)\n", type, address, 0); #if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN)) if (TRANS(WSAStartup)()) { - PRMSG (1,"TRANS(Open): WSAStartup failed\n", 0, 0, 0); + PRMSG (1,"Open: WSAStartup failed\n", 0, 0, 0); return NULL; } #endif @@ -406,7 +393,7 @@ char *address; if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0) { - PRMSG (1,"TRANS(Open): Unable to Parse address %s\n", address, 0, 0); + PRMSG (1,"Open: Unable to Parse address %s\n", address, 0, 0); return NULL; } @@ -414,12 +401,12 @@ char *address; if ((thistrans = TRANS(SelectTransport) (protocol)) == NULL) { - PRMSG (1,"TRANS(Open): Unable to find transport for %s\n", + PRMSG (1,"Open: Unable to find transport for %s\n", protocol, 0, 0); - free (protocol); - free (host); - free (port); + xfree (protocol); + xfree (host); + xfree (port); return NULL; } @@ -448,24 +435,27 @@ char *address; #endif /* TRANS_SERVER */ break; default: - PRMSG (1,"TRANS(Open): Unknown Open type %d\n", type, 0, 0); + PRMSG (1,"Open: Unknown Open type %d\n", type, 0, 0); } if (ciptr == NULL) { - PRMSG (1,"TRANS(Open): transport open failed for %s/%s:%s\n", - protocol, host, port); - free (protocol); - free (host); - free (port); + if (!(thistrans->flags & TRANS_DISABLED)) + { + PRMSG (1,"Open: transport open failed for %s/%s:%s\n", + protocol, host, port); + } + xfree (protocol); + xfree (host); + xfree (port); return NULL; } ciptr->transptr = thistrans; ciptr->port = port; /* We need this for TRANS(Reopen) */ - free (protocol); - free (host); + xfree (protocol); + xfree (host); return ciptr; } @@ -480,12 +470,7 @@ char *address; */ static XtransConnInfo -TRANS(Reopen) (type, trans_id, fd, port) - -int type; -int trans_id; -int fd; -char *port; +TRANS(Reopen) (int type, int trans_id, int fd, char *port) { XtransConnInfo ciptr = NULL; @@ -493,7 +478,7 @@ char *port; char *save_port; int i; - PRMSG (2,"TRANS(Reopen) (%d,%d,%s)\n", trans_id, fd, port); + PRMSG (2,"Reopen(%d,%d,%s)\n", trans_id, fd, port); /* Determine the transport type */ @@ -506,15 +491,15 @@ char *port; if (thistrans == NULL) { - PRMSG (1,"TRANS(Reopen): Unable to find transport id %d\n", + PRMSG (1,"Reopen: Unable to find transport id %d\n", trans_id, 0, 0); return NULL; } - if ((save_port = (char *) malloc (strlen (port) + 1)) == NULL) + if ((save_port = (char *) xalloc (strlen (port) + 1)) == NULL) { - PRMSG (1,"TRANS(Reopen): Unable to malloc port string\n", 0, 0, 0); + PRMSG (1,"Reopen: Unable to malloc port string\n", 0, 0, 0); return NULL; } @@ -532,12 +517,12 @@ char *port; ciptr = thistrans->ReopenCLTSServer(thistrans, fd, port); break; default: - PRMSG (1,"TRANS(Reopen): Bad Open type %d\n", type, 0, 0); + PRMSG (1,"Reopen: Bad Open type %d\n", type, 0, 0); } if (ciptr == NULL) { - PRMSG (1,"TRANS(Reopen): transport open failed\n", 0, 0, 0); + PRMSG (1,"Reopen: transport open failed\n", 0, 0, 0); return NULL; } @@ -560,12 +545,10 @@ char *port; #ifdef TRANS_CLIENT XtransConnInfo -TRANS(OpenCOTSClient) (address) - -char *address; +TRANS(OpenCOTSClient) (char *address) { - PRMSG (2,"TRANS(OpenCOTSClient) (%s)\n", address, 0, 0); + PRMSG (2,"OpenCOTSClient(%s)\n", address, 0, 0); return TRANS(Open) (XTRANS_OPEN_COTS_CLIENT, address); } @@ -575,12 +558,10 @@ char *address; #ifdef TRANS_SERVER XtransConnInfo -TRANS(OpenCOTSServer) (address) - -char *address; +TRANS(OpenCOTSServer) (char *address) { - PRMSG (2,"TRANS(OpenCOTSServer) (%s)\n", address, 0, 0); + PRMSG (2,"OpenCOTSServer(%s)\n", address, 0, 0); return TRANS(Open) (XTRANS_OPEN_COTS_SERVER, address); } @@ -590,11 +571,10 @@ char *address; #ifdef TRANS_CLIENT XtransConnInfo -TRANS(OpenCLTSClient) (address) +TRANS(OpenCLTSClient) (char *address) -char *address; { - PRMSG (2,"TRANS(OpenCLTSClient) (%s)\n", address, 0, 0); + PRMSG (2,"OpenCLTSClient(%s)\n", address, 0, 0); return TRANS(Open) (XTRANS_OPEN_CLTS_CLIENT, address); } @@ -604,12 +584,10 @@ char *address; #ifdef TRANS_SERVER XtransConnInfo -TRANS(OpenCLTSServer) (address) - -char *address; +TRANS(OpenCLTSServer) (char *address) { - PRMSG (2,"TRANS(OpenCLTSServer) (%s)\n", address, 0, 0); + PRMSG (2,"OpenCLTSServer(%s)\n", address, 0, 0); return TRANS(Open) (XTRANS_OPEN_CLTS_SERVER, address); } @@ -619,37 +597,25 @@ char *address; #ifdef TRANS_REOPEN XtransConnInfo -TRANS(ReopenCOTSServer) (trans_id, fd, port) - -int trans_id; -int fd; -char *port; +TRANS(ReopenCOTSServer) (int trans_id, int fd, char *port) { - PRMSG (2,"TRANS(ReopenCOTSServer) (%d, %d, %s)\n", trans_id, fd, port); + PRMSG (2,"ReopenCOTSServer(%d, %d, %s)\n", trans_id, fd, port); return TRANS(Reopen) (XTRANS_OPEN_COTS_SERVER, trans_id, fd, port); } XtransConnInfo -TRANS(ReopenCLTSServer) (trans_id, fd, port) - -int trans_id; -int fd; -char *port; +TRANS(ReopenCLTSServer) (int trans_id, int fd, char *port) { - PRMSG (2,"TRANS(ReopenCLTSServer) (%d, %d, %s)\n", trans_id, fd, port); + PRMSG (2,"ReopenCLTSServer(%d, %d, %s)\n", trans_id, fd, port); return TRANS(Reopen) (XTRANS_OPEN_CLTS_SERVER, trans_id, fd, port); } int -TRANS(GetReopenInfo) (ciptr, trans_id, fd, port) - -XtransConnInfo ciptr; -int *trans_id; -int *fd; -char **port; +TRANS(GetReopenInfo) (XtransConnInfo ciptr, + int *trans_id, int *fd, char **port) { int i; @@ -660,7 +626,7 @@ char **port; *trans_id = Xtransports[i].transport_id; *fd = ciptr->fd; - if ((*port = (char *) malloc (strlen (ciptr->port) + 1)) == NULL) + if ((*port = (char *) xalloc (strlen (ciptr->port) + 1)) == NULL) return 0; else { @@ -676,17 +642,13 @@ char **port; int -TRANS(SetOption) (ciptr, option, arg) - -XtransConnInfo ciptr; -int option; -int arg; +TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg) { int fd = ciptr->fd; int ret = 0; - PRMSG (2,"TRANS(SetOption) (%d,%d,%d)\n", fd, option, arg); + PRMSG (2,"SetOption(%d,%d,%d)\n", fd, option, arg); /* * For now, all transport type use the same stuff for setting options. @@ -707,7 +669,8 @@ int arg; /* Set to blocking mode */ break; case 1: /* Set to non-blocking mode */ -#if defined(O_NONBLOCK) && (!defined(ultrix) && !defined(hpux) && !defined(AIXV3) && !defined(uniosu)) + +#if defined(O_NONBLOCK) && (!defined(ultrix) && !defined(hpux) && !defined(AIXV3) && !defined(uniosu) && !defined(__UNIXOS2__) && !defined(SCO)) && !defined(__QNX__) ret = fcntl (fd, F_GETFL, 0); if (ret != -1) ret = fcntl (fd, F_SETFL, ret | O_NONBLOCK); @@ -719,11 +682,17 @@ int arg; ret = ioctl (fd, FIOSNBIO, &arg); } #else -#if (defined(AIXV3) || defined(uniosu) || defined(WIN32)) && defined(FIONBIO) +#if (defined(AIXV3) || defined(uniosu) || defined(WIN32) || defined(__UNIXOS2__) || defined(__QNX__)) && defined(FIONBIO) { int arg; arg = 1; +/* IBM TCP/IP understands this option too well: it causes TRANS(Read) to fail + * eventually with EWOULDBLOCK */ +#ifndef __UNIXOS2__ ret = ioctl (fd, FIONBIO, &arg); +#else +/* ret = ioctl(fd, FIONBIO, &arg, sizeof(int));*/ +#endif } #else ret = fcntl (fd, F_GETFL, 0); @@ -758,20 +727,32 @@ int arg; #ifdef TRANS_SERVER int -TRANS(CreateListener) (ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(CreateListener) (XtransConnInfo ciptr, char *port) { return ciptr->transptr->CreateListener (ciptr, port); } - int -TRANS(ResetListener) (ciptr) +TRANS(NoListen) (char * protocol) + +{ + Xtransport *trans; + + if ((trans = TRANS(SelectTransport)(protocol)) == NULL) + { + PRMSG (1,"TRANS(TransNoListen): unable to find transport: %s\n", + protocol, 0, 0); + + return -1; + } + + trans->flags |= TRANS_NOLISTEN; + return 0; +} -XtransConnInfo ciptr; +int +TRANS(ResetListener) (XtransConnInfo ciptr) { if (ciptr->transptr->ResetListener) @@ -782,15 +763,12 @@ XtransConnInfo ciptr; XtransConnInfo -TRANS(Accept) (ciptr, status) - -XtransConnInfo ciptr; -int *status; +TRANS(Accept) (XtransConnInfo ciptr, int *status) { XtransConnInfo newciptr; - PRMSG (2,"TRANS(Accept) (%d)\n", ciptr->fd, 0, 0); + PRMSG (2,"Accept(%d)\n", ciptr->fd, 0, 0); newciptr = ciptr->transptr->Accept (ciptr, status); @@ -806,10 +784,7 @@ int *status; #ifdef TRANS_CLIENT int -TRANS(Connect) (ciptr, address) - -XtransConnInfo ciptr; -char *address; +TRANS(Connect) (XtransConnInfo ciptr, char *address) { char *protocol; @@ -817,29 +792,29 @@ char *address; char *port; int ret; - PRMSG (2,"TRANS(Connect) (%d,%s)\n", ciptr->fd, address, 0); + PRMSG (2,"Connect(%d,%s)\n", ciptr->fd, address, 0); if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0) { - PRMSG (1,"TRANS(Connect): Unable to Parse address %s\n", + PRMSG (1,"Connect: Unable to Parse address %s\n", address, 0, 0); return -1; } if (!port || !*port) { - PRMSG (1,"TRANS(Connect): Missing port specification in %s\n", + PRMSG (1,"Connect: Missing port specification in %s\n", address, 0, 0); - if (protocol) free (protocol); - if (host) free (host); + if (protocol) xfree (protocol); + if (host) xfree (host); return -1; } ret = ciptr->transptr->Connect (ciptr, host, port); - if (protocol) free (protocol); - if (host) free (host); - if (port) free (port); + if (protocol) xfree (protocol); + if (host) xfree (host); + if (port) xfree (port); return ret; } @@ -848,76 +823,54 @@ char *address; int -TRANS(BytesReadable) (ciptr, pend) - -XtransConnInfo ciptr; -BytesReadable_t *pend; +TRANS(BytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend) { return ciptr->transptr->BytesReadable (ciptr, pend); } int -TRANS(Read) (ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +TRANS(Read) (XtransConnInfo ciptr, char *buf, int size) { return ciptr->transptr->Read (ciptr, buf, size); } int -TRANS(Write) (ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +TRANS(Write) (XtransConnInfo ciptr, char *buf, int size) { return ciptr->transptr->Write (ciptr, buf, size); } int -TRANS(Readv) (ciptr, buf, size) +TRANS(Readv) (XtransConnInfo ciptr, struct iovec *buf, int size) -XtransConnInfo ciptr; -struct iovec *buf; -int size; { return ciptr->transptr->Readv (ciptr, buf, size); } int -TRANS(Writev) (ciptr, buf, size) - -XtransConnInfo ciptr; -struct iovec *buf; -int size; +TRANS(Writev) (XtransConnInfo ciptr, struct iovec *buf, int size) { return ciptr->transptr->Writev (ciptr, buf, size); } int -TRANS(Disconnect) (ciptr) - -XtransConnInfo ciptr; +TRANS(Disconnect) (XtransConnInfo ciptr) { return ciptr->transptr->Disconnect (ciptr); } int -TRANS(Close) (ciptr) - -XtransConnInfo ciptr; +TRANS(Close) (XtransConnInfo ciptr) { int ret; - PRMSG (2,"TRANS(Close) (%d)\n", ciptr->fd, 0, 0); + PRMSG (2,"Close(%d)\n", ciptr->fd, 0, 0); ret = ciptr->transptr->Close (ciptr); @@ -927,14 +880,12 @@ XtransConnInfo ciptr; } int -TRANS(CloseForCloning) (ciptr) - -XtransConnInfo ciptr; +TRANS(CloseForCloning) (XtransConnInfo ciptr) { int ret; - PRMSG (2,"TRANS(CloseForCloning) (%d)\n", ciptr->fd, 0, 0); + PRMSG (2,"CloseForCloning(%d)\n", ciptr->fd, 0, 0); ret = ciptr->transptr->CloseForCloning (ciptr); @@ -944,9 +895,7 @@ XtransConnInfo ciptr; } int -TRANS(IsLocal) (ciptr) - -XtransConnInfo ciptr; +TRANS(IsLocal) (XtransConnInfo ciptr) { return (ciptr->family == AF_UNIX); @@ -954,22 +903,18 @@ XtransConnInfo ciptr; int -TRANS(GetMyAddr) (ciptr, familyp, addrlenp, addrp) - -XtransConnInfo ciptr; -int *familyp; -int *addrlenp; -Xtransaddr **addrp; +TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp, + Xtransaddr **addrp) { - PRMSG (2,"TRANS(GetMyAddr) (%d)\n", ciptr->fd, 0, 0); + PRMSG (2,"GetMyAddr(%d)\n", ciptr->fd, 0, 0); *familyp = ciptr->family; *addrlenp = ciptr->addrlen; - if ((*addrp = (Xtransaddr *) malloc (ciptr->addrlen)) == NULL) + if ((*addrp = (Xtransaddr *) xalloc (ciptr->addrlen)) == NULL) { - PRMSG (1,"TRANS(GetMyAddr) malloc failed\n", 0, 0, 0); + PRMSG (1,"GetMyAddr: malloc failed\n", 0, 0, 0); return -1; } memcpy(*addrp, ciptr->addr, ciptr->addrlen); @@ -978,22 +923,18 @@ Xtransaddr **addrp; } int -TRANS(GetPeerAddr) (ciptr, familyp, addrlenp, addrp) - -XtransConnInfo ciptr; -int *familyp; -int *addrlenp; -Xtransaddr **addrp; +TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp, + Xtransaddr **addrp) { - PRMSG (2,"TRANS(GetPeerAddr) (%d)\n", ciptr->fd, 0, 0); + PRMSG (2,"GetPeerAddr(%d)\n", ciptr->fd, 0, 0); *familyp = ciptr->family; *addrlenp = ciptr->peeraddrlen; - if ((*addrp = (Xtransaddr *) malloc (ciptr->peeraddrlen)) == NULL) + if ((*addrp = (Xtransaddr *) xalloc (ciptr->peeraddrlen)) == NULL) { - PRMSG (1,"TRANS(GetPeerAddr) malloc failed\n", 0, 0, 0); + PRMSG (1,"GetPeerAddr: malloc failed\n", 0, 0, 0); return -1; } memcpy(*addrp, ciptr->peeraddr, ciptr->peeraddrlen); @@ -1003,9 +944,7 @@ Xtransaddr **addrp; int -TRANS(GetConnectionNumber) (ciptr) - -XtransConnInfo ciptr; +TRANS(GetConnectionNumber) (XtransConnInfo ciptr) { return ciptr->fd; @@ -1018,8 +957,10 @@ XtransConnInfo ciptr; * Independant API. */ +#ifdef TRANS_SERVER + static int -complete_network_count () +complete_network_count (void) { int count = 0; @@ -1032,7 +973,8 @@ complete_network_count () for (i = 0; i < NUMTRANS; i++) { - if (Xtransports[i].transport->flags & TRANS_ALIAS) + if (Xtransports[i].transport->flags & TRANS_ALIAS + || Xtransports[i].transport->flags & TRANS_NOLISTEN) continue; if (Xtransports[i].transport->flags & TRANS_LOCAL) @@ -1045,22 +987,17 @@ complete_network_count () } -#ifdef TRANS_SERVER int -TRANS(MakeAllCOTSServerListeners) (port, partial, count_ret, ciptrs_ret) - -char *port; -int *partial; -int *count_ret; -XtransConnInfo **ciptrs_ret; +TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret, + XtransConnInfo **ciptrs_ret) { char buffer[256]; /* ??? What size ?? */ XtransConnInfo ciptr, temp_ciptrs[NUMTRANS]; int status, i, j; - PRMSG (2,"TRANS(MakeAllCOTSServerListeners) (%s,%x)\n", + PRMSG (2,"MakeAllCOTSServerListeners(%s,%x)\n", port ? port : "NULL", ciptrs_ret, 0); *count_ret = 0; @@ -1069,18 +1006,21 @@ XtransConnInfo **ciptrs_ret; { Xtransport *trans = Xtransports[i].transport; - if (trans->flags&TRANS_ALIAS) + if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN) continue; sprintf(buffer,"%s/:%s", trans->TransName, port ? port : ""); - PRMSG (5,"TRANS(MakeAllCOTSServerListeners) opening %s\n", + PRMSG (5,"MakeAllCOTSServerListeners: opening %s\n", buffer, 0, 0); if ((ciptr = TRANS(OpenCOTSServer(buffer))) == NULL) { + if (trans->flags & TRANS_DISABLED) + continue; + PRMSG (1, - "TRANS(MakeAllCOTSServerListeners) failed to open listener for %s\n", + "MakeAllCOTSServerListeners: failed to open listener for %s\n", trans->TransName, 0, 0); continue; } @@ -1096,7 +1036,7 @@ XtransConnInfo **ciptrs_ret; */ PRMSG (1, - "TRANS(MakeAllCOTSServerListeners) server already running\n", + "MakeAllCOTSServerListeners: server already running\n", 0, 0, 0); for (j = 0; j < *count_ret; j++) @@ -1110,7 +1050,7 @@ XtransConnInfo **ciptrs_ret; else { PRMSG (1, - "TRANS(MakeAllCOTSServerListeners) failed to create listener for %s\n", + "MakeAllCOTSServerListeners: failed to create listener for %s\n", trans->TransName, 0, 0); continue; @@ -1118,7 +1058,7 @@ XtransConnInfo **ciptrs_ret; } PRMSG (5, - "TRANS(MakeAllCOTSServerListeners) opened listener for %s, %d\n", + "MakeAllCOTSServerListeners: opened listener for %s, %d\n", trans->TransName, ciptr->fd, 0); temp_ciptrs[*count_ret] = ciptr; @@ -1128,12 +1068,12 @@ XtransConnInfo **ciptrs_ret; *partial = (*count_ret < complete_network_count()); PRMSG (5, - "TRANS(MakeAllCLTSServerListeners) partial=%d, actual=%d, complete=%d \n", + "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n", *partial, *count_ret, complete_network_count()); if (*count_ret > 0) { - if ((*ciptrs_ret = (XtransConnInfo *) malloc ( + if ((*ciptrs_ret = (XtransConnInfo *) xalloc ( *count_ret * sizeof (XtransConnInfo))) == NULL) { return -1; @@ -1151,19 +1091,15 @@ XtransConnInfo **ciptrs_ret; } int -TRANS(MakeAllCLTSServerListeners) (port, partial, count_ret, ciptrs_ret) - -char *port; -int *partial; -int *count_ret; -XtransConnInfo **ciptrs_ret; +TRANS(MakeAllCLTSServerListeners) (char *port, int *partial, int *count_ret, + XtransConnInfo **ciptrs_ret) { char buffer[256]; /* ??? What size ?? */ XtransConnInfo ciptr, temp_ciptrs[NUMTRANS]; int status, i, j; - PRMSG (2,"TRANS(MakeAllCLTSServerListeners) (%s,%x)\n", + PRMSG (2,"MakeAllCLTSServerListeners(%s,%x)\n", port ? port : "NULL", ciptrs_ret, 0); *count_ret = 0; @@ -1172,18 +1108,18 @@ XtransConnInfo **ciptrs_ret; { Xtransport *trans = Xtransports[i].transport; - if (trans->flags&TRANS_ALIAS) + if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN) continue; sprintf(buffer,"%s/:%s", trans->TransName, port ? port : ""); - PRMSG (5,"TRANS(MakeAllCLTSServerListeners) opening %s\n", + PRMSG (5,"MakeAllCLTSServerListeners: opening %s\n", buffer, 0, 0); if ((ciptr = TRANS(OpenCLTSServer (buffer))) == NULL) { PRMSG (1, - "TRANS(MakeAllCLTSServerListeners) failed to open listener for %s\n", + "MakeAllCLTSServerListeners: failed to open listener for %s\n", trans->TransName, 0, 0); continue; } @@ -1199,7 +1135,7 @@ XtransConnInfo **ciptrs_ret; */ PRMSG (1, - "TRANS(MakeAllCLTSServerListeners) server already running\n", + "MakeAllCLTSServerListeners: server already running\n", 0, 0, 0); for (j = 0; j < *count_ret; j++) @@ -1213,7 +1149,7 @@ XtransConnInfo **ciptrs_ret; else { PRMSG (1, - "TRANS(MakeAllCLTSServerListeners) failed to create listener for %s\n", + "MakeAllCLTSServerListeners: failed to create listener for %s\n", trans->TransName, 0, 0); continue; @@ -1221,7 +1157,7 @@ XtransConnInfo **ciptrs_ret; } PRMSG (5, - "TRANS(MakeAllCLTSServerListeners) opened listener for %s, %d\n", + "MakeAllCLTSServerListeners: opened listener for %s, %d\n", trans->TransName, ciptr->fd, 0); temp_ciptrs[*count_ret] = ciptr; (*count_ret)++; @@ -1230,12 +1166,12 @@ XtransConnInfo **ciptrs_ret; *partial = (*count_ret < complete_network_count()); PRMSG (5, - "TRANS(MakeAllCLTSServerListeners) partial=%d, actual=%d, complete=%d \n", + "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n", *partial, *count_ret, complete_network_count()); if (*count_ret > 0) { - if ((*ciptrs_ret = (XtransConnInfo *) malloc ( + if ((*ciptrs_ret = (XtransConnInfo *) xalloc ( *count_ret * sizeof (XtransConnInfo))) == NULL) { return -1; @@ -1267,11 +1203,7 @@ XtransConnInfo **ciptrs_ret; * Cray UniCOS does not have readv and writev so we emulate */ -static int TRANS(ReadV) (ciptr, iov, iovcnt) - -XtransConnInfo ciptr; -struct iovec *iov; -int iovcnt; +static int TRANS(ReadV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) { struct msghdr hdr; @@ -1286,11 +1218,7 @@ int iovcnt; return (recvmsg (ciptr->fd, &hdr, 0)); } -static int TRANS(WriteV) (ciptr, iov, iovcnt) - -XtransConnInfo ciptr; -struct iovec *iov; -int iovcnt; +static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) { struct msghdr hdr; @@ -1307,17 +1235,13 @@ int iovcnt; #endif /* CRAY */ -#if (defined(SYSV) && defined(i386)) || defined(WIN32) || defined(__sxg__) || defined(SCO) +#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) /* * emulate readv */ -static int TRANS(ReadV) (ciptr, iov, iovcnt) - -XtransConnInfo ciptr; -struct iovec *iov; -int iovcnt; +static int TRANS(ReadV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) { int i, len, total; @@ -1341,19 +1265,15 @@ int iovcnt; return total; } -#endif /* SYSV && SYSV386 || WIN32 || __sxg__ || SCO */ +#endif /* SYSV && i386 || WIN32 || __sxg__ */ -#if defined(WIN32) || defined(__sxg__) || defined(SCO) +#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) /* * emulate writev */ -static int TRANS(WriteV) (ciptr, iov, iovcnt) - -XtransConnInfo ciptr; -struct iovec *iov; -int iovcnt; +static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) { int i, len, total; @@ -1377,11 +1297,13 @@ int iovcnt; return total; } -#endif /* WIN32 || __sxg__ || SCO */ +#endif /* SYSV && i386 || WIN32 || __sxg__ */ -#if (defined(_POSIX_SOURCE) && !defined(AIXV3)) || defined(hpux) || defined(USG) || defined(SVR4) +#if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(SCO) +#ifndef NEED_UTSNAME #define NEED_UTSNAME +#endif #include #endif @@ -1389,10 +1311,7 @@ int iovcnt; * TRANS(GetHostname) - similar to gethostname but allows special processing. */ -int TRANS(GetHostname) (buf, maxlen) - -char *buf; -int maxlen; +int TRANS(GetHostname) (char *buf, int maxlen) { int len; diff --git a/Xtrans.h b/Xtrans.h index cdba474..f2d297f 100644 --- a/Xtrans.h +++ b/Xtrans.h @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/xtrans/Xtrans.h,v 3.18 2001/12/14 19:57:04 dawes Exp $ */ /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * @@ -62,77 +63,104 @@ from The Open Group. */ #ifdef X11_t -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#if !defined(UNIXCPP) || defined(ANSICPP) #define TRANS(func) _X11Trans##func #else #define TRANS(func) _X11Trans/**/func #endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_X11Trans"; +#endif #endif /* X11_t */ #ifdef XSERV_t -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#if !defined(UNIXCPP) || defined(ANSICPP) #define TRANS(func) _XSERVTrans##func #else #define TRANS(func) _XSERVTrans/**/func #endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_XSERVTrans"; +#endif #define X11_t #endif /* X11_t */ #ifdef XIM_t -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#if !defined(UNIXCPP) || defined(ANSICPP) #define TRANS(func) _XimXTrans##func #else #define TRANS(func) _XimXTrans/**/func #endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_XimTrans"; +#endif #endif /* XIM_t */ #ifdef FS_t -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#if !defined(UNIXCPP) || defined(ANSICPP) #define TRANS(func) _FSTrans##func #else #define TRANS(func) _FSTrans/**/func #endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_FSTrans"; +#endif #endif /* FS_t */ #ifdef FONT_t -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#if !defined(UNIXCPP) || defined(ANSICPP) #define TRANS(func) _FontTrans##func #else #define TRANS(func) _FontTrans/**/func #endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_FontTrans"; +#endif #endif /* FONT_t */ #ifdef ICE_t -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#if !defined(UNIXCPP) || defined(ANSICPP) #define TRANS(func) _IceTrans##func #else #define TRANS(func) _IceTrans/**/func #endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_IceTrans"; +#endif #endif /* ICE_t */ #ifdef TEST_t -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#if !defined(UNIXCPP) || defined(ANSICPP) #define TRANS(func) _TESTTrans##func #else #define TRANS(func) _TESTTrans/**/func #endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_TESTTrans"; +#endif #endif /* TEST_t */ #ifdef LBXPROXY_t -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#if !defined(UNIXCPP) || defined(ANSICPP) #define TRANS(func) _LBXPROXYTrans##func #else #define TRANS(func) _LBXPROXYTrans/**/func #endif #define X11_t /* The server defines this - so should the LBX proxy */ +#ifdef XTRANSDEBUG +static char* __xtransname = "_LBXPROXYTrans"; +#endif #endif /* LBXPROXY_t */ #if !defined(TRANS) -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#if !defined(UNIXCPP) || defined(ANSICPP) #define TRANS(func) _XTrans##func #else #define TRANS(func) _XTrans/**/func #endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_XTrans"; +#endif #endif /* !TRANS */ @@ -173,7 +201,11 @@ struct iovec { }; #else +#ifndef Lynx #include +#else +#include +#endif #endif typedef struct _XtransConnInfo *XtransConnInfo; @@ -193,6 +225,7 @@ typedef struct _XtransConnInfo *XtransConnInfo; #define TRANS_CONNECT_FAILED -1 #define TRANS_TRY_CONNECT_AGAIN -2 +#define TRANS_IN_PROGRESS -3 /* @@ -225,12 +258,14 @@ typedef struct _XtransConnInfo *XtransConnInfo; * Function prototypes for the exposed interface */ +void TRANS(FreeConnInfo) ( + XtransConnInfo /* ciptr */ +); + #ifdef TRANS_CLIENT XtransConnInfo TRANS(OpenCOTSClient)( -#if NeedFunctionPrototypes char * /* address */ -#endif ); #endif /* TRANS_CLIENT */ @@ -238,9 +273,7 @@ XtransConnInfo TRANS(OpenCOTSClient)( #ifdef TRANS_SERVER XtransConnInfo TRANS(OpenCOTSServer)( -#if NeedFunctionPrototypes char * /* address */ -#endif ); #endif /* TRANS_SERVER */ @@ -248,9 +281,7 @@ XtransConnInfo TRANS(OpenCOTSServer)( #ifdef TRANS_CLIENT XtransConnInfo TRANS(OpenCLTSClient)( -#if NeedFunctionPrototypes char * /* address */ -#endif ); #endif /* TRANS_CLIENT */ @@ -258,9 +289,7 @@ XtransConnInfo TRANS(OpenCLTSClient)( #ifdef TRANS_SERVER XtransConnInfo TRANS(OpenCLTSServer)( -#if NeedFunctionPrototypes char * /* address */ -#endif ); #endif /* TRANS_SERVER */ @@ -268,61 +297,51 @@ XtransConnInfo TRANS(OpenCLTSServer)( #ifdef TRANS_REOPEN XtransConnInfo TRANS(ReopenCOTSServer)( -#if NeedFunctionPrototypes int, /* trans_id */ int, /* fd */ char * /* port */ -#endif ); XtransConnInfo TRANS(ReopenCLTSServer)( -#if NeedFunctionPrototypes int, /* trans_id */ int, /* fd */ char * /* port */ -#endif ); int TRANS(GetReopenInfo)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ int *, /* trans_id */ int *, /* fd */ char ** /* port */ -#endif ); #endif /* TRANS_REOPEN */ int TRANS(SetOption)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ int, /* option */ int /* arg */ -#endif ); #ifdef TRANS_SERVER int TRANS(CreateListener)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ char * /* port */ -#endif +); + +int TRANS(NoListen) ( + char* /* protocol*/ ); int TRANS(ResetListener)( -#if NeedFunctionPrototypes XtransConnInfo /* ciptr */ -#endif ); XtransConnInfo TRANS(Accept)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ int * /* status */ -#endif ); #endif /* TRANS_SERVER */ @@ -330,119 +349,89 @@ XtransConnInfo TRANS(Accept)( #ifdef TRANS_CLIENT int TRANS(Connect)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ char * /* address */ -#endif ); #endif /* TRANS_CLIENT */ int TRANS(BytesReadable)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ BytesReadable_t * /* pend */ -#endif ); int TRANS(Read)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ char *, /* buf */ int /* size */ -#endif ); int TRANS(Write)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ char *, /* buf */ int /* size */ -#endif ); int TRANS(Readv)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ struct iovec *, /* buf */ int /* size */ -#endif ); int TRANS(Writev)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ struct iovec *, /* buf */ int /* size */ -#endif ); int TRANS(Disconnect)( -#if NeedFunctionPrototypes XtransConnInfo /* ciptr */ -#endif ); int TRANS(Close)( -#if NeedFunctionPrototypes XtransConnInfo /* ciptr */ -#endif ); int TRANS(CloseForCloning)( -#if NeedFunctionPrototypes XtransConnInfo /* ciptr */ -#endif ); int TRANS(IsLocal)( -#if NeedFunctionPrototypes XtransConnInfo /* ciptr */ -#endif ); int TRANS(GetMyAddr)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ int *, /* familyp */ int *, /* addrlenp */ Xtransaddr ** /* addrp */ -#endif ); int TRANS(GetPeerAddr)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ int *, /* familyp */ int *, /* addrlenp */ Xtransaddr ** /* addrp */ -#endif ); int TRANS(GetConnectionNumber)( -#if NeedFunctionPrototypes XtransConnInfo /* ciptr */ -#endif ); #ifdef TRANS_SERVER int TRANS(MakeAllCOTSServerListeners)( -#if NeedFunctionPrototypes char *, /* port */ int *, /* partial */ int *, /* count_ret */ XtransConnInfo ** /* ciptrs_ret */ -#endif ); int TRANS(MakeAllCLTSServerListeners)( -#if NeedFunctionPrototypes char *, /* port */ int *, /* partial */ int *, /* count_ret */ XtransConnInfo ** /* ciptrs_ret */ -#endif ); #endif /* TRANS_SERVER */ @@ -455,11 +444,9 @@ int TRANS(MakeAllCLTSServerListeners)( #ifdef X11_t int TRANS(ConvertAddress)( -#if NeedFunctionPrototypes int *, /* familyp */ int *, /* addrlenp */ Xtransaddr ** /* addrp */ -#endif ); #endif /* X11_t */ @@ -468,20 +455,22 @@ int TRANS(ConvertAddress)( char * TRANS(GetMyNetworkId)( -#if NeedFunctionPrototypes XtransConnInfo /* ciptr */ -#endif ); char * TRANS(GetPeerNetworkId)( -#if NeedFunctionPrototypes XtransConnInfo /* ciptr */ -#endif ); #endif /* ICE_t */ +int +TRANS(GetHostname) ( + char * /* buf */, + int /* maxlen */ +); + #if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN)) int TRANS(WSAStartup)(); #endif diff --git a/Xtransdnet.c b/Xtransdnet.c index 55a618c..fcdede0 100644 --- a/Xtransdnet.c +++ b/Xtransdnet.c @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/xtrans/Xtransdnet.c,v 3.7 2002/11/26 01:12:30 dawes Exp $ */ /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * @@ -100,19 +101,17 @@ from The Open Group. */ static int -TRANS(DNETGetAddr) (ciptr) - -XtransConnInfo ciptr; +TRANS(DNETGetAddr) (XtransConnInfo ciptr) { struct sockaddr_dn sockname; int namelen = sizeof(sockname); - PRMSG (3,"TRANS(DNETGetAddr) (%x)\n", ciptr, 0, 0); + PRMSG (3,"DNETGetAddr(%x)\n", ciptr, 0, 0); if (getsockname (ciptr->fd, (struct sockaddr *) &sockname, &namelen) < 0) { - PRMSG (1,"TRANS(DNETGetAddr): getsockname() failed: %d\n", + PRMSG (1,"DNETGetAddr: getsockname() failed: %d\n", EGET(), 0, 0); return -1; } @@ -122,9 +121,9 @@ XtransConnInfo ciptr; * Everything looks good: fill in the XtransConnInfo structure. */ - if ((ciptr->addr = (char *) malloc (namelen)) == NULL) + if ((ciptr->addr = (char *) xalloc (namelen)) == NULL) { - PRMSG (1, "TRANS(DNETGetAddr): Can't allocate space for the addr\n", + PRMSG (1, "DNETGetAddr: Can't allocate space for the addr\n", 0, 0, 0); return -1; } @@ -143,19 +142,17 @@ XtransConnInfo ciptr; */ static int -TRANS(DNETGetPeerAddr) (ciptr) - -XtransConnInfo ciptr; +TRANS(DNETGetPeerAddr) (XtransConnInfo ciptr) { struct sockaddr_dn sockname; int namelen = sizeof(sockname); - PRMSG (3,"TRANS(DNETGetPeerAddr) (%x)\n", ciptr, 0, 0); + PRMSG (3,"DNETGetPeerAddr(%x)\n", ciptr, 0, 0); if (getpeername (ciptr->fd, (struct sockaddr *) &sockname, &namelen) < 0) { - PRMSG (1,"TRANS(DNETGetPeerAddr): getpeername() failed: %d\n", + PRMSG (1,"DNETGetPeerAddr: getpeername() failed: %d\n", EGET(), 0, 0); return -1; } @@ -164,10 +161,10 @@ XtransConnInfo ciptr; * Everything looks good: fill in the XtransConnInfo structure. */ - if ((ciptr->peeraddr = (char *) malloc (namelen)) == NULL) + if ((ciptr->peeraddr = (char *) xalloc (namelen)) == NULL) { PRMSG (1, - "TRANS(DNETGetPeerAddr): Can't allocate space for the addr\n", + "DNETGetPeerAddr: Can't allocate space for the addr\n", 0, 0, 0); return -1; } @@ -182,22 +179,18 @@ XtransConnInfo ciptr; #ifdef TRANS_CLIENT static XtransConnInfo -TRANS(DNETOpenCOTSClient) (thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(DNETOpenCOTSClient) (Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; - PRMSG (2,"TRANS(DNETOpenCOTSClient) (%s,%s,%s)\n", protocol, host, port); + PRMSG (2,"DNETOpenCOTSClient(%s,%s,%s)\n", protocol, host, port); - if ((ciptr = (XtransConnInfo) calloc ( + if ((ciptr = (XtransConnInfo) xcalloc ( 1, sizeof(struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(DNETOpenCOTSClient): malloc failed\n", 0, 0, 0); + PRMSG (1, "DNETOpenCOTSClient: malloc failed\n", 0, 0, 0); return NULL; } @@ -214,28 +207,24 @@ char *port; #ifdef TRANS_SERVER static XtransConnInfo -TRANS(DNETOpenCOTSServer) (thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(DNETOpenCOTSServer) (Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; - PRMSG (2,"TRANS(DNETOpenCOTSServer) (%s,%s,%s)\n", protocol, host, port); + PRMSG (2,"DNETOpenCOTSServer(%s,%s,%s)\n", protocol, host, port); - if ((ciptr = (XtransConnInfo) calloc ( + if ((ciptr = (XtransConnInfo) xcalloc ( 1, sizeof(struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(DNETOpenCOTSServer): malloc failed\n", 0, 0, 0); + PRMSG (1, "DNETOpenCOTSServer: malloc failed\n", 0, 0, 0); return NULL; } if ((ciptr->fd = socket (AF_DECnet, SOCK_STREAM, 0)) < 0) { - free ((char *) ciptr); + xfree ((char *) ciptr); return NULL; } @@ -250,22 +239,18 @@ char *port; #ifdef TRANS_CLIENT static XtransConnInfo -TRANS(DNETOpenCLTSClient) (thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(DNETOpenCLTSClient) (Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; - PRMSG (2,"TRANS(DNETOpenCLTSClient) (%s,%s,%s)\n", protocol, host, port); + PRMSG (2,"DNETOpenCLTSClient(%s,%s,%s)\n", protocol, host, port); - if ((ciptr = (XtransConnInfo) calloc ( + if ((ciptr = (XtransConnInfo) xcalloc ( 1, sizeof (struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(DNETOpenCLTSClient): malloc failed\n", 0, 0, 0); + PRMSG (1, "DNETOpenCLTSClient: malloc failed\n", 0, 0, 0); return NULL; } @@ -282,17 +267,13 @@ char *port; #ifdef TRANS_SERVER static XtransConnInfo -TRANS(DNETOpenCLTSServer) (thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(DNETOpenCLTSServer) (Xtransport *thistrans, char *protocol, + char *host, char *port) { /* NEED TO IMPLEMENT */ - PRMSG (2,"TRANS(DNETOpenCLTSServer) (%s,%s,%s)\n", protocol, host, port); + PRMSG (2,"DNETOpenCLTSServer(%s,%s,%s)\n", protocol, host, port); return NULL; } @@ -302,21 +283,17 @@ char *port; #ifdef TRANS_REOPEN static XtransConnInfo -TRANS(DNETReopenCOTSServer) (thistrans, fd, port) - -Xtransport *thistrans; -int fd; -char *port; +TRANS(DNETReopenCOTSServer) (Xtransport *thistrans, int fd, char *port) { XtransConnInfo ciptr; - PRMSG (2,"TRANS(DNETReopenCOTSServer) (%d, %s)\n", fd, port, 0); + PRMSG (2,"DNETReopenCOTSServer(%d,%s)\n", fd, port, 0); - if ((ciptr = (XtransConnInfo) calloc ( + if ((ciptr = (XtransConnInfo) xcalloc ( 1, sizeof(struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(DNETReopenCOTSServer): malloc failed\n", 0, 0, 0); + PRMSG (1, "DNETReopenCOTSServer: malloc failed\n", 0, 0, 0); return NULL; } @@ -327,21 +304,17 @@ char *port; } static XtransConnInfo -TRANS(DNETReopenCLTSServer) (thistrans, fd, port) - -Xtransport *thistrans; -int fd; -char *port; +TRANS(DNETReopenCLTSServer) (Xtransport *thistrans, int fd, char *port) { XtransConnInfo ciptr; - PRMSG (2,"TRANS(DNETReopenCLTSServer) (%d, %s)\n", fd, port, 0); + PRMSG (2,"DNETReopenCLTSServer(%d,%s)\n", fd, port, 0); - if ((ciptr = (XtransConnInfo) calloc ( + if ((ciptr = (XtransConnInfo) xcalloc ( 1, sizeof(struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(DNETReopenCLTSServer): malloc failed\n", 0, 0, 0); + PRMSG (1, "DNETReopenCLTSServer: malloc failed\n", 0, 0, 0); return NULL; } @@ -355,14 +328,10 @@ char *port; static int -TRANS(DNETSetOption) (ciptr, option, arg) - -XtransConnInfo ciptr; -int option; -int arg; +TRANS(DNETSetOption) (XtransConnInfo ciptr, int option, int arg) { - PRMSG (2,"TRANS(DNETSetOption) (%d,%d,%d)\n", ciptr->fd, option, arg); + PRMSG (2,"DNETSetOption(%d,%d,%d)\n", ciptr->fd, option, arg); return -1; } @@ -371,16 +340,13 @@ int arg; #ifdef TRANS_SERVER static int -TRANS(DNETCreateListener) (ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(DNETCreateListener) (XtransConnInfo ciptr, char *port) { struct sockaddr_dn dnsock; int fd = ciptr->fd; - PRMSG (3, "TRANS(DNETCreateListener) (%x,%d)\n", ciptr, fd, 0); + PRMSG (3, "DNETCreateListener(%x,%d)\n", ciptr, fd, 0); bzero ((char *) &dnsock, sizeof (dnsock)); dnsock.sdn_family = AF_DECnet; @@ -411,29 +377,26 @@ char *port; /* Set a flag to indicate that this connection is a listener */ - ciptr->flags = 1; + ciptr->flags = 1 | (ciptr->flags & TRANS_KEEPFLAGS); return 0; } static XtransConnInfo -TRANS(DNETAccept) (ciptr, status) - -XtransConnInfo ciptr; -int *status; +TRANS(DNETAccept) (XtransConnInfo ciptr, int *status) { XtransConnInfo newciptr; struct sockaddr_dn sockname; int namelen = sizeof(sockname); - PRMSG (2, "TRANS(DNETAccept) (%x,%d)\n", ciptr, ciptr->fd, 0); + PRMSG (2, "DNETAccept(%x,%d)\n", ciptr, ciptr->fd, 0); - if ((newciptr = (XtransConnInfo) calloc( + if ((newciptr = (XtransConnInfo) xcalloc( 1, sizeof (struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(DNETAccept): malloc failed\n", 0, 0, 0); + PRMSG (1, "DNETAccept: malloc failed\n", 0, 0, 0); *status = TRANS_ACCEPT_BAD_MALLOC; return NULL; } @@ -441,9 +404,9 @@ int *status; if((newciptr->fd = accept (ciptr->fd, (struct sockaddr *) &sockname, &namelen)) < 0) { - PRMSG (1, "TRANS(DNETAccept): accept() failed\n", 0, 0, 0); + PRMSG (1, "DNETAccept: accept() failed\n", 0, 0, 0); - free (newciptr); + xfree (newciptr); *status = TRANS_ACCEPT_FAILED; return NULL; } @@ -456,9 +419,9 @@ int *status; if (TRANS(DNETGetAddr) (newciptr) < 0) { PRMSG(1, - "TRANS(DNETAccept): TRANS(DNETGetAddr)() failed:\n", 0, 0, 0); + "DNETAccept: ...DNETGetAddr() failed:\n", 0, 0, 0); close (newciptr->fd); - free (newciptr); + xfree (newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; } @@ -466,11 +429,11 @@ int *status; if (TRANS(DNETGetPeerAddr) (newciptr) < 0) { PRMSG(1, - "TRANS(DNETAccept): TRANS(DNETGetPeerAddr)() failed:\n", 0, 0, 0); + "DNETAccept: ...DNETGetPeerAddr() failed:\n", 0, 0, 0); close (newciptr->fd); - if (newciptr->addr) free (newciptr->addr); - free (newciptr); + if (newciptr->addr) xfree (newciptr->addr); + xfree (newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; } @@ -488,18 +451,14 @@ int *status; #define OBJBUFSIZE 64 static int -TRANS(DNETConnect) (ciptr, host, port) - -XtransConnInfo ciptr; -char *host; -char *port; +TRANS(DNETConnect) (XtransConnInfo ciptr, char *host, char *port) { char objname[OBJBUFSIZE]; extern int dnet_conn(); - PRMSG (2,"TRANS(DNETConnect) (%d,%s,%s)\n", ciptr->fd, host, port); + PRMSG (2,"DNETConnect(%d,%s,%s)\n", ciptr->fd, host, port); #ifdef X11_t /* @@ -541,14 +500,14 @@ char *port; if (TRANS(DNETGetAddr) (ciptr) < 0) { PRMSG (1, - "TRANS(DNETConnect): TRANS(DNETGetAddr) () failed:\n", 0, 0, 0); + "DNETConnect: ...DNETGetAddr() failed:\n", 0, 0, 0); return TRANS_CONNECT_FAILED; } if (TRANS(DNETGetPeerAddr) (ciptr) < 0) { PRMSG (1, - "TRANS(DNETConnect): TRANS(DNETGetPeerAddr) () failed:\n", + "DNETConnect: ...DNETGetPeerAddr() failed:\n", 0, 0, 0); return TRANS_CONNECT_FAILED; } @@ -560,13 +519,10 @@ char *port; static int -TRANS(DNETBytesReadable) (ciptr, pend) - -XtransConnInfo ciptr; -BytesReadable_t *pend; +TRANS(DNETBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend) { - PRMSG (2,"TRANS(DNETBytesReadable) (%x,%d,%x)\n", ciptr, ciptr->fd, pend); + PRMSG (2,"DNETBytesReadable(%x,%d,%x)\n", ciptr, ciptr->fd, pend); #ifdef WIN32 return ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend); @@ -577,14 +533,10 @@ BytesReadable_t *pend; static int -TRANS(DNETRead) (ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +TRANS(DNETRead) (XtransConnInfo ciptr, char *buf, int size) { - PRMSG (2,"TRANS(DNETRead) (%d,%x,%d)\n", ciptr->fd, buf, size); + PRMSG (2,"DNETRead(%d,%x,%d)\n", ciptr->fd, buf, size); #ifdef WIN32 return recv ((SOCKET)ciptr->fd, buf, size, 0); @@ -595,14 +547,10 @@ int size; static int -TRANS(DNETWrite) (ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +TRANS(DNETWrite) (XtransConnInfo ciptr, char *buf, int size) { - PRMSG (2,"TRANS(DNETWrite) (%d,%x,%d)\n", ciptr->fd, buf, size); + PRMSG (2,"DNETWrite(%d,%x,%d)\n", ciptr->fd, buf, size); #ifdef WIN32 return send ((SOCKET)ciptr->fd, buf, size, 0); @@ -613,52 +561,40 @@ int size; static int -TRANS(DNETReadv) (ciptr, buf, size) - -XtransConnInfo ciptr; -struct iovec *buf; -int size; +TRANS(DNETReadv) (XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG (2,"TRANS(DNETReadv) (%d,%x,%d)\n", ciptr->fd, buf, size); + PRMSG (2,"DNETReadv(%d,%x,%d)\n", ciptr->fd, buf, size); return READV (ciptr, buf, size); } static int -TRANS(DNETWritev) (ciptr, buf, size) - -XtransConnInfo ciptr; -struct iovec *buf; -int size; +TRANS(DNETWritev) (XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG (2,"TRANS(DNETWritev) (%d,%x,%d)\n", ciptr->fd, buf, size); + PRMSG (2,"DNETWritev(%d,%x,%d)\n", ciptr->fd, buf, size); return WRITEV (ciptr, buf, size); } static int -TRANS(DNETDisconnect) (ciptr) - -XtransConnInfo ciptr; +TRANS(DNETDisconnect) (XtransConnInfo ciptr) { - PRMSG (2,"TRANS(DNETDisconnect) (%x,%d)\n", ciptr, ciptr->fd, 0); + PRMSG (2,"DNETDisconnect(%x,%d)\n", ciptr, ciptr->fd, 0); return shutdown (ciptr->fd, 2); /* disallow further sends and receives */ } static int -TRANS(DNETClose) (ciptr) - -XtransConnInfo ciptr; +TRANS(DNETClose) (XtransConnInfo ciptr) { - PRMSG (2,"TRANS(DNETClose) (%x,%d)\n", ciptr, ciptr->fd, 0); + PRMSG (2,"DNETClose(%x,%d)\n", ciptr, ciptr->fd, 0); return close (ciptr->fd); } diff --git a/Xtransint.h b/Xtransint.h index 29c8522..a9d7d91 100644 --- a/Xtransint.h +++ b/Xtransint.h @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/xtrans/Xtransint.h,v 3.35 2002/11/26 01:12:30 dawes Exp $ */ /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * @@ -50,6 +51,9 @@ from The Open Group. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef _XTRANSINT_H_ +#define _XTRANSINT_H_ + /* * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport * Interface code. Each use of the PRMSG macro has a level associated with @@ -63,10 +67,18 @@ from The Open Group. * XTRANSDEBUG=4 printing of intermediate values * XTRANSDEBUG=5 really detailed stuff #define XTRANSDEBUG 2 + * + * Defining XTRANSDEBUGTIMESTAMP will cause printing timestamps with each + * message. */ -#ifndef _XTRANSINT_H_ -#define _XTRANSINT_H_ +#ifndef XTRANSDEBUG +# ifndef __UNIXOS2__ +# define XTRANSDEBUG 1 +# else +# define XTRANSDEBUG 1 +# endif +#endif #ifdef WIN32 #define _WILLWINSOCK_ @@ -79,12 +91,30 @@ from The Open Group. #endif /* XTRANSDEBUG */ #include -#ifdef X_NOT_STDC_ENV -extern int errno; /* Internal system error number. */ -#endif #ifndef WIN32 +#ifndef Lynx #include +#else +#include +#endif +#include +#include +#ifdef __UNIXOS2__ +#include +#endif + +/* + * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c, + * to avoid a race condition. JKJ (6/5/97) + */ + +#if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(SCO) +#ifndef NEED_UTSNAME +#define NEED_UTSNAME +#endif +#include +#endif /* * makedepend screws up on #undef OPEN_MAX, so we define a new symbol @@ -102,6 +132,9 @@ extern int errno; /* Internal system error number. */ #endif #endif #ifndef OPEN_MAX +#ifdef __GNU__ +#define OPEN_MAX (sysconf(_SC_OPEN_MAX)) +#endif #ifdef SVR4 #define OPEN_MAX 256 #else @@ -113,23 +146,33 @@ extern int errno; /* Internal system error number. */ #ifdef NOFILE #define OPEN_MAX NOFILE #else +#if !defined(__UNIXOS2__) && !defined(__QNX__) #define OPEN_MAX NOFILES_MAX +#else +#define OPEN_MAX 256 #endif #endif #endif #endif #endif - +#endif +#ifdef __GNU__ +#define TRANS_OPEN_MAX OPEN_MAX +#else /* !__GNU__ */ #if OPEN_MAX > 256 #define TRANS_OPEN_MAX 256 #else #define TRANS_OPEN_MAX OPEN_MAX #endif +#endif /*__GNU__*/ #endif /* TRANS_OPEN_MAX */ - +#ifdef __UNIXOS2__ +#define ESET(val) +#else #define ESET(val) errno = val +#endif #define EGET() errno #else /* WIN32 */ @@ -141,9 +184,7 @@ extern int errno; /* Internal system error number. */ #endif /* WIN32 */ -#ifndef NULL -#define NULL 0 -#endif +#include #ifdef X11_t #define X_TCP_PORT 6000 @@ -176,12 +217,10 @@ typedef struct _Xtransport { #ifdef TRANS_CLIENT XtransConnInfo (*OpenCOTSClient)( -#if NeedNestedPrototypes struct _Xtransport *, /* transport */ char *, /* protocol */ char *, /* host */ char * /* port */ -#endif ); #endif /* TRANS_CLIENT */ @@ -189,12 +228,10 @@ typedef struct _Xtransport { #ifdef TRANS_SERVER XtransConnInfo (*OpenCOTSServer)( -#if NeedNestedPrototypes struct _Xtransport *, /* transport */ char *, /* protocol */ char *, /* host */ char * /* port */ -#endif ); #endif /* TRANS_SERVER */ @@ -202,12 +239,10 @@ typedef struct _Xtransport { #ifdef TRANS_CLIENT XtransConnInfo (*OpenCLTSClient)( -#if NeedNestedPrototypes struct _Xtransport *, /* transport */ char *, /* protocol */ char *, /* host */ char * /* port */ -#endif ); #endif /* TRANS_CLIENT */ @@ -215,12 +250,10 @@ typedef struct _Xtransport { #ifdef TRANS_SERVER XtransConnInfo (*OpenCLTSServer)( -#if NeedNestedPrototypes struct _Xtransport *, /* transport */ char *, /* protocol */ char *, /* host */ char * /* port */ -#endif ); #endif /* TRANS_SERVER */ @@ -229,52 +262,40 @@ typedef struct _Xtransport { #ifdef TRANS_REOPEN XtransConnInfo (*ReopenCOTSServer)( -#if NeedNestedPrototypes struct _Xtransport *, /* transport */ int, /* fd */ char * /* port */ -#endif ); XtransConnInfo (*ReopenCLTSServer)( -#if NeedNestedPrototypes struct _Xtransport *, /* transport */ int, /* fd */ char * /* port */ -#endif ); #endif /* TRANS_REOPEN */ int (*SetOption)( -#if NeedNestedPrototypes XtransConnInfo, /* connection */ int, /* option */ int /* arg */ -#endif ); #ifdef TRANS_SERVER int (*CreateListener)( -#if NeedNestedPrototypes XtransConnInfo, /* connection */ char * /* port */ -#endif ); int (*ResetListener)( -#if NeedNestedPrototypes XtransConnInfo /* connection */ -#endif ); XtransConnInfo (*Accept)( -#if NeedNestedPrototypes XtransConnInfo, /* connection */ int * /* status */ -#endif ); #endif /* TRANS_SERVER */ @@ -282,70 +303,52 @@ typedef struct _Xtransport { #ifdef TRANS_CLIENT int (*Connect)( -#if NeedNestedPrototypes XtransConnInfo, /* connection */ char *, /* host */ char * /* port */ -#endif ); #endif /* TRANS_CLIENT */ int (*BytesReadable)( -#if NeedNestedPrototypes XtransConnInfo, /* connection */ BytesReadable_t * /* pend */ -#endif ); int (*Read)( -#if NeedNestedPrototypes XtransConnInfo, /* connection */ char *, /* buf */ int /* size */ -#endif ); int (*Write)( -#if NeedNestedPrototypes XtransConnInfo, /* connection */ char *, /* buf */ int /* size */ -#endif ); int (*Readv)( -#if NeedNestedPrototypes XtransConnInfo, /* connection */ struct iovec *, /* buf */ int /* size */ -#endif ); int (*Writev)( -#if NeedNestedPrototypes XtransConnInfo, /* connection */ struct iovec *, /* buf */ int /* size */ -#endif ); int (*Disconnect)( -#if NeedNestedPrototypes XtransConnInfo /* connection */ -#endif ); int (*Close)( -#if NeedNestedPrototypes XtransConnInfo /* connection */ -#endif ); int (*CloseForCloning)( -#if NeedNestedPrototypes XtransConnInfo /* connection */ -#endif ); } Xtransport; @@ -363,70 +366,115 @@ typedef struct _Xtransport_table { #define TRANS_ALIAS (1<<0) /* record is an alias, don't create server */ #define TRANS_LOCAL (1<<1) /* local transport */ +#define TRANS_DISABLED (1<<2) /* Don't open this one */ +#define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */ +#define TRANS_NOUNLINK (1<<4) /* Dont unlink transport endpoints */ +/* Flags to preserve when setting others */ +#define TRANS_KEEPFLAGS (TRANS_NOUNLINK) /* * readv() and writev() don't exist or don't work correctly on some * systems, so they may be emulated. */ -#if defined(CRAY) || (defined(SYSV) && defined(SYSV386)) || defined(WIN32) || defined(__sxg__) || defined(sco324) +#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) #define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt) static int TRANS(ReadV)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ struct iovec *, /* iov */ int /* iovcnt */ -#endif ); #else #define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt) -#endif /* CRAY || (SYSV && SYSV386) || WIN32 || __sxg__ || sco324 */ +#endif /* CRAY || (SYSV && i386) || WIN32 || __sxg__ || */ -#if defined(CRAY) || defined(WIN32) || defined(__sxg__) || defined(sco324) +#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__) #define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt) static int TRANS(WriteV)( -#if NeedFunctionPrototypes XtransConnInfo, /* ciptr */ struct iovec *, /* iov */ int /* iovcnt */ -#endif ); #else #define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt) -#endif /* CRAY || WIN32 || __sxg__ || sco324 */ +#endif /* CRAY || WIN32 || __sxg__ */ static int is_numeric ( -#if NeedFunctionPrototypes char * /* str */ -#endif ); +#ifdef TRANS_SERVER +static int trans_mkdir ( + char *, /* path */ + int /* mode */ +); +#endif /* * Some XTRANSDEBUG stuff */ #if defined(XTRANSDEBUG) +/* add hack to the format string to avoid warnings about extra arguments + * to fprintf. + */ +#ifdef XTRANSDEBUGTIMESTAMP +#if defined(XSERV_t) && defined(TRANS_SERVER) +/* Use ErrorF() for the X server */ +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + struct timeval tp;\ + gettimeofday(&tp,0); \ + ErrorF(__xtransname); \ + ErrorF(x+hack,a,b,c); \ + ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ + errno=saveerrno; \ + } else ((void)0) +#else +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + struct timeval tp;\ + gettimeofday(&tp,0); \ + fprintf(stderr, __xtransname); fflush(stderr); \ + fprintf(stderr, x+hack,a,b,c); fflush(stderr); \ + fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ + fflush(stderr); \ + errno=saveerrno; \ + } else ((void)0) +#endif /* XSERV_t && TRANS_SERVER */ +#else /* XTRANSDEBUGTIMESTAMP */ +#if defined(XSERV_t) && defined(TRANS_SERVER) +/* Use ErrorF() for the X server */ +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + ErrorF(__xtransname); \ + ErrorF(x+hack,a,b,c); \ + errno=saveerrno; \ + } else ((void)0) +#else #define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ - int saveerrno=errno; \ - fprintf(stderr, x,a,b,c); fflush(stderr); \ + int hack= 0, saveerrno=errno; \ + fprintf(stderr, __xtransname); fflush(stderr); \ + fprintf(stderr, x+hack,a,b,c); fflush(stderr); \ errno=saveerrno; \ - } + } else ((void)0) +#endif /* XSERV_t && TRANS_SERVER */ +#endif /* XTRANSDEBUGTIMESTAMP */ #else -#define PRMSG(lvl,x,a,b,c) +#define PRMSG(lvl,x,a,b,c) ((void)0) #endif /* XTRANSDEBUG */ #endif /* _XTRANSINT_H_ */ diff --git a/Xtranslcl.c b/Xtranslcl.c index 1dde90f..f92d6f8 100644 --- a/Xtranslcl.c +++ b/Xtranslcl.c @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/xtrans/Xtranslcl.c,v 3.39 2002/11/26 01:12:30 dawes Exp $ */ /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * @@ -78,11 +79,13 @@ from The Open Group. #include #include #include -#if 0 -#include /* Maybe for SVR4 only?? */ -#endif -#ifdef SVR4 +#if defined(SVR4) +#if !defined(DGUX) #include +#else /* DGUX */ +#include +#include +#endif #endif #include #include @@ -96,8 +99,14 @@ from The Open Group. */ #include +#ifndef X_NO_SYS_UN #include +#endif +#if defined(ISC) && !defined(_POSIX_SOURCE) +typedef unsigned short mode_t; +/* POSIX needed for mode_t define in sys/types.h */ +#endif /* * These functions actually implement the local connection mechanisms. @@ -106,10 +115,7 @@ from The Open Group. /* Type Not Supported */ static int -TRANS(OpenFail)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(OpenFail)(XtransConnInfo ciptr, char *port) { return -1; @@ -118,11 +124,7 @@ char *port; #ifdef TRANS_REOPEN static int -TRANS(ReopenFail)(ciptr, fd, port) - -XtransConnInfo ciptr; -int fd; -char *port; +TRANS(ReopenFail)(XtransConnInfo ciptr, int fd, char *port) { return 0; @@ -133,11 +135,7 @@ char *port; static int -TRANS(FillAddrInfo)(ciptr, sun_path, peer_sun_path) - -XtransConnInfo ciptr; -char *sun_path; -char *peer_sun_path; +TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path) { struct sockaddr_un *sunaddr; @@ -146,17 +144,21 @@ char *peer_sun_path; ciptr->family = AF_UNIX; ciptr->addrlen = sizeof (struct sockaddr_un); - if ((sunaddr = (struct sockaddr_un *) malloc (ciptr->addrlen)) == NULL) + if ((sunaddr = (struct sockaddr_un *) xalloc (ciptr->addrlen)) == NULL) { - PRMSG(1,"TRANS(FillAddrInfo)() failed to allocate memory for addr\n", + PRMSG(1,"FillAddrInfo: failed to allocate memory for addr\n", 0,0,0); return 0; } sunaddr->sun_family = AF_UNIX; + if (strlen(sun_path) > sizeof(sunaddr->sun_path) - 1) { + PRMSG(1, "FillAddrInfo: path too long\n", 0, 0, 0); + return 0; + } strcpy (sunaddr->sun_path, sun_path); -#ifdef BSD44SOCKETS +#if defined(BSD44SOCKETS) && !defined(Lynx) sunaddr->sun_len = strlen (sunaddr->sun_path); #endif @@ -164,13 +166,13 @@ char *peer_sun_path; ciptr->peeraddrlen = sizeof (struct sockaddr_un); - if ((p_sunaddr = (struct sockaddr_un *) malloc ( + if ((p_sunaddr = (struct sockaddr_un *) xalloc ( ciptr->peeraddrlen)) == NULL) { PRMSG(1, - "TRANS(FillAddrInfo)() failed to allocate memory for peer addr\n", + "FillAddrInfo: failed to allocate memory for peer addr\n", 0,0,0); - free ((char *) sunaddr); + xfree ((char *) sunaddr); ciptr->addr = NULL; return 0; @@ -178,8 +180,12 @@ char *peer_sun_path; p_sunaddr->sun_family = AF_UNIX; + if (strlen(peer_sun_path) > sizeof(p_sunaddr->sun_path) - 1) { + PRMSG(1, "FillAddrInfo: peer path too long\n", 0, 0, 0); + return 0; + } strcpy (p_sunaddr->sun_path, peer_sun_path); -#ifdef BSD44SOCKETS +#if defined(BSD44SOCKETS) && !defined(Lynx) p_sunaddr->sun_len = strlen (p_sunaddr->sun_path); #endif @@ -192,7 +198,7 @@ char *peer_sun_path; /* PTS */ -#if defined(SYSV) && !defined(sco) +#if defined(SYSV) && !defined(sco) && !defined(SCO) && !defined(ISC) #define SIGNAL_T int #else #define SIGNAL_T void @@ -203,14 +209,10 @@ typedef SIGNAL_T (*PFV)(); extern PFV signal(); extern char *ptsname( -#if NeedFunctionPrototypes int -#endif ); -static void _dummy(sig) - -int sig; +static void _dummy(int sig) { } @@ -241,7 +243,7 @@ int sig; * backwards binary compatability only. */ -#define X_ISC_DIR "/dev/X" +#define X_ISC_DIR "/dev/X/ISCCONN" #define ISCDEVNODENAME "/dev/X/ISCCONN/X%s" #define ISCTMPNODENAME "/tmp/.X11-unix/X%s" #define SCORNODENAME "/dev/X%1sR" @@ -274,23 +276,22 @@ int sig; #ifdef TRANS_CLIENT static int -TRANS(PTSOpenClient)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) { +#ifdef PTSNODENAME int fd,server,exitval,alarm_time,ret; char server_path[64]; char *slave, namelen; char buf[20]; /* MAX_PATH_LEN?? */ PFV savef; pid_t saved_pid; +#endif - PRMSG(2,"TRANS(PTSOpenClient)(%s)\n", port, 0,0 ); + PRMSG(2,"PTSOpenClient(%s)\n", port, 0,0 ); #if !defined(PTSNODENAME) - PRMSG(1,"Protocol is not supported by a pts connection\n", 0,0,0); + PRMSG(1,"PTSOpenClient: Protocol is not supported by a pts connection\n", 0,0,0); return -1; #else if (port && *port ) { @@ -309,7 +310,7 @@ char *port; */ if ((server = open (server_path, O_RDWR)) < 0) { - PRMSG(1,"TRANS(PTSOpenClient)() failed to open %s\n", server_path, 0,0); + PRMSG(1,"PTSOpenClient: failed to open %s\n", server_path, 0,0); return -1; } @@ -319,7 +320,7 @@ char *port; */ if ((fd = open("/dev/ptmx", O_RDWR)) < 0) { - PRMSG(1,"TRANS(PTSOpenClient)() failed to open /dev/ptmx\n", 0,0,0); + PRMSG(1,"PTSOpenClient: failed to open /dev/ptmx\n", 0,0,0); return -1; } @@ -329,7 +330,7 @@ char *port; slave = ptsname(fd); /* get name */ if( slave == NULL ) { - PRMSG(1,"TRANS(PTSOpenClient)() failed to get ptsname()\n", 0,0,0); + PRMSG(1,"PTSOpenClient: failed to get ptsname()\n", 0,0,0); close(fd); close(server); return -1; @@ -360,7 +361,7 @@ char *port; if (chmod(slave, 0666) < 0) { close(fd); close(server); - PRMSG(1,"Cannot chmod %s\n", slave, 0,0); + PRMSG(1,"PTSOpenClient: Cannot chmod %s\n", slave, 0,0); return(-1); } @@ -388,7 +389,7 @@ char *port; if (ret != 1) { PRMSG(1, - "TRANS(PTSOpenClient)() failed to get acknoledgement from server\n", + "PTSOpenClient: failed to get acknoledgement from server\n", 0,0,0); (void) close(fd); fd = -1; @@ -400,7 +401,7 @@ char *port; if (TRANS(FillAddrInfo) (ciptr, slave, server_path) == 0) { - PRMSG(1,"TRANS(PTSOpenClient)() failed to fill in addr info\n", + PRMSG(1,"PTSOpenClient: failed to fill in addr info\n", 0,0,0); close(fd); return -1; @@ -417,19 +418,19 @@ char *port; #ifdef TRANS_SERVER static int -TRANS(PTSOpenServer)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port) { +#ifdef PTSNODENAME int fd, server; char server_path[64], *slave; + int mode; +#endif - PRMSG(2,"TRANS(PTSOpenServer)(%s)\n", port, 0,0 ); + PRMSG(2,"PTSOpenServer(%s)\n", port, 0,0 ); #if !defined(PTSNODENAME) - PRMSG(1,"Protocol is not supported by a pts connection\n", 0,0,0); + PRMSG(1,"PTSOpenServer: Protocol is not supported by a pts connection\n", 0,0,0); return -1; #else if (port && *port ) { @@ -443,24 +444,36 @@ char *port; } #ifdef HAS_STICKY_DIR_BIT - mkdir(X_STREAMS_DIR, 01777); - chmod(X_STREAMS_DIR, 01777); + mode = 01777; #else - mkdir(X_STREAMS_DIR, 0777); - chmod(X_STREAMS_DIR, 0777); + mode = 0777; #endif + if (trans_mkdir(X_STREAMS_DIR, mode) == -1) { + PRMSG (1, "PTSOpenServer: mkdir(%s) failed, errno = %d\n", + X_STREAMS_DIR, errno, 0); + return(-1); + } +#if 0 if( (fd=open(server_path, O_RDWR)) >= 0 ) { - PRMSG(1, "A server is already running on port %s\n", port, 0,0 ); - PRMSG(1, "Remove %s if this is incorrect.\n", server_path, 0,0 ); + /* + * This doesn't prevent the server from starting up, and doesn't + * prevent clients from trying to connect to the in-use PTS (which + * is often in use by something other than another server). + */ + PRMSG(1, "PTSOpenServer: A server is already running on port %s\n", port, 0,0 ); + PRMSG(1, "PTSOpenServer: Remove %s if this is incorrect.\n", server_path, 0,0 ); close(fd); return(-1); } +#else + /* Just remove the old path (which is what happens with UNIXCONN) */ +#endif unlink(server_path); if( (fd=open(DEV_PTMX, O_RDWR)) < 0) { - PRMSG(1, "Unable to open %s\n", DEV_PTMX, 0,0 ); + PRMSG(1, "PTSOpenServer: Unable to open %s\n", DEV_PTMX, 0,0 ); return(-1); } @@ -468,25 +481,25 @@ char *port; unlockpt(fd); if( (slave=ptsname(fd)) == NULL) { - PRMSG(1, "Unable to get slave device name\n", 0,0,0 ); + PRMSG(1, "PTSOpenServer: Unable to get slave device name\n", 0,0,0 ); close(fd); return(-1); } if( link(slave,server_path) < 0 ) { - PRMSG(1, "Unable to link %s to %s\n", slave, server_path,0 ); + PRMSG(1, "PTSOpenServer: Unable to link %s to %s\n", slave, server_path,0 ); close(fd); return(-1); } if( chmod(server_path, 0666) < 0 ) { - PRMSG(1, "Unable to chmod %s to 0666\n", server_path,0,0 ); + PRMSG(1, "PTSOpenServer: Unable to chmod %s to 0666\n", server_path,0,0 ); close(fd); return(-1); } if( (server=open(server_path, O_RDWR)) < 0 ) { - PRMSG(1, "Unable to open server device %s\n", server_path,0,0 ); + PRMSG(1, "PTSOpenServer: Unable to open server device %s\n", server_path,0,0 ); close(fd); return(-1); } @@ -499,7 +512,7 @@ char *port; if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"TRANS(PTSOpenServer)() failed to fill in addr info\n", + PRMSG(1,"PTSOpenServer: failed to fill in addr info\n", 0,0,0); close(fd); return -1; @@ -511,11 +524,7 @@ char *port; } static int -TRANS(PTSAccept)(ciptr, newciptr, status) - -XtransConnInfo ciptr; -XtransConnInfo newciptr; -int *status; +TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) { int newfd; @@ -524,16 +533,16 @@ int *status; char buf[256]; struct sockaddr_un *sunaddr; - PRMSG(2,"TRANS(PTSAccept)(%x->%d)\n",ciptr,ciptr->fd,0); + PRMSG(2,"PTSAccept(%x->%d)\n",ciptr,ciptr->fd,0); if( (in=read(ciptr->fd,&length,1)) <= 0 ){ if( !in ) { - PRMSG(1, - "TRANS(PTSAccept)() Incoming connection closed\n",0,0,0); + PRMSG(2, + "PTSAccept: Incoming connection closed\n",0,0,0); } else { PRMSG(1, - "TRANS(PTSAccept)() Error reading incoming connection. errno=%d \n", + "PTSAccept: Error reading incoming connection. errno=%d \n", errno,0,0); } *status = TRANS_ACCEPT_MISC_ERROR; @@ -542,12 +551,12 @@ int *status; if( (in=read(ciptr->fd,buf,length)) <= 0 ){ if( !in ) { - PRMSG(1, - "TRANS(PTSAccept)() Incoming connection closed\n",0,0,0); + PRMSG(2, + "PTSAccept: Incoming connection closed\n",0,0,0); } else { PRMSG(1, -"TRANS(PTSAccept)() Error reading device name for new connection. errno=%d \n", +"PTSAccept: Error reading device name for new connection. errno=%d \n", errno,0,0); } *status = TRANS_ACCEPT_MISC_ERROR; @@ -557,7 +566,7 @@ int *status; buf[length] = '\0'; if( (newfd=open(buf,O_RDWR)) < 0 ) { - PRMSG(1, "TRANS(PTSAccept)() Failed to open %s\n",buf,0,0); + PRMSG(1, "PTSAccept: Failed to open %s\n",buf,0,0); *status = TRANS_ACCEPT_MISC_ERROR; return -1; } @@ -569,8 +578,8 @@ int *status; */ newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { - PRMSG(1,"TRANS(PTSAccept)() failed to allocate memory for peer addr\n", + if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) { + PRMSG(1,"PTSAccept: failed to allocate memory for peer addr\n", 0,0,0); close(newfd); *status = TRANS_ACCEPT_BAD_MALLOC; @@ -580,10 +589,10 @@ int *status; memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen); newciptr->peeraddrlen=sizeof(struct sockaddr_un); - if( (sunaddr=(struct sockaddr_un *)malloc(newciptr->peeraddrlen)) == NULL ) { - PRMSG(1,"TRANS(PTSAccept)() failed to allocate memory for peer addr\n", + if( (sunaddr=(struct sockaddr_un *)xalloc(newciptr->peeraddrlen)) == NULL ) { + PRMSG(1,"PTSAccept: failed to allocate memory for peer addr\n", 0,0,0); - free(newciptr->addr); + xfree(newciptr->addr); close(newfd); *status = TRANS_ACCEPT_BAD_MALLOC; return -1; @@ -591,7 +600,7 @@ int *status; sunaddr->sun_family=AF_UNIX; strcpy(sunaddr->sun_path,buf); -#ifdef BSD44SOCKETS +#if defined(BSD44SOCKETS) && !defined(Lynx) sunaddr->sun_len=strlen(sunaddr->sun_path); #endif @@ -613,21 +622,20 @@ int *status; #ifdef TRANS_CLIENT static int -TRANS(NAMEDOpenClient)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, char *port) { +#ifdef NAMEDNODENAME int fd; char server_path[64]; struct stat filestat; extern int isastream(); +#endif - PRMSG(2,"TRANS(NAMEDOpenClient)(%s)\n", port, 0,0 ); + PRMSG(2,"NAMEDOpenClient(%s)\n", port, 0,0 ); #if !defined(NAMEDNODENAME) - PRMSG(1,"Protocol is not supported by a NAMED connection\n", 0,0,0); + PRMSG(1,"NAMEDOpenClient: Protocol is not supported by a NAMED connection\n", 0,0,0); return -1; #else if ( port && *port ) { @@ -637,27 +645,27 @@ char *port; (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port); } } else { - (void) sprintf(server_path, "%s%d", NAMEDNODENAME, getpid()); + (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid()); } if (stat(server_path, &filestat) < 0 ) { - PRMSG(1,"No device %s for NAMED connection\n", server_path, 0,0 ); + PRMSG(1,"NAMEDOpenClient: No device %s for NAMED connection\n", server_path, 0,0 ); return -1; } if ((filestat.st_mode & S_IFMT) != S_IFIFO) { - PRMSG(1,"Device %s is not a FIFO\n", server_path, 0,0 ); + PRMSG(1,"NAMEDOpenClient: Device %s is not a FIFO\n", server_path, 0,0 ); /* Is this really a failure? */ return -1; } if ((fd = open(server_path, O_RDWR)) < 0) { - PRMSG(1,"Cannot open %s for NAMED connection\n", server_path, 0,0 ); + PRMSG(1,"NAMEDOpenClient: Cannot open %s for NAMED connection\n", server_path, 0,0 ); return -1; } if (isastream(fd) <= 0) { - PRMSG(1,"%s is not a streams device\n", server_path, 0,0 ); + PRMSG(1,"NAMEDOpenClient: %s is not a streams device\n", server_path, 0,0 ); (void) close(fd); return -1; } @@ -668,7 +676,7 @@ char *port; if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"TRANS(NAMEDOpenClient)() failed to fill in addr info\n", + PRMSG(1,"NAMEDOpenClient: failed to fill in addr info\n", 0,0,0); close(fd); return -1; @@ -685,20 +693,20 @@ char *port; #ifdef TRANS_SERVER static int -TRANS(NAMEDOpenServer)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, char *port) { +#ifdef NAMEDNODENAME int fd, pipefd[2]; char server_path[64]; struct stat sbuf; + int mode; +#endif - PRMSG(2,"TRANS(NAMEDOpenServer)(%s)\n", port, 0,0 ); + PRMSG(2,"NAMEDOpenServer(%s)\n", port, 0,0 ); #if !defined(NAMEDNODENAME) - PRMSG(1,"Protocol is not supported by a NAMED connection\n", 0,0,0); + PRMSG(1,"NAMEDOpenServer: Protocol is not supported by a NAMED connection\n", 0,0,0); return -1; #else if ( port && *port ) { @@ -708,48 +716,51 @@ char *port; (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port); } } else { - (void) sprintf(server_path, "%s%d", NAMEDNODENAME, getpid()); + (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid()); } #ifdef HAS_STICKY_DIR_BIT - mkdir(X_STREAMS_DIR, 01777); - chmod(X_STREAMS_DIR, 01777); + mode = 01777; #else - mkdir(X_STREAMS_DIR, 0777); - chmod(X_STREAMS_DIR, 0777); + mode = 0777; #endif + if (trans_mkdir(X_STREAMS_DIR, mode) == -1) { + PRMSG (1, "NAMEDOpenServer: mkdir(%s) failed, errno = %d\n", + X_STREAMS_DIR, errno, 0); + return(-1); + } if(stat(server_path, &sbuf) != 0) { if (errno == ENOENT) { if ((fd = creat(server_path, (mode_t)0666)) == -1) { - PRMSG(1, "Can't open %s\n", server_path, 0,0 ); + PRMSG(1, "NAMEDOpenServer: Can't open %s\n", server_path, 0,0 ); return(-1); } close(fd); if (chmod(server_path, (mode_t)0666) < 0) { - PRMSG(1, "Can't open %s\n", server_path, 0,0 ); + PRMSG(1, "NAMEDOpenServer: Can't open %s\n", server_path, 0,0 ); return(-1); } } else { - PRMSG(1, "stat on %s failed\n", server_path, 0,0 ); + PRMSG(1, "NAMEDOpenServer: stat on %s failed\n", server_path, 0,0 ); return(-1); } } if( pipe(pipefd) != 0) { - PRMSG(1, "pipe() failed, errno=%d\n",errno, 0,0 ); + PRMSG(1, "NAMEDOpenServer: pipe() failed, errno=%d\n",errno, 0,0 ); return(-1); } if( ioctl(pipefd[0], I_PUSH, "connld") != 0) { - PRMSG(1, "ioctl(I_PUSH,\"connld\") failed, errno=%d\n",errno, 0,0 ); + PRMSG(1, "NAMEDOpenServer: ioctl(I_PUSH,\"connld\") failed, errno=%d\n",errno, 0,0 ); close(pipefd[0]); close(pipefd[1]); return(-1); } if( fattach(pipefd[0], server_path) != 0) { - PRMSG(1, "fattach(%s) failed, errno=%d\n", server_path,errno, 0 ); + PRMSG(1, "NAMEDOpenServer: fattach(%s) failed, errno=%d\n", server_path,errno, 0 ); close(pipefd[0]); close(pipefd[1]); return(-1); @@ -761,9 +772,7 @@ char *port; if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"TRANS(NAMEDOpenServer)() failed to fill in addr info\n", - 0,0,0); - close(fd); + PRMSG(1,"NAMEDOpenServer: failed to fill in addr info\n", 0,0,0); return -1; } @@ -773,19 +782,15 @@ char *port; } static int -TRANS(NAMEDAccept)(ciptr, newciptr, status) - -XtransConnInfo ciptr; -XtransConnInfo newciptr; -int *status; +TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) { struct strrecvfd str; - PRMSG(2,"TRANS(NAMEDAccept)(%x->%d)\n", ciptr, ciptr->fd, 0 ); + PRMSG(2,"NAMEDAccept(%x->%d)\n", ciptr, ciptr->fd, 0 ); if( ioctl(ciptr->fd, I_RECVFD, &str ) < 0 ) { - PRMSG(1, "ioctl(I_RECVFD) failed, errno=%d\n", errno, 0,0 ); + PRMSG(1, "NAMEDAccept: ioctl(I_RECVFD) failed, errno=%d\n", errno, 0,0 ); *status = TRANS_ACCEPT_MISC_ERROR; return(-1); } @@ -795,9 +800,9 @@ int *status; */ newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { + if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) { PRMSG(1, - "TRANS(NAMEDAccept)() failed to allocate memory for peer addr\n", + "NAMEDAccept: failed to allocate memory for peer addr\n", 0,0,0); close(str.fd); *status = TRANS_ACCEPT_BAD_MALLOC; @@ -807,11 +812,11 @@ int *status; memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen); newciptr->peeraddrlen=newciptr->addrlen; - if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) { + if( (newciptr->peeraddr=(char *)xalloc(newciptr->peeraddrlen)) == NULL ) { PRMSG(1, - "TRANS(NAMEDAccept)() failed to allocate memory for peer addr\n", + "NAMEDAccept: failed to allocate memory for peer addr\n", 0,0,0); - free(newciptr->addr); + xfree(newciptr->addr); close(str.fd); *status = TRANS_ACCEPT_BAD_MALLOC; return -1; @@ -831,14 +836,15 @@ int *status; #ifndef sun + +/* SCO doesnt use the ISC transport type - it causes problems */ +#ifndef SCO325 + /* - * connect_spipe is used by both the SCO and ISC connection types. + * connect_spipe is used by the ISC connection type. */ static int -connect_spipe(fd1, fd2) - -int fd1, fd2; - +connect_spipe(int fd1, int fd2) { long temp; struct strfdinsert sbuf; @@ -860,14 +866,11 @@ int fd1, fd2; } /* - * connect_spipe is used by both the SCO and ISC connection types. + * named_spipe is used by ISC connection type. */ static int -named_spipe(fd, path) - -int fd; -char *path; +named_spipe(int fd, char *path) { int oldUmask, ret; @@ -885,7 +888,7 @@ char *path; } else { ret = fd; } - + return(ret); } @@ -895,12 +898,10 @@ char *path; #ifdef TRANS_CLIENT static int -TRANS(ISCOpenClient)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(ISCOpenClient)(XtransConnInfo ciptr, char *port) { +#ifdef ISCDEVNODENAME int fd,fds,server; char server_path[64]; char server_dev_path[64]; @@ -908,11 +909,12 @@ char *port; long temp; mode_t spmode; struct stat filestat; - - PRMSG(2,"TRANS(ISCOpenClient)(%s)\n", port, 0,0 ); - +#endif + + PRMSG(2,"ISCOpenClient(%s)\n", port, 0,0 ); + #if !defined(ISCDEVNODENAME) - PRMSG(1,"Protocol is not supported by a ISC connection\n", 0,0,0); + PRMSG(1,"ISCOpenClient: Protocol is not supported by a ISC connection\n", 0,0,0); return -1; #else (void) sprintf(server_path, ISCTMPNODENAME, port); @@ -921,7 +923,7 @@ char *port; fd = fds = server = -1; if (stat(DEV_SPX, &filestat) == -1) { - PRMSG(1, "stat(%s) failed, errno=%d\n", DEV_SPX, errno, 0 ); + PRMSG(1, "ISCOpenClient: stat(%s) failed, errno=%d\n", DEV_SPX, errno, 0 ); return(-1); } @@ -930,26 +932,26 @@ char *port; if (stat(server_path, &filestat) != -1) { if ((filestat.st_mode & S_IFMT) == spmode) { if ((server = open(server_path, O_RDWR)) < 0) { - PRMSG(1,"TRANS(ISCOpenClient): failed to open %s\n", + PRMSG(1,"ISCOpenClient: failed to open %s\n", server_path, 0,0 ); } } } - + if (server < 0) { /* try the alternate path */ if (stat(server_dev_path, &filestat) != -1) { if ((filestat.st_mode & S_IFMT) == spmode) { if ((server = open(server_dev_path, O_RDWR)) < 0) { - PRMSG(1,"TRANS(ISCOpenClient): failed to open %s\n", + PRMSG(1,"ISCOpenClient: failed to open %s\n", server_dev_path, 0,0 ); } } } } - + if (server < 0) { - PRMSG(1,"TRANS(ISCOpenClient): can't open either device %s or %s\n", + PRMSG(1,"ISCOpenClient: can't open either device %s or %s\n", server_path, server_dev_path, 0 ); return -1; } @@ -957,7 +959,7 @@ char *port; if ((fds = open(DEV_SPX, O_RDWR)) < 0 || (fd = open(DEV_SPX, O_RDWR)) < 0) { /* Failed to open all of the devices */ - PRMSG(1,"TRANS(ISCOpenClient): can't open %s\n", DEV_SPX, 0,0 ); + PRMSG(1,"ISCOpenClient: can't open %s\n", DEV_SPX, 0,0 ); (void) close(server); if (fds != -1) (void) close(fds); @@ -977,10 +979,10 @@ char *port; buf.offset = 0; buf.fildes = fd; buf.flags = 0; - + if (ioctl(fds, I_FDINSERT, &buf) < 0 || ioctl(server, I_SENDFD, fds) < 0) { - PRMSG(1,"TRANS(ISCOpenClient): ioctl(I_FDINSERT or I_SENDFD) failed\n", + PRMSG(1,"ISCOpenClient: ioctl(I_FDINSERT or I_SENDFD) failed\n", 0,0,0 ); (void) close(server); (void) close(fds); @@ -991,10 +993,10 @@ char *port; /* * Everything looks good: fill in the XtransConnInfo structure. */ - + if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"TRANS(ISCOpenClient)() failed to fill in addr info\n", + PRMSG(1,"ISCOpenClient: failed to fill in addr info\n", 0,0,0); close(fd); return -1; @@ -1011,81 +1013,93 @@ char *port; #ifdef TRANS_SERVER static int -TRANS(ISCOpenServer)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(ISCOpenServer)(XtransConnInfo ciptr, char *port) { +#ifdef ISCDEVNODENAME int fd = -1,fds = -1; char server_path[64],server_unix_path[64]; - - PRMSG(2,"TRANS(ISCOpenServer)(%s)\n", port, 0,0 ); - + unsigned int mode = 0; +#endif + + PRMSG(2,"ISCOpenServer(%s)\n", port, 0,0 ); + #if !defined(ISCDEVNODENAME) - PRMSG(1,"Protocol is not supported by a ISC connection\n", 0,0,0); + PRMSG(1,"ISCOpenServer: Protocol is not supported by a ISC connection\n", 0,0,0); return -1; #else (void) sprintf(server_path, ISCDEVNODENAME, port); (void) sprintf(server_unix_path, ISCTMPNODENAME, port); - + #ifdef HAS_STICKY_DIR_BIT - mkdir(X_STREAMS_DIR, 01777); /* "/dev/X" */ - chmod(X_STREAMS_DIR, 01777); - mkdir(X_ISC_DIR, 01777); /* "/dev/X/ISCCONN" */ - chmod(X_ISC_DIR, 01777); + mode = 01777; #else - mkdir(X_STREAMS_DIR, 0777); /* "/dev/X" */ - chmod(X_STREAMS_DIR, 0777); - mkdir(X_ISC_DIR, 0777); /* "/dev/X/ISCCONN" */ - chmod(X_ISC_DIR, 0777); + mode = 0777; #endif - + + /* "/dev/X" */ + if (trans_mkdir(X_STREAMS_DIR, mode) == -1) { + PRMSG (1, "ISCOpenServer: mkdir(%s) failed, errno = %d\n", + X_STREAMS_DIR, errno, 0); + return(-1); + } + /* "/dev/X/ISCCONN" */ + if (trans_mkdir(X_ISC_DIR, mode) == -1) { + PRMSG (1, "ISCOpenServer: mkdir(%s) failed, errno = %d\n", + X_ISC_DIR, errno, 0); + return(-1); + } + unlink(server_path); - + if( ((fds=open(DEV_SPX, O_RDWR)) < 0) || ((fd =open(DEV_SPX, O_RDWR)) < 0)) { - PRMSG(1,"TRANS(ISCOpenServer): failed to open %s\n", DEV_SPX, 0,0 ); + PRMSG(1,"ISCOpenServer: failed to open %s\n", DEV_SPX, 0,0 ); return -1; } - + if( (connect_spipe(fds, fd) < 0) || (named_spipe(fds, server_path) < 0)) { - PRMSG(1,"TRANS(ISCOpenServer): failed connect pipes\n", 0,0,0 ); + PRMSG(1,"ISCOpenServer: failed connect pipes\n", 0,0,0 ); close(fd); close(fds); return -1; } - + #if !defined(UNIXCONN) /* * If the UNIX Domain socket transport is not being used, then link this * device to the path /tmp/.X11-unix/X path. */ #define X_UNIX_DIR "/tmp/.X11-unix" - -#ifdef HAS_STICKY_DIR_BIT - if (!mkdir(X_UNIX_DIR, 01777)) - chmod(X_UNIX_DIR, 01777); -#else - if (!mkdir(X_UNIX_DIR, 0777)) - chmod(X_UNIX_DIR, 0777); -#endif - + + if (trans_mkdir(X_UNIX_DIR, mode) == -1) { + PRMSG (1, "ISCOpenServer: mkdir(%s) failed, errno = %d\n", + X_UNIX_DIR, errno, 0); + return(-1); + } + unlink(server_unix_path); - + #ifdef SVR4 /* we prefer symbolic links because hard links can't cross file systems */ if( symlink(server_path, server_unix_path) < 0 ) - PRMSG(1,"TRANS(ISCOpenServer): failed to link %s to %s\n", + PRMSG(1,"ISCOpenServer: failed to link %s to %s\n", server_path, server_unix_path, 0 ); /* * Don't make this failure fatal since the listener * is already established, and this just for compatability */ #else +#ifdef ISC40 + /* catch SIGSYS on symlink for ISC40 compiled binaries running on ISC30 */ + signal(SIGSYS,_dummy); +#endif if( link(server_path, server_unix_path) < 0 ) - PRMSG(1,"TRANS(ISCOpenServer): failed to link %s to %s\n", +#ifdef ISC40 + if( symlink(server_path, server_unix_path) < 0 ) +#endif + PRMSG(1,"ISCOpenServer: failed to link %s to %s\n", server_path, server_unix_path, 0 ); /* * Don't make this failure fatal since the listener @@ -1093,14 +1107,14 @@ char *port; */ #endif /* SVR4 */ #endif /* !UNIXCONN */ - + /* * Everything looks good: fill in the XtransConnInfo structure. */ - + if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"TRANS(ISCOpenServer)() failed to fill in addr info\n", + PRMSG(1,"ISCOpenServer: failed to fill in addr info\n", 0,0,0); close(fd); return -1; @@ -1112,75 +1126,76 @@ char *port; } static int -TRANS(ISCAccept)(ciptr, newciptr, status) - -XtransConnInfo ciptr; -XtransConnInfo newciptr; -int *status; +TRANS(ISCAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) { struct strrecvfd str; - - PRMSG(2,"TRANS(ISCAccept)(%d)\n", ciptr->fd, 0,0 ); - + + PRMSG(2,"ISCAccept(%d)\n", ciptr->fd, 0,0 ); + while (ioctl(ciptr->fd, I_RECVFD, &str) < 0) { if (errno != EAGAIN) { - PRMSG(1,"TRANS(ISCAccept): Can't read fildes", 0,0,0 ); + PRMSG(1,"ISCAccept: Can't read fildes", 0,0,0 ); *status = TRANS_ACCEPT_MISC_ERROR; return(-1); } } - + /* * Everything looks good: fill in the XtransConnInfo structure. */ - + newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { + if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) { PRMSG(1, - "TRANS(ISCAccept)() failed to allocate memory for peer addr\n", + "ISCAccept: failed to allocate memory for peer addr\n", 0,0,0); close(str.fd); *status = TRANS_ACCEPT_BAD_MALLOC; return -1; } - + memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen); - + newciptr->peeraddrlen=newciptr->addrlen; - if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) { + if( (newciptr->peeraddr=(char *)xalloc(newciptr->peeraddrlen)) == NULL ) { PRMSG(1, - "TRANS(ISCAccept)() failed to allocate memory for peer addr\n", + "ISCAccept: failed to allocate memory for peer addr\n", 0,0,0); - free(newciptr->addr); + xfree(newciptr->addr); close(str.fd); *status = TRANS_ACCEPT_BAD_MALLOC; return -1; } - + memcpy(newciptr->peeraddr,newciptr->addr,newciptr->peeraddrlen); - + *status = 0; return(str.fd); } #endif /* TRANS_SERVER */ - +#endif /* !SCO325 */ - /* SCO */ +/* + * 2002-11-09 (jkj@sco.com) + * + * This code has been modified to match what is in the actual SCO X server. + * This greatly helps inter-operability between X11R6 and X11R5 (the native + * SCO server). Mainly, it relies on streams nodes existing in /dev, not + * creating them or unlinking them, which breaks the native X server. + */ + #ifdef TRANS_CLIENT static int -TRANS(SCOOpenClient)(ciptr, port) - -XtransConnInfo ciptr; -char *port; - +TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port) { +#ifdef SCORNODENAME int fd, server, fl, ret; char server_path[64]; struct strbuf ctlbuf; @@ -1188,68 +1203,70 @@ char *port; void (*savef)(); long temp; extern int getmsg(), putmsg(); - - PRMSG(2,"TRANS(SCOOpenClient)(%s)\n", port, 0,0 ); - +#endif + + PRMSG(2,"SCOOpenClient(%s)\n", port, 0,0 ); + #if !defined(SCORNODENAME) - PRMSG(1,"Protocol is not supported by a SCO connection\n", 0,0,0); + PRMSG(1,"SCOOpenClient: Protocol is not supported by a SCO connection\n", 0,0,0); return -1; #else (void) sprintf(server_path, SCORNODENAME, port); - + if ((server = open(server_path, O_RDWR)) < 0) { - PRMSG(1,"TRANS(SCOOpenClient) failed to open %s\n", server_path, 0,0 ); + PRMSG(1,"SCOOpenClient: failed to open %s\n", server_path, 0,0 ); return -1; } - + if ((fd = open(DEV_SPX, O_RDWR)) < 0) { - PRMSG(1,"TRANS(SCOOpenClient) failed to open %s\n", DEV_SPX, 0,0 ); + PRMSG(1,"SCOOpenClient: failed to open %s\n", DEV_SPX, 0,0 ); close(server); return -1; } - + (void) write(server, &server, 1); ctlbuf.len = 0; ctlbuf.maxlen = sizeof(long); ctlbuf.buf = (caddr_t)&temp; fl = 0; - + savef = signal(SIGALRM, _dummy); alarm_time = alarm(10); - + ret = getmsg(server, &ctlbuf, 0, &fl); - + (void) alarm(alarm_time); (void) signal(SIGALRM, savef); - + if (ret < 0) { - PRMSG(1,"TRANS(SCOOpenClient) error from getmsg\n", 0,0,0 ); + PRMSG(1,"SCOOpenClient: error from getmsg\n", 0,0,0 ); close(fd); close(server); return -1; } - + /* The msg we got via getmsg is the result of an * I_FDINSERT, so if we do a putmsg with whatever * we recieved, we're doing another I_FDINSERT ... */ (void) putmsg(fd, &ctlbuf, 0, 0); (void) fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0)|O_NDELAY); - + (void) close(server); - + /* * Everything looks good: fill in the XtransConnInfo structure. */ - + + ciptr->flags |= TRANS_NOUNLINK; if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"TRANS(SCOOpenClient)() failed to fill addr info\n", + PRMSG(1,"SCOOpenClient: failed to fill addr info\n", 0,0,0); close(fd); return -1; } - + return(fd); #endif /* !SCORNODENAME */ @@ -1261,125 +1278,157 @@ char *port; #ifdef TRANS_SERVER static int -TRANS(SCOOpenServer)(ciptr, port) - -XtransConnInfo ciptr; -char *port; - +TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port) { +#ifdef SCORNODENAME char serverR_path[64]; char serverS_path[64]; - int fdr = -1; - int fds = -1; - - PRMSG(2,"TRANS(SCOOpenServer)(%s)\n", port, 0,0 ); - + struct flock mylock; + int fdr = -1; + int fds = -1; + long temp; + struct strfdinsert sbuf; +#endif + + PRMSG(2,"SCOOpenServer(%s)\n", port, 0,0 ); + #if !defined(SCORNODENAME) - PRMSG(1,"Protocol is not supported by a SCO connection\n", 0,0,0); + PRMSG(1,"SCOOpenServer: Protocol is not supported by a SCO connection\n", 0,0,0); return -1; #else (void) sprintf(serverR_path, SCORNODENAME, port); (void) sprintf(serverS_path, SCOSNODENAME, port); - - unlink(serverR_path); - unlink(serverS_path); - - if ((fds = open(DEV_SPX, O_RDWR)) < 0 || - (fdr = open(DEV_SPX, O_RDWR)) < 0 ) { - PRMSG(2,"TRANS(SCOOpenServer) failed to open %s\n", DEV_SPX, 0,0 ); + + fds = open (serverS_path, O_RDWR | O_NDELAY); + if (fds < 0) { + PRMSG(1,"SCOOpenServer: failed to open %s", serverS_path, 0, 0); return -1; } - - if (connect_spipe(fds, fdr) != -1 && - named_spipe(fds, serverS_path) != -1 && - named_spipe(fdr, serverR_path) != -1) { - PRMSG(2,"TRANS(SCOOpenServer) connect pipes\n", 0,0,0 ); - } else { - PRMSG(2,"TRANS(SCOOpenServer) failed to connect pipes\n", 0,0,0 ); - close(fds); - close(fdr); + + /* + * Lock the connection device for the duration of the server. + * This resolves multiple server starts especially on SMP machines. + */ + mylock.l_type = F_WRLCK; + mylock.l_whence = 0; + mylock.l_start = 0; + mylock.l_len = 0; + if (fcntl (fds, F_SETLK, &mylock) < 0) { + PRMSG(1,"SCOOpenServer: failed to lock %s", serverS_path, 0, 0); + close (fds); + return -1; + } + + fdr = open (serverR_path, O_RDWR | O_NDELAY); + if (fds < 0) { + PRMSG(1,"SCOOpenServer: failed to open %s", serverR_path, 0, 0); + close (fds); + return -1; + } + + sbuf.databuf.maxlen = 0; + sbuf.databuf.len = -1; + sbuf.databuf.buf = NULL; + sbuf.ctlbuf.maxlen = sizeof(long); + sbuf.ctlbuf.len = sizeof(long); + sbuf.ctlbuf.buf = (caddr_t)&temp; + sbuf.offset = 0; + sbuf.flags = 0; + sbuf.fildes = fdr; + + if (ioctl(fds, I_FDINSERT, &sbuf) < 0) { + PRMSG(1,"SCOOpenServer: ioctl(I_FDINSERT) failed on %s", serverS_path, 0, 0); + close (fdr); + close (fds); return -1; } - + /* * Everything looks good: fill in the XtransConnInfo structure. */ - - if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0) - { - PRMSG(1,"TRANS(SCOOpenServer)() failed to fill in addr info\n", - 0,0,0); + + ciptr->flags |= TRANS_NOUNLINK; + if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0) { + PRMSG(1,"SCOOpenServer: failed to fill in addr info\n", 0,0,0); close(fds); close(fdr); return -1; } - + return(fds); #endif /* !SCORNODENAME */ } static int -TRANS(SCOAccept)(ciptr, newciptr, status) +TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) +{ + char c; + int fd; + long temp; + struct strfdinsert sbuf; -XtransConnInfo ciptr; -XtransConnInfo newciptr; -int *status; + PRMSG(2,"SCOAccept(%d)\n", ciptr->fd, 0,0 ); -{ - char c; - int fd; - - PRMSG(2,"TRANS(SCOAccept)(%d)\n", ciptr->fd, 0,0 ); - if (read(ciptr->fd, &c, 1) < 0) { - PRMSG(1,"TRANS(SCOAccept): can't read from client",0,0,0); + PRMSG(1,"SCOAccept: can't read from client",0,0,0); *status = TRANS_ACCEPT_MISC_ERROR; return(-1); } - + if( (fd = open(DEV_SPX, O_RDWR)) < 0 ) { - PRMSG(1,"TRANS(SCOAccept)(): can't open \"%s\"",DEV_SPX, 0,0 ); + PRMSG(1,"SCOAccept: can't open \"%s\"",DEV_SPX, 0,0 ); *status = TRANS_ACCEPT_MISC_ERROR; return(-1); } - - if (connect_spipe(ciptr->fd, fd) < 0) { - PRMSG(1,"TRANS(SCOAccept)(): can't connect pipes", 0,0,0 ); - (void) close(fd); + + sbuf.databuf.maxlen = 0; + sbuf.databuf.len = -1; + sbuf.databuf.buf = NULL; + sbuf.ctlbuf.maxlen = sizeof(long); + sbuf.ctlbuf.len = sizeof(long); + sbuf.ctlbuf.buf = (caddr_t)&temp; + sbuf.offset = 0; + sbuf.flags = 0; + sbuf.fildes = fd; + + if (ioctl(ciptr->fd, I_FDINSERT, &sbuf) < 0) { + PRMSG(1,"SCOAccept: ioctl(I_FDINSERT) failed", 0, 0, 0); + close (fd); *status = TRANS_ACCEPT_MISC_ERROR; - return(-1); + return -1; } - + /* * Everything looks good: fill in the XtransConnInfo structure. */ - + newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { + if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) { PRMSG(1, - "TRANS(SCOAccept)() failed to allocate memory for peer addr\n", + "SCOAccept: failed to allocate memory for peer addr\n", 0,0,0); close(fd); *status = TRANS_ACCEPT_BAD_MALLOC; return -1; } - + memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen); - + newciptr->flags |= TRANS_NOUNLINK; + newciptr->peeraddrlen=newciptr->addrlen; - if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) { + if( (newciptr->peeraddr=(char *)xalloc(newciptr->peeraddrlen)) == NULL ) { PRMSG(1, - "TRANS(SCOAccept)() failed to allocate memory for peer addr\n", + "SCOAccept: failed to allocate memory for peer addr\n", 0,0,0); - free(newciptr->addr); + xfree(newciptr->addr); close(fd); *status = TRANS_ACCEPT_BAD_MALLOC; return -1; } - + memcpy(newciptr->peeraddr,newciptr->addr,newciptr->peeraddrlen); - + *status = 0; return(fd); @@ -1391,20 +1440,20 @@ int *status; #ifdef TRANS_REOPEN +#ifndef sun static int -TRANS(PTSReopenServer)(ciptr, fd, port) +TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, char *port) -XtransConnInfo ciptr; -int fd; -char *port; { +#ifdef PTSNODENAME char server_path[64]; +#endif - PRMSG(2,"TRANS(PTSReopenServer)(%d,%s)\n", fd, port, 0 ); + PRMSG(2,"PTSReopenServer(%d,%s)\n", fd, port, 0 ); #if !defined(PTSNODENAME) - PRMSG(1,"Protocol is not supported by a pts connection\n", 0,0,0); + PRMSG(1,"PTSReopenServer: Protocol is not supported by a pts connection\n", 0,0,0); return 0; #else if (port && *port ) { @@ -1414,12 +1463,12 @@ char *port; (void) sprintf(server_path, "%s%s", PTSNODENAME, port); } } else { - (void) sprintf(server_path, "%s%d", PTSNODENAME, getpid()); + (void) sprintf(server_path, "%s%ld", PTSNODENAME, (long)getpid()); } if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"TRANS(PTSReopenServer)() failed to fill in addr info\n", + PRMSG(1,"PTSReopenServer: failed to fill in addr info\n", 0,0,0); return 0; } @@ -1429,21 +1478,20 @@ char *port; #endif /* !PTSNODENAME */ } +#endif /* !sun */ static int -TRANS(NAMEDReopenServer)(ciptr, fd, port) - -XtransConnInfo ciptr; -int fd; -char *port; +TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd, char *port) { +#ifdef NAMEDNODENAME char server_path[64]; +#endif - PRMSG(2,"TRANS(NAMEDReopenServer)(%s)\n", port, 0,0 ); + PRMSG(2,"NAMEDReopenServer(%s)\n", port, 0,0 ); #if !defined(NAMEDNODENAME) - PRMSG(1,"Protocol is not supported by a NAMED connection\n", 0,0,0); + PRMSG(1,"NAMEDReopenServer: Protocol is not supported by a NAMED connection\n", 0,0,0); return 0; #else if ( port && *port ) { @@ -1453,12 +1501,12 @@ char *port; (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port); } } else { - (void) sprintf(server_path, "%s%d", NAMEDNODENAME, getpid()); + (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid()); } if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"TRANS(NAMEDReopenServer)() failed to fill in addr info\n", + PRMSG(1,"NAMEDReopenServer: failed to fill in addr info\n", 0,0,0); return 0; } @@ -1468,21 +1516,20 @@ char *port; #endif /* !NAMEDNODENAME */ } - +#ifndef sun +#ifndef SCO325 static int -TRANS(ISCReopenServer)(ciptr, fd, port) - -XtransConnInfo ciptr; -int fd; -char *port; +TRANS(ISCReopenServer)(XtransConnInfo ciptr, int fd, char *port) { - char server_path[64],server_unix_path[64]; - - PRMSG(2,"TRANS(ISCReopenServer)(%s)\n", port, 0,0 ); - +#ifdef ISCDEVNODENAME + char server_path[64], server_unix_path[64]; +#endif + + PRMSG(2,"ISCReopenServer(%s)\n", port, 0,0 ); + #if !defined(ISCDEVNODENAME) - PRMSG(1,"Protocol is not supported by a ISC connection\n", 0,0,0); + PRMSG(1,"ISCReopenServer: Protocol is not supported by a ISC connection\n", 0,0,0); return 0; #else (void) sprintf(server_path, ISCDEVNODENAME, port); @@ -1490,49 +1537,47 @@ char *port; if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"TRANS(ISCReopenServer)() failed to fill in addr info\n", - 0,0,0); + PRMSG(1, "ISCReopenServer: failed to fill in addr info\n", 0,0,0); return 0; } - + return 1; #endif /* !ISCDEVNODENAME */ } - +#endif /* !SCO325 */ static int -TRANS(SCOReopenServer)(ciptr, fd, port) - -XtransConnInfo ciptr; -int fd; -char *port; +TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port) { - char serverR_path[64]; - char serverS_path[64]; - - PRMSG(2,"TRANS(SCOReopenServer)(%s)\n", port, 0,0 ); - +#ifdef SCORNODENAME + char serverR_path[64], serverS_path[64]; +#endif + + PRMSG(2,"SCOReopenServer(%s)\n", port, 0,0 ); + #if !defined(SCORNODENAME) - PRMSG(1,"Protocol is not supported by a SCO connection\n", 0,0,0); + PRMSG(1,"SCOReopenServer: Protocol is not supported by a SCO connection\n", 0,0,0); return 0; #else (void) sprintf(serverR_path, SCORNODENAME, port); (void) sprintf(serverS_path, SCOSNODENAME, port); - + + ciptr->flags |= TRANS_NOUNLINK; if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0) { - PRMSG(1,"TRANS(SCOReopenServer)() failed to fill in addr info\n", - 0,0,0); + PRMSG(1, "SCOReopenServer: failed to fill in addr info\n", 0,0,0); return 0; } - + return 1; #endif /* SCORNODENAME */ } +#endif /* !sun */ + #endif /* TRANS_REOPEN */ @@ -1548,9 +1593,7 @@ typedef struct _LOCALtrans2dev { #ifdef TRANS_CLIENT int (*devcotsopenclient)( -#if NeedFunctionPrototypes XtransConnInfo, char * /*port*/ -#endif ); #endif /* TRANS_CLIENT */ @@ -1558,9 +1601,7 @@ typedef struct _LOCALtrans2dev { #ifdef TRANS_SERVER int (*devcotsopenserver)( -#if NeedFunctionPrototypes XtransConnInfo, char * /*port*/ -#endif ); #endif /* TRANS_SERVER */ @@ -1568,9 +1609,7 @@ typedef struct _LOCALtrans2dev { #ifdef TRANS_CLIENT int (*devcltsopenclient)( -#if NeedFunctionPrototypes XtransConnInfo, char * /*port*/ -#endif ); #endif /* TRANS_CLIENT */ @@ -1578,9 +1617,7 @@ typedef struct _LOCALtrans2dev { #ifdef TRANS_SERVER int (*devcltsopenserver)( -#if NeedFunctionPrototypes XtransConnInfo, char * /*port*/ -#endif ); #endif /* TRANS_SERVER */ @@ -1588,19 +1625,15 @@ typedef struct _LOCALtrans2dev { #ifdef TRANS_REOPEN int (*devcotsreopenserver)( -#if NeedFunctionPrototypes XtransConnInfo, int, /* fd */ char * /* port */ -#endif ); int (*devcltsreopenserver)( -#if NeedFunctionPrototypes XtransConnInfo, int, /* fd */ char * /* port */ -#endif ); #endif /* TRANS_REOPEN */ @@ -1608,10 +1641,7 @@ typedef struct _LOCALtrans2dev { #ifdef TRANS_SERVER int (*devaccept)( -#if NeedFunctionPrototypes XtransConnInfo, XtransConnInfo, int * -#endif - ); #endif /* TRANS_SERVER */ @@ -1756,6 +1786,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { #endif /* SVR4 */ #ifndef sun +#ifndef SCO325 {"isc", #ifdef TRANS_CLIENT TRANS(ISCOpenClient), @@ -1777,6 +1808,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { TRANS(ISCAccept) #endif /* TRANS_SERVER */ }, +#endif /* !SCO325 */ {"sco", #ifdef TRANS_CLIENT @@ -1803,28 +1835,26 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { }; #define NUMTRANSPORTS (sizeof(LOCALtrans2devtab)/sizeof(LOCALtrans2dev)) - + static char *XLOCAL=NULL; static char *workingXLOCAL=NULL; static char *freeXLOCAL=NULL; -#ifdef sco -#define DEF_XLOCAL "UNIX:SCO:PTS:NAMED:ISC" +#ifdef SCO325 +#define DEF_XLOCAL "SCO:UNIX:PTS" #else #define DEF_XLOCAL "UNIX:PTS:NAMED:ISC:SCO" #endif static void -TRANS(LocalInitTransports)(protocol) - -char *protocol; +TRANS(LocalInitTransports)(char *protocol) { - PRMSG(3,"TRANS(LocalInitTransports)(%s)\n", protocol, 0,0 ); - + PRMSG(3,"LocalInitTransports(%s)\n", protocol, 0,0 ); + if( strcmp(protocol,"local") && strcmp(protocol,"LOCAL") ) { - workingXLOCAL=freeXLOCAL=(char *)malloc (strlen (protocol) + 1); + workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (protocol) + 1); if (workingXLOCAL) strcpy (workingXLOCAL, protocol); } @@ -1832,40 +1862,43 @@ char *protocol; XLOCAL=(char *)getenv("XLOCAL"); if(XLOCAL==NULL) XLOCAL=DEF_XLOCAL; - workingXLOCAL=freeXLOCAL=(char *)malloc (strlen (XLOCAL) + 1); + workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (XLOCAL) + 1); if (workingXLOCAL) strcpy (workingXLOCAL, XLOCAL); } } static void -TRANS(LocalEndTransports)() +TRANS(LocalEndTransports)(void) { - PRMSG(3,"TRANS(LocalEndTransports)()\n", 0,0,0 ); - free(freeXLOCAL); + PRMSG(3,"LocalEndTransports()\n", 0,0,0 ); + xfree(freeXLOCAL); } +#define TYPEBUFSIZE 32 + +#ifdef TRANS_CLIENT + static LOCALtrans2dev * -TRANS(LocalGetNextTransport)() +TRANS(LocalGetNextTransport)(void) { int i,j; char *typetocheck; -#define TYPEBUFSIZE 32 char typebuf[TYPEBUFSIZE]; - PRMSG(3,"TRANS(LocalGetNextTransport)()\n", 0,0,0 ); - + PRMSG(3,"LocalGetNextTransport()\n", 0,0,0 ); + while(1) { if( workingXLOCAL == NULL || *workingXLOCAL == '\0' ) return NULL; - + typetocheck=workingXLOCAL; workingXLOCAL=strchr(workingXLOCAL,':'); if(workingXLOCAL && *workingXLOCAL) *workingXLOCAL++='\0'; - + for(i=0;i #endif @@ -1897,9 +1930,7 @@ TRANS(LocalGetNextTransport)() */ static int -HostReallyLocal (host) - -char *host; +HostReallyLocal (char *host) { /* @@ -1929,21 +1960,15 @@ char *host; static XtransConnInfo -TRANS(LocalOpenClient)(type, protocol, host, port) - -int type; -char *protocol; -char *host; -char *port; +TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port) { - int fd = -1; LOCALtrans2dev *transptr; XtransConnInfo ciptr; int index; - PRMSG(3,"TRANS(LocalOpenClient)()\n", 0,0,0 ); - + PRMSG(3,"LocalOpenClient()\n", 0,0,0 ); + /* * Make sure 'host' is really local. If not, we return failure. * The reason we make this check is because a process may advertise @@ -1955,7 +1980,7 @@ char *port; if (strcmp (host, "unix") != 0 && !HostReallyLocal (host)) { PRMSG (1, - "TRANS(LocalOpenClient): Cannot connect to non-local host %s\n", + "LocalOpenClient: Cannot connect to non-local host %s\n", host, 0, 0); return NULL; } @@ -1972,18 +1997,18 @@ char *port; * we don't have to do anything special. */ #endif /* X11_t */ - - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + + if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { - PRMSG(1,"TRANS(LocalOpenClient)() calloc(1,%d) failed\n", + PRMSG(1,"LocalOpenClient: calloc(1,%d) failed\n", sizeof(struct _XtransConnInfo),0,0 ); return NULL; } - + ciptr->fd = -1; - + TRANS(LocalInitTransports)(protocol); - + index = 0; for(transptr=TRANS(LocalGetNextTransport)(); transptr!=NULL;transptr=TRANS(LocalGetNextTransport)(), index++) @@ -1999,29 +2024,29 @@ char *port; case XTRANS_OPEN_COTS_SERVER: case XTRANS_OPEN_CLTS_SERVER: PRMSG(1, - "TRANS(LocalOpenClient): Should not be opening a server with this function\n", + "LocalOpenClient: Should not be opening a server with this function\n", 0,0,0); break; default: PRMSG(1, - "TRANS(LocalOpenClient): Unknown Open type %d\n", + "LocalOpenClient: Unknown Open type %d\n", type, 0,0 ); } if( ciptr->fd >= 0 ) break; } - + TRANS(LocalEndTransports)(); - + if( ciptr->fd < 0 ) { - free(ciptr); + xfree(ciptr); return NULL; } - + ciptr->priv=(char *)transptr; ciptr->index = index; - + return ciptr; } @@ -2031,19 +2056,14 @@ char *port; #ifdef TRANS_SERVER static XtransConnInfo -TRANS(LocalOpenServer)(type, protocol, host, port) - -int type; -char *protocol; -char *host; -char *port; +TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port) { - int i,fd = -1; + int i; XtransConnInfo ciptr; - - PRMSG(2,"TRANS(LocalOpenServer)(%d,%s,%s)\n", type, protocol, port); - + + PRMSG(2,"LocalOpenServer(%d,%s,%s)\n", type, protocol, port); + #if defined(X11_t) /* * For X11, the port will be in the format xserverN where N is the @@ -2052,14 +2072,14 @@ char *port; * the port. This just truncates port to the display portion. */ #endif /* X11_t */ - - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + + if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { - PRMSG(1,"TRANS(LocalOpenServer)() calloc(1,%d) failed\n", + PRMSG(1,"LocalOpenServer: calloc(1,%d) failed\n", sizeof(struct _XtransConnInfo),0,0 ); return NULL; } - + for(i=1;ifd=LOCALtrans2devtab[i].devcltsopenserver(ciptr,port); break; default: - PRMSG(1,"TRANS(LocalOpenServer): Unknown Open type %d\n", + PRMSG(1,"LocalOpenServer: Unknown Open type %d\n", type ,0,0); } if( ciptr->fd >= 0 ) { ciptr->priv=(char *)&LOCALtrans2devtab[i]; ciptr->index=i; - ciptr->flags=1; + ciptr->flags = 1 | (ciptr->flags & TRANS_KEEPFLAGS); return ciptr; } } - - free(ciptr); + + xfree(ciptr); return NULL; } @@ -2100,26 +2120,21 @@ char *port; #ifdef TRANS_REOPEN static XtransConnInfo -TRANS(LocalReopenServer)(type, index, fd, port) - -int type; -int index; -int fd; -char *port; +TRANS(LocalReopenServer)(int type, int index, int fd, char *port) { XtransConnInfo ciptr; - int stat; - - PRMSG(2,"TRANS(LocalReopenServer)(%d,%d,%d)\n", type, index, fd); - - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + int stat = 0; + + PRMSG(2,"LocalReopenServer(%d,%d,%d)\n", type, index, fd); + + if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { - PRMSG(1,"TRANS(LocalReopenServer)() calloc(1,%d) failed\n", + PRMSG(1,"LocalReopenServer: calloc(1,%d) failed\n", sizeof(struct _XtransConnInfo),0,0 ); return NULL; } - + ciptr->fd = fd; switch( type ) @@ -2131,18 +2146,18 @@ char *port; stat = LOCALtrans2devtab[index].devcltsreopenserver(ciptr,fd,port); break; default: - PRMSG(1,"TRANS(LocalReopenServer): Unknown Open type %d\n", + PRMSG(1,"LocalReopenServer: Unknown Open type %d\n", type ,0,0); } if( stat > 0 ) { ciptr->priv=(char *)&LOCALtrans2devtab[index]; ciptr->index=index; - ciptr->flags=1; + ciptr->flags = 1 | (ciptr->flags & TRANS_KEEPFLAGS); return ciptr; } - - free(ciptr); + + xfree(ciptr); return NULL; } @@ -2157,16 +2172,12 @@ char *port; #ifdef TRANS_CLIENT static XtransConnInfo -TRANS(LocalOpenCOTSClient)(thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(LocalOpenCOTSClient)(Xtransport *thistrans, char *protocol, + char *host, char *port) { - PRMSG(2,"TRANS(LocalOpenCOTSClient)(%s,%s,%s)\n",protocol,host,port); - + PRMSG(2,"LocalOpenCOTSClient(%s,%s,%s)\n",protocol,host,port); + return TRANS(LocalOpenClient)(XTRANS_OPEN_COTS_CLIENT, protocol, host, port); } @@ -2176,16 +2187,41 @@ char *port; #ifdef TRANS_SERVER static XtransConnInfo -TRANS(LocalOpenCOTSServer)(thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, char *protocol, + char *host, char *port) { - PRMSG(2,"TRANS(LocalOpenCOTSServer)(%s,%s,%s)\n",protocol,host,port); - + char *typetocheck = NULL; + int found = 0; + char typebuf[TYPEBUFSIZE]; + + PRMSG(2,"LocalOpenCOTSServer(%s,%s,%s)\n",protocol,host,port); + + /* Check if this local type is in the XLOCAL list */ + TRANS(LocalInitTransports)("local"); + typetocheck = workingXLOCAL; + while (typetocheck && !found) { + int j; + + workingXLOCAL = strchr(workingXLOCAL, ':'); + if (workingXLOCAL && *workingXLOCAL) + *workingXLOCAL++ = '\0'; + strncpy(typebuf, typetocheck, TYPEBUFSIZE); + for (j = 0; j < TYPEBUFSIZE; j++) + if (isupper(typebuf[j])) + typebuf[j] = tolower(typebuf[j]); + if (!strcmp(thistrans->TransName, typebuf)) + found = 1; + typetocheck = workingXLOCAL; + } + TRANS(LocalEndTransports)(); + + if (!found) { + PRMSG(3,"LocalOpenCOTSServer: disabling %s\n",thistrans->TransName,0,0); + thistrans->flags |= TRANS_DISABLED; + return NULL; + } + return TRANS(LocalOpenServer)(XTRANS_OPEN_COTS_SERVER, protocol, host, port); } @@ -2195,16 +2231,12 @@ char *port; #ifdef TRANS_CLIENT static XtransConnInfo -TRANS(LocalOpenCLTSClient)(thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(LocalOpenCLTSClient)(Xtransport *thistrans, char *protocol, + char *host, char *port) { - PRMSG(2,"TRANS(LocalOpenCLTSClient)(%s,%s,%s)\n",protocol,host,port); - + PRMSG(2,"LocalOpenCLTSClient(%s,%s,%s)\n",protocol,host,port); + return TRANS(LocalOpenClient)(XTRANS_OPEN_CLTS_CLIENT, protocol, host, port); } @@ -2214,16 +2246,12 @@ char *port; #ifdef TRANS_SERVER static XtransConnInfo -TRANS(LocalOpenCLTSServer)(thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(LocalOpenCLTSServer)(Xtransport *thistrans, char *protocol, + char *host, char *port) { - PRMSG(2,"TRANS(LocalOpenCLTSServer)(%s,%s,%s)\n",protocol,host,port); - + PRMSG(2,"LocalOpenCLTSServer(%s,%s,%s)\n",protocol,host,port); + return TRANS(LocalOpenServer)(XTRANS_OPEN_CLTS_SERVER, protocol, host, port); } @@ -2233,24 +2261,20 @@ char *port; #ifdef TRANS_REOPEN static XtransConnInfo -TRANS(LocalReopenCOTSServer)(thistrans, fd, port) - -Xtransport *thistrans; -int fd; -char *port; +TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, char *port) { int index; - PRMSG(2,"TRANS(LocalReopenCOTSServer)(%d,%s)\n", fd, port, 0); - + PRMSG(2,"LocalReopenCOTSServer(%d,%s)\n", fd, port, 0); + for(index=1;indexTransName, LOCALtrans2devtab[index].transname) == 0 ) break; } - + if (index >= NUMTRANSPORTS) { return (NULL); @@ -2261,24 +2285,20 @@ char *port; } static XtransConnInfo -TRANS(LocalReopenCLTSServer)(thistrans, fd, port) - -Xtransport *thistrans; -int fd; -char *port; +TRANS(LocalReopenCLTSServer)(Xtransport *thistrans, int fd, char *port) { int index; - PRMSG(2,"TRANS(LocalReopenCLTSServer)(%d,%s)\n", fd, port, 0); - + PRMSG(2,"LocalReopenCLTSServer(%d,%s)\n", fd, port, 0); + for(index=1;indexTransName, LOCALtrans2devtab[index].transname) == 0 ) break; } - + if (index >= NUMTRANSPORTS) { return (NULL); @@ -2292,67 +2312,57 @@ char *port; -static -TRANS(LocalSetOption)(ciptr, option, arg) - -XtransConnInfo ciptr; -int option; -int arg; +static int +TRANS(LocalSetOption)(XtransConnInfo ciptr, int option, int arg) { - PRMSG(2,"TRANS(LocalSetOption)(%d,%d,%d)\n",ciptr->fd,option,arg); - + PRMSG(2,"LocalSetOption(%d,%d,%d)\n",ciptr->fd,option,arg); + return -1; } #ifdef TRANS_SERVER -static -TRANS(LocalCreateListener)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +static int +TRANS(LocalCreateListener)(XtransConnInfo ciptr, char *port) { - PRMSG(2,"TRANS(LocalCreateListener)(%x->%d,%s)\n",ciptr,ciptr->fd,port); - + PRMSG(2,"LocalCreateListener(%x->%d,%s)\n",ciptr,ciptr->fd,port); + return 0; } static XtransConnInfo -TRANS(LocalAccept)(ciptr, status) - -XtransConnInfo ciptr; -int *status; +TRANS(LocalAccept)(XtransConnInfo ciptr, int *status) { XtransConnInfo newciptr; LOCALtrans2dev *transptr; - - PRMSG(2,"TRANS(LocalAccept)(%x->%d)\n", ciptr, ciptr->fd,0); - + + PRMSG(2,"LocalAccept(%x->%d)\n", ciptr, ciptr->fd,0); + transptr=(LOCALtrans2dev *)ciptr->priv; - - if( (newciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo)))==NULL ) + + if( (newciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo)))==NULL ) { - PRMSG(1,"TRANS(LocalAccept)() calloc(1,%d) failed\n", + PRMSG(1,"LocalAccept: calloc(1,%d) failed\n", sizeof(struct _XtransConnInfo),0,0 ); *status = TRANS_ACCEPT_BAD_MALLOC; return NULL; } - + newciptr->fd=transptr->devaccept(ciptr,newciptr,status); - + if( newciptr->fd < 0 ) { - free(newciptr); + xfree(newciptr); return NULL; } - + newciptr->priv=(char *)transptr; newciptr->index = ciptr->index; - + *status = 0; return newciptr; @@ -2363,16 +2373,12 @@ int *status; #ifdef TRANS_CLIENT -static -TRANS(LocalConnect)(ciptr, host, port) - -XtransConnInfo ciptr; -char *host; -char *port; +static int +TRANS(LocalConnect)(XtransConnInfo ciptr, char *host, char *port) { - PRMSG(2,"TRANS(LocalConnect)(%x->%d,%s)\n", ciptr, ciptr->fd, port); - + PRMSG(2,"LocalConnect(%x->%d,%s)\n", ciptr, ciptr->fd, port); + return 0; } @@ -2380,15 +2386,12 @@ char *port; static int -TRANS(LocalBytesReadable)(ciptr, pend ) - -XtransConnInfo ciptr; -BytesReadable_t *pend; +TRANS(LocalBytesReadable)(XtransConnInfo ciptr, BytesReadable_t *pend ) { - PRMSG(2,"TRANS(LocalBytesReadable)(%x->%d,%x)\n", ciptr, ciptr->fd, pend); - -#ifdef sco + PRMSG(2,"LocalBytesReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend); + +#if defined(ISC) || defined(SCO) return ioctl(ciptr->fd, I_NREAD, (char *)pend); #else return ioctl(ciptr->fd, FIONREAD, (char *)pend); @@ -2396,82 +2399,62 @@ BytesReadable_t *pend; } static int -TRANS(LocalRead)(ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +TRANS(LocalRead)(XtransConnInfo ciptr, char *buf, int size) { - PRMSG(2,"TRANS(LocalRead)(%d,%x,%d)\n", ciptr->fd, buf, size ); - + PRMSG(2,"LocalRead(%d,%x,%d)\n", ciptr->fd, buf, size ); + return read(ciptr->fd,buf,size); } static int -TRANS(LocalWrite)(ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +TRANS(LocalWrite)(XtransConnInfo ciptr, char *buf, int size) { - PRMSG(2,"TRANS(LocalWrite)(%d,%x,%d)\n", ciptr->fd, buf, size ); - + PRMSG(2,"LocalWrite(%d,%x,%d)\n", ciptr->fd, buf, size ); + return write(ciptr->fd,buf,size); } static int -TRANS(LocalReadv)(ciptr, buf, size) - -XtransConnInfo ciptr; -struct iovec *buf; -int size; +TRANS(LocalReadv)(XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG(2,"TRANS(LocalReadv)(%d,%x,%d)\n", ciptr->fd, buf, size ); - + PRMSG(2,"LocalReadv(%d,%x,%d)\n", ciptr->fd, buf, size ); + return READV(ciptr,buf,size); } static int -TRANS(LocalWritev)(ciptr, buf, size) - -XtransConnInfo ciptr; -struct iovec *buf; -int size; +TRANS(LocalWritev)(XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG(2,"TRANS(LocalWritev)(%d,%x,%d)\n", ciptr->fd, buf, size ); - + PRMSG(2,"LocalWritev(%d,%x,%d)\n", ciptr->fd, buf, size ); + return WRITEV(ciptr,buf,size); } static int -TRANS(LocalDisconnect)(ciptr) - -XtransConnInfo ciptr; +TRANS(LocalDisconnect)(XtransConnInfo ciptr) { - PRMSG(2,"TRANS(LocalDisconnect)(%x->%d)\n", ciptr, ciptr->fd, 0); - + PRMSG(2,"LocalDisconnect(%x->%d)\n", ciptr, ciptr->fd, 0); + return 0; } static int -TRANS(LocalClose)(ciptr) - -XtransConnInfo ciptr; +TRANS(LocalClose)(XtransConnInfo ciptr) { struct sockaddr_un *sockname=(struct sockaddr_un *) ciptr->addr; char path[200]; /* > sizeof sun_path +1 */ int ret; - - PRMSG(2,"TRANS(LocalClose)(%x->%d)\n", ciptr, ciptr->fd ,0); - + + PRMSG(2,"LocalClose(%x->%d)\n", ciptr, ciptr->fd ,0); + ret=close(ciptr->fd); - + if(ciptr->flags && sockname && sockname->sun_family == AF_UNIX @@ -2479,26 +2462,25 @@ XtransConnInfo ciptr; { strncpy(path,sockname->sun_path, ciptr->addrlen-sizeof(sockname->sun_family)); - unlink(path); + if (!(ciptr->flags & TRANS_NOUNLINK)) + unlink(path); } - + return ret; } static int -TRANS(LocalCloseForCloning)(ciptr) - -XtransConnInfo ciptr; +TRANS(LocalCloseForCloning)(XtransConnInfo ciptr) { int ret; - PRMSG(2,"TRANS(LocalCloseForCloning)(%x->%d)\n", ciptr, ciptr->fd ,0); - + PRMSG(2,"LocalCloseForCloning(%x->%d)\n", ciptr, ciptr->fd ,0); + /* Don't unlink path */ ret=close(ciptr->fd); - + return ret; } @@ -2635,7 +2617,7 @@ Xtransport TRANS(NAMEDFuncs) = { }; #ifndef sun - +#ifndef SCO325 Xtransport TRANS(ISCFuncs) = { /* Local Interface */ "isc", @@ -2674,6 +2656,7 @@ Xtransport TRANS(ISCFuncs) = { TRANS(LocalClose), TRANS(LocalCloseForCloning), }; +#endif /* !SCO325 */ Xtransport TRANS(SCOFuncs) = { /* Local Interface */ "sco", diff --git a/Xtranssock.c b/Xtranssock.c index 62033c9..50098f5 100644 --- a/Xtranssock.c +++ b/Xtranssock.c @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/xtrans/Xtranssock.c,v 3.56 2002/11/26 01:12:30 dawes Exp $ */ /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * @@ -59,10 +60,6 @@ from The Open Group. #if defined(TCPCONN) || defined(UNIXCONN) #include -#else -#ifdef ESIX -#include -#endif #endif #if defined(TCPCONN) || defined(UNIXCONN) @@ -72,11 +69,17 @@ from The Open Group. #endif #ifdef UNIXCONN +#ifndef X_NO_SYS_UN +#ifndef Lynx #include +#else +#include +#endif +#endif #include #endif -#if defined(hpux) || defined(__EMX__) || (defined(MOTOROLA) && defined(SYSV)) +#if defined(hpux) || defined(__UNIXOS2__) || (defined(MOTOROLA) && defined(SYSV)) #define NO_TCP_H #endif @@ -84,19 +87,18 @@ from The Open Group. #ifdef __osf__ #include #endif /* osf */ -#if defined(__NetBSD__) || defined(__FreeBSD__) +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) #include -#endif /* __NetBSD__ || __FreeBSD__ */ +#endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ */ #include #endif /* !NO_TCP_H */ #include - -#if defined (SVR4) && !defined(SCO325) && !defined(_SEQUENT_) +#if defined(SVR4) && !defined(SCO325) && !defined(DGUX) && !defined(_SEQUENT_) #include #endif -#if (defined(i386) && defined(SYSV)) && !defined(ESIX) && !defined(sco) +#if (defined(i386) && defined(SYSV)) && !defined(sco) #include #endif @@ -126,7 +128,43 @@ from The Open Group. #undef SO_DONTLINGER #endif +#if defined(__UNIXOS2__) +#if defined(NOT_EMX09A) +static int IBMsockInit = 0; +#define SocketInitOnce()\ + if (!IBMsockInit) {\ + sock_init();\ + IBMsockInit = 1;\ + } +#undef EINTR +#define EINTR SOCEINTR +#undef EINVAL +#define EINVAL SOCEINVAL +#undef errno +#define errno sock_errno() +#undef close +#define close soclose +#undef ioctl +#define ioctl sockioctl +#else +#define SocketInitOnce() /**/ +#endif +/* this is still not there */ +#define SOCKET int +#else +/* others don't need this */ +#define SocketInitOnce() /**/ +#endif +#define MIN_BACKLOG 128 +#ifdef SOMAXCONN +#if SOMAXCONN > MIN_BACKLOG +#define BACKLOG SOMAXCONN +#endif +#endif +#ifndef BACKLOG +#define BACKLOG MIN_BACKLOG +#endif /* * This is the Socket implementation of the X Transport service layer * @@ -228,14 +266,12 @@ static Sockettrans2dev Sockettrans2devtab[] = { */ static int -TRANS(SocketSelectFamily) (family) - -char *family; +TRANS(SocketSelectFamily) (char *family) { int i; - PRMSG (3,"TRANS(SocketSelectFamily) (%s)\n", family, 0, 0); + PRMSG (3,"SocketSelectFamily(%s)\n", family, 0, 0); for (i = 0; i < NUMSOCKETFAMILIES;i++) { @@ -253,19 +289,22 @@ char *family; */ static int -TRANS(SocketINETGetAddr) (ciptr) - -XtransConnInfo ciptr; +TRANS(SocketINETGetAddr) (XtransConnInfo ciptr) { struct sockaddr_in sockname; - int namelen = sizeof sockname; +#if defined(SVR4) || defined(SCO325) + size_t namelen = sizeof sockname; +#else + int namelen = sizeof sockname; +#endif - PRMSG (3,"TRANS(SocketINETGetAddr) (%x)\n", ciptr, 0, 0); + PRMSG (3,"SocketINETGetAddr(%x)\n", ciptr, 0, 0); - if (getsockname (ciptr->fd,(struct sockaddr *) &sockname, &namelen) < 0) + if (getsockname (ciptr->fd,(struct sockaddr *) &sockname, + (void *)&namelen) < 0) { - PRMSG (1,"TRANS(SocketINETGetAddr): getsockname() failed: %d\n", + PRMSG (1,"SocketINETGetAddr: getsockname() failed: %d\n", EGET(),0, 0); return -1; } @@ -274,10 +313,10 @@ XtransConnInfo ciptr; * Everything looks good: fill in the XtransConnInfo structure. */ - if ((ciptr->addr = (char *) malloc (namelen)) == NULL) + if ((ciptr->addr = (char *) xalloc (namelen)) == NULL) { PRMSG (1, - "TRANS(SocketINETGetAddr): Can't allocate space for the addr\n", + "SocketINETGetAddr: Can't allocate space for the addr\n", 0, 0, 0); return -1; } @@ -296,19 +335,22 @@ XtransConnInfo ciptr; */ static int -TRANS(SocketINETGetPeerAddr) (ciptr) - -XtransConnInfo ciptr; +TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr) { struct sockaddr_in sockname; - int namelen = sizeof(sockname); +#if defined(SVR4) || defined(SCO325) + size_t namelen = sizeof sockname; +#else + int namelen = sizeof sockname; +#endif - PRMSG (3,"TRANS(SocketINETGetPeerAddr) (%x)\n", ciptr, 0, 0); + PRMSG (3,"SocketINETGetPeerAddr(%x)\n", ciptr, 0, 0); - if (getpeername (ciptr->fd, (struct sockaddr *) &sockname, &namelen) < 0) + if (getpeername (ciptr->fd, (struct sockaddr *) &sockname, + (void *)&namelen) < 0) { - PRMSG (1,"TRANS(SocketINETGetPeerAddr): getpeername() failed: %d\n", + PRMSG (1,"SocketINETGetPeerAddr: getpeername() failed: %d\n", EGET(), 0, 0); return -1; } @@ -317,10 +359,10 @@ XtransConnInfo ciptr; * Everything looks good: fill in the XtransConnInfo structure. */ - if ((ciptr->peeraddr = (char *) malloc (namelen)) == NULL) + if ((ciptr->peeraddr = (char *) xalloc (namelen)) == NULL) { PRMSG (1, - "TRANS(SocketINETGetPeerAddr): Can't allocate space for the addr\n", + "SocketINETGetPeerAddr: Can't allocate space for the addr\n", 0, 0, 0); return -1; } @@ -333,20 +375,17 @@ XtransConnInfo ciptr; static XtransConnInfo -TRANS(SocketOpen) (i, type) - -int i; -int type; +TRANS(SocketOpen) (int i, int type) { XtransConnInfo ciptr; - PRMSG (3,"TRANS(SocketOpen) (%d,%d)\n", i, type, 0); + PRMSG (3,"SocketOpen(%d,%d)\n", i, type, 0); - if ((ciptr = (XtransConnInfo) calloc ( + if ((ciptr = (XtransConnInfo) xcalloc ( 1, sizeof(struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(SocketOpen): malloc failed\n", 0, 0, 0); + PRMSG (1, "SocketOpen: malloc failed\n", 0, 0, 0); return NULL; } @@ -358,10 +397,10 @@ int type; #endif #endif ) { - PRMSG (1, "TRANS(SocketOpen): socket() failed for %s\n", + PRMSG (1, "SocketOpen: socket() failed for %s\n", Sockettrans2devtab[i].transname, 0, 0); - free ((char *) ciptr); + xfree ((char *) ciptr); return NULL; } @@ -385,22 +424,17 @@ int type; #ifdef TRANS_REOPEN static XtransConnInfo -TRANS(SocketReopen) (i, type, fd, port) - -int i; -int type; -int fd; -char *port; +TRANS(SocketReopen) (int i, int type, int fd, char *port) { XtransConnInfo ciptr; - PRMSG (3,"TRANS(SocketReopen) (%d,%d,%s)\n", type, fd, port); + PRMSG (3,"SocketReopen(%d,%d,%s)\n", type, fd, port); - if ((ciptr = (XtransConnInfo) calloc ( + if ((ciptr = (XtransConnInfo) xcalloc ( 1, sizeof(struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(SocketReopen): malloc failed\n", 0, 0, 0); + PRMSG (1, "SocketReopen: malloc failed\n", 0, 0, 0); return NULL; } @@ -419,24 +453,22 @@ char *port; #ifdef TRANS_CLIENT static XtransConnInfo -TRANS(SocketOpenCOTSClient) (thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; int i; - PRMSG (2, "TRANS(SocketOpenCOTSClient) (%s,%s,%s)\n", + PRMSG (2, "SocketOpenCOTSClient(%s,%s,%s)\n", protocol, host, port); + SocketInitOnce(); + if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) { PRMSG (1, - "TRANS(SocketOpenCOTSClient): Unable to determine socket type for %s\n", + "SocketOpenCOTSClient: Unable to determine socket type for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -444,7 +476,7 @@ char *port; if ((ciptr = TRANS(SocketOpen) ( i, Sockettrans2devtab[i].devcotsname)) == NULL) { - PRMSG (1,"TRANS(SocketOpenCOTSClient): Unable to open socket for %s\n", + PRMSG (1,"SocketOpenCOTSClient: Unable to open socket for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -462,23 +494,21 @@ char *port; #ifdef TRANS_SERVER static XtransConnInfo -TRANS(SocketOpenCOTSServer) (thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; int i; - PRMSG (2,"TRANS(SocketOpenCOTSServer) (%s,%s,%s)\n", protocol, host, port); + PRMSG (2,"SocketOpenCOTSServer(%s,%s,%s)\n", protocol, host, port); + + SocketInitOnce(); if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) { PRMSG (1, - "TRANS(SocketOpenCOTSServer): Unable to determine socket type for %s\n", + "SocketOpenCOTSServer: Unable to determine socket type for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -486,11 +516,15 @@ char *port; if ((ciptr = TRANS(SocketOpen) ( i, Sockettrans2devtab[i].devcotsname)) == NULL) { - PRMSG (1,"TRANS(SocketOpenCOTSServer): Unable to open socket for %s\n", + PRMSG (1,"SocketOpenCOTSServer: Unable to open socket for %s\n", thistrans->TransName, 0, 0); return NULL; } + /* + * Using this prevents the bind() check for an existing server listening + * on the same port, but it is required for other reasons. + */ #ifdef SO_REUSEADDR /* @@ -518,23 +552,21 @@ char *port; #ifdef TRANS_CLIENT static XtransConnInfo -TRANS(SocketOpenCLTSClient) (thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(SocketOpenCLTSClient) (Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; int i; - PRMSG (2,"TRANS(SocketOpenCLTSClient) (%s,%s,%s)\n", protocol, host, port); + PRMSG (2,"SocketOpenCLTSClient(%s,%s,%s)\n", protocol, host, port); + + SocketInitOnce(); if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) { PRMSG (1, - "TRANS(SocketOpenCLTSClient): Unable to determine socket type for %s\n", + "SocketOpenCLTSClient: Unable to determine socket type for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -542,7 +574,7 @@ char *port; if ((ciptr = TRANS(SocketOpen) ( i, Sockettrans2devtab[i].devcotsname)) == NULL) { - PRMSG (1,"TRANS(SocketOpenCLTSClient): Unable to open socket for %s\n", + PRMSG (1,"SocketOpenCLTSClient: Unable to open socket for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -560,23 +592,21 @@ char *port; #ifdef TRANS_SERVER static XtransConnInfo -TRANS(SocketOpenCLTSServer) (thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(SocketOpenCLTSServer) (Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; int i; - PRMSG (2,"TRANS(SocketOpenCLTSServer) (%s,%s,%s)\n", protocol, host, port); + PRMSG (2,"SocketOpenCLTSServer(%s,%s,%s)\n", protocol, host, port); + + SocketInitOnce(); if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) { PRMSG (1, - "TRANS(SocketOpenCLTSServer): Unable to determine socket type for %s\n", + "SocketOpenCLTSServer: Unable to determine socket type for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -584,7 +614,7 @@ char *port; if ((ciptr = TRANS(SocketOpen) ( i, Sockettrans2devtab[i].devcotsname)) == NULL) { - PRMSG (1,"TRANS(SocketOpenCLTSServer): Unable to open socket for %s\n", + PRMSG (1,"SocketOpenCLTSServer: Unable to open socket for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -602,23 +632,21 @@ char *port; #ifdef TRANS_REOPEN static XtransConnInfo -TRANS(SocketReopenCOTSServer) (thistrans, fd, port) - -Xtransport *thistrans; -int fd; -char *port; +TRANS(SocketReopenCOTSServer) (Xtransport *thistrans, int fd, char *port) { XtransConnInfo ciptr; int i; PRMSG (2, - "TRANS(SocketReopenCOTSServer) (%d, %s)\n", fd, port, 0); + "SocketReopenCOTSServer(%d, %s)\n", fd, port, 0); + + SocketInitOnce(); if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) { PRMSG (1, - "TRANS(SocketReopenCOTSServer): Unable to determine socket type for %s\n", + "SocketReopenCOTSServer: Unable to determine socket type for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -627,7 +655,7 @@ char *port; i, Sockettrans2devtab[i].devcotsname, fd, port)) == NULL) { PRMSG (1, - "TRANS(SocketReopenCOTSServer): Unable to reopen socket for %s\n", + "SocketReopenCOTSServer: Unable to reopen socket for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -640,24 +668,21 @@ char *port; } static XtransConnInfo -TRANS(SocketReopenCLTSServer) (thistrans, fd, port) - -Xtransport *thistrans; -int fd; -char *port; +TRANS(SocketReopenCLTSServer) (Xtransport *thistrans, int fd, char *port) { XtransConnInfo ciptr; int i; - PRMSG (2, - "TRANS(SocketReopenCLTSServer) (%d, %s)\n", fd, port, 0); + "SocketReopenCLTSServer(%d, %s)\n", fd, port, 0); + + SocketInitOnce(); if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) { PRMSG (1, - "TRANS(SocketReopenCLTSServer): Unable to determine socket type for %s\n", + "SocketReopenCLTSServer: Unable to determine socket type for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -666,7 +691,7 @@ char *port; i, Sockettrans2devtab[i].devcotsname, fd, port)) == NULL) { PRMSG (1, - "TRANS(SocketReopenCLTSServer): Unable to reopen socket for %s\n", + "SocketReopenCLTSServer: Unable to reopen socket for %s\n", thistrans->TransName, 0, 0); return NULL; } @@ -682,19 +707,14 @@ char *port; static int -TRANS(SocketSetOption) (ciptr, option, arg) - -XtransConnInfo ciptr; -int option; -int arg; +TRANS(SocketSetOption) (XtransConnInfo ciptr, int option, int arg) { - PRMSG (2,"TRANS(SocketSetOption) (%d,%d,%d)\n", ciptr->fd, option, arg); + PRMSG (2,"SocketSetOption(%d,%d,%d)\n", ciptr->fd, option, arg); return -1; } - #ifdef UNIXCONN static int set_sun_path(const char *port, const char *upath, char *path) @@ -716,23 +736,20 @@ set_sun_path(const char *port, const char *upath, char *path) } return 0; } -#endif /* UNIXCONN */ +#endif #ifdef TRANS_SERVER static int -TRANS(SocketCreateListener) (ciptr, sockname, socknamelen) - -XtransConnInfo ciptr; -struct sockaddr *sockname; -int socknamelen; +TRANS(SocketCreateListener) (XtransConnInfo ciptr, + struct sockaddr *sockname, int socknamelen) { int namelen = socknamelen; int fd = ciptr->fd; int retry; - PRMSG (3, "TRANS(SocketCreateListener) (%x,%d)\n", ciptr, fd, 0); + PRMSG (3, "SocketCreateListener(%x,%d)\n", ciptr, fd, 0); if (Sockettrans2devtab[ciptr->index].family == AF_INET) retry = 20; @@ -745,7 +762,7 @@ int socknamelen; return TRANS_ADDR_IN_USE; if (retry-- == 0) { - PRMSG (1, "TRANS(SocketCreateListener): failed to bind listener\n", + PRMSG (1, "SocketCreateListener: failed to bind listener\n", 0, 0, 0); close (fd); return TRANS_CREATE_LISTENER_FAILED; @@ -771,39 +788,39 @@ int socknamelen; #endif } - if (listen (fd, 5) < 0) + if (listen (fd, BACKLOG) < 0) { - PRMSG (1, "TRANS(SocketCreateListener): listen() failed\n", 0, 0, 0); + PRMSG (1, "SocketCreateListener: listen() failed\n", 0, 0, 0); close (fd); return TRANS_CREATE_LISTENER_FAILED; } /* Set a flag to indicate that this connection is a listener */ - ciptr->flags = 1; + ciptr->flags = 1 | (ciptr->flags & TRANS_KEEPFLAGS); return 0; } #ifdef TCPCONN static int -TRANS(SocketINETCreateListener) (ciptr, port) - -XtransConnInfo ciptr; -char *port; +TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port) { struct sockaddr_in sockname; int namelen = sizeof(sockname); int status; long tmpport; +#ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgetservbynameparams sparams; +#endif struct servent *servp; - +#ifdef X11_t char portbuf[PORTBUFSIZE]; +#endif - PRMSG (2, "TRANS(SocketINETCreateListener) (%s)\n", port, 0, 0); + PRMSG (2, "SocketINETCreateListener(%s)\n", port, 0, 0); #ifdef X11_t /* @@ -819,7 +836,7 @@ char *port; { /* fixup the server port address */ tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10); - sprintf (portbuf,"%u", tmpport); + sprintf (portbuf,"%lu", tmpport); port = portbuf; } #endif @@ -833,7 +850,7 @@ char *port; if ((servp = _XGetservbyname (port,"tcp",sparams)) == NULL) { PRMSG (1, - "TRANS(SocketINETCreateListener): Unable to get service for %s\n", + "SocketINETCreateListener: Unable to get service for %s\n", port, 0, 0); return TRANS_CREATE_LISTENER_FAILED; } @@ -868,7 +885,7 @@ char *port; (struct sockaddr *) &sockname, namelen)) < 0) { PRMSG (1, - "TRANS(SocketINETCreateListener): TRANS(SocketCreateListener) () failed\n", + "SocketINETCreateListener: ...SocketCreateListener() failed\n", 0, 0, 0); return status; } @@ -876,7 +893,7 @@ char *port; if (TRANS(SocketINETGetAddr) (ciptr) < 0) { PRMSG (1, - "TRANS(SocketINETCreateListener): TRANS(SocketINETGetAddr) () failed\n", + "SocketINETCreateListener: ...SocketINETGetAddr() failed\n", 0, 0, 0); return TRANS_CREATE_LISTENER_FAILED; } @@ -889,19 +906,17 @@ char *port; #ifdef UNIXCONN -static -TRANS(SocketUNIXCreateListener) (ciptr, port) - -XtransConnInfo ciptr; -char *port; +static int +TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port) { struct sockaddr_un sockname; int namelen; int oldUmask; int status; + unsigned int mode; - PRMSG (2, "TRANS(SocketUNIXCreateListener) (%s)\n", + PRMSG (2, "SocketUNIXCreateListener(%s)\n", port ? port : "NULL", 0, 0); /* Make sure the directory is created */ @@ -909,13 +924,17 @@ char *port; oldUmask = umask (0); #ifdef UNIX_DIR -# ifdef HAS_STICKY_DIR_BIT - if (!mkdir (UNIX_DIR, 01777)) - chmod (UNIX_DIR, 01777); -# else - if (!mkdir (UNIX_DIR, 0777)) - chmod (UNIX_DIR, 0777); -# endif +#ifdef HAS_STICKY_DIR_BIT + mode = 01777; +#else + mode = 0777; +#endif + if (trans_mkdir(UNIX_DIR, mode) == -1) { + PRMSG (1, "SocketUNIXCreateListener: mkdir(%s) failed, errno = %d\n", + UNIX_DIR, errno, 0); + (void) umask (oldUmask); + return TRANS_CREATE_LISTENER_FAILED; + } #endif sockname.sun_family = AF_UNIX; @@ -926,10 +945,10 @@ char *port; return TRANS_CREATE_LISTENER_FAILED; } } else { - sprintf (sockname.sun_path, "%s%d", UNIX_PATH, getpid()); + sprintf (sockname.sun_path, "%s%ld", UNIX_PATH, (long)getpid()); } -#ifdef BSD44SOCKETS +#if defined(BSD44SOCKETS) && !defined(Lynx) sockname.sun_len = strlen(sockname.sun_path); namelen = SUN_LEN(&sockname); #else @@ -942,8 +961,9 @@ char *port; (struct sockaddr *) &sockname, namelen)) < 0) { PRMSG (1, - "TRANS(SocketUNIXCreateListener): TRANS(SocketCreateListener) () failed\n", + "SocketUNIXCreateListener: ...SocketCreateListener() failed\n", 0, 0, 0); + (void) umask (oldUmask); return status; } @@ -956,11 +976,12 @@ char *port; namelen = sizeof (sockname); /* this will always make it the same size */ - if ((ciptr->addr = (char *) malloc (namelen)) == NULL) + if ((ciptr->addr = (char *) xalloc (namelen)) == NULL) { PRMSG (1, - "TRANS(SocketUNIXCreateListener): Can't allocate space for the addr\n", + "SocketUNIXCreateListener: Can't allocate space for the addr\n", 0, 0, 0); + (void) umask (oldUmask); return TRANS_CREATE_LISTENER_FAILED; } @@ -974,10 +995,8 @@ char *port; } -static -TRANS(SocketUNIXResetListener) (ciptr) - -XtransConnInfo ciptr; +static int +TRANS(SocketUNIXResetListener) (XtransConnInfo ciptr) { /* @@ -987,13 +1006,13 @@ XtransConnInfo ciptr; struct sockaddr_un *unsock = (struct sockaddr_un *) ciptr->addr; struct stat statb; int status = TRANS_RESET_NOOP; - void TRANS(FreeConnInfo) (); + unsigned int mode; - PRMSG (3, "TRANS(SocketUNIXResetListener) (%x,%d)\n", ciptr, ciptr->fd, 0); + PRMSG (3, "SocketUNIXResetListener(%x,%d)\n", ciptr, ciptr->fd, 0); if (stat (unsock->sun_path, &statb) == -1 || ((statb.st_mode & S_IFMT) != -#if (defined (sun) && defined(SVR4)) || defined(NCR) || defined(sco) +#if (defined (sun) && defined(SVR4)) || defined(NCR) || defined(SCO) || defined(sco) || !defined(S_IFSOCK) S_IFIFO)) #else S_IFSOCK)) @@ -1002,13 +1021,17 @@ XtransConnInfo ciptr; int oldUmask = umask (0); #ifdef UNIX_DIR -# ifdef HAS_STICKY_DIR_BIT - if (!mkdir (UNIX_DIR, 01777)) - chmod (UNIX_DIR, 01777); -# else - if (!mkdir (UNIX_DIR, 0777)) - chmod (UNIX_DIR, 0777); -# endif +#ifdef HAS_STICKY_DIR_BIT + mode = 01777; +#else + mode = 0777; +#endif + if (trans_mkdir(UNIX_DIR, mode) == -1) { + PRMSG (1, "SocketUNIXResetListener: mkdir(%s) failed, errno = %d\n", + UNIX_DIR, errno, 0); + (void) umask (oldUmask); + return TRANS_RESET_FAILURE; + } #endif close (ciptr->fd); @@ -1017,6 +1040,7 @@ XtransConnInfo ciptr; if ((ciptr->fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) { TRANS(FreeConnInfo) (ciptr); + (void) umask (oldUmask); return TRANS_RESET_FAILURE; } @@ -1027,10 +1051,11 @@ XtransConnInfo ciptr; return TRANS_RESET_FAILURE; } - if (listen (ciptr->fd, 5) < 0) + if (listen (ciptr->fd, BACKLOG) < 0) { close (ciptr->fd); TRANS(FreeConnInfo) (ciptr); + (void) umask (oldUmask); return TRANS_RESET_FAILURE; } @@ -1048,31 +1073,28 @@ XtransConnInfo ciptr; #ifdef TCPCONN static XtransConnInfo -TRANS(SocketINETAccept) (ciptr, status) - -XtransConnInfo ciptr; -int *status; +TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status) { XtransConnInfo newciptr; struct sockaddr_in sockname; int namelen = sizeof(sockname); - PRMSG (2, "TRANS(SocketINETAccept) (%x,%d)\n", ciptr, ciptr->fd, 0); + PRMSG (2, "SocketINETAccept(%x,%d)\n", ciptr, ciptr->fd, 0); - if ((newciptr = (XtransConnInfo) calloc ( + if ((newciptr = (XtransConnInfo) xcalloc ( 1, sizeof(struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(SocketINETAccept): malloc failed\n", 0, 0, 0); + PRMSG (1, "SocketINETAccept: malloc failed\n", 0, 0, 0); *status = TRANS_ACCEPT_BAD_MALLOC; return NULL; } if ((newciptr->fd = accept (ciptr->fd, - (struct sockaddr *) &sockname, &namelen)) < 0) + (struct sockaddr *) &sockname, (void *)&namelen)) < 0) { - PRMSG (1, "TRANS(SocketINETAccept): accept() failed\n", 0, 0, 0); - free (newciptr); + PRMSG (1, "SocketINETAccept: accept() failed\n", 0, 0, 0); + xfree (newciptr); *status = TRANS_ACCEPT_FAILED; return NULL; } @@ -1097,10 +1119,10 @@ int *status; if (TRANS(SocketINETGetAddr) (newciptr) < 0) { PRMSG (1, - "TRANS(SocketINETAccept): TRANS(SocketINETGetAddr) () failed:\n", + "SocketINETAccept: ...SocketINETGetAddr() failed:\n", 0, 0, 0); close (newciptr->fd); - free (newciptr); + xfree (newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; } @@ -1108,11 +1130,11 @@ int *status; if (TRANS(SocketINETGetPeerAddr) (newciptr) < 0) { PRMSG (1, - "TRANS(SocketINETAccept): TRANS(SocketINETGetPeerAddr) () failed:\n", + "SocketINETAccept: ...SocketINETGetPeerAddr() failed:\n", 0, 0, 0); close (newciptr->fd); - if (newciptr->addr) free (newciptr->addr); - free (newciptr); + if (newciptr->addr) xfree (newciptr->addr); + xfree (newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; } @@ -1127,31 +1149,32 @@ int *status; #ifdef UNIXCONN static XtransConnInfo -TRANS(SocketUNIXAccept) (ciptr, status) - -XtransConnInfo ciptr; -int *status; +TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) { XtransConnInfo newciptr; struct sockaddr_un sockname; - int namelen = sizeof(sockname); +#if defined(SVR4) || defined(SCO325) + size_t namelen = sizeof sockname; +#else + int namelen = sizeof sockname; +#endif - PRMSG (2, "TRANS(SocketUNIXAccept) (%x,%d)\n", ciptr, ciptr->fd, 0); + PRMSG (2, "SocketUNIXAccept(%x,%d)\n", ciptr, ciptr->fd, 0); - if ((newciptr = (XtransConnInfo) calloc ( + if ((newciptr = (XtransConnInfo) xcalloc ( 1, sizeof(struct _XtransConnInfo))) == NULL) { - PRMSG (1, "TRANS(SocketUNIXAccept): malloc failed\n", 0, 0, 0); + PRMSG (1, "SocketUNIXAccept: malloc() failed\n", 0, 0, 0); *status = TRANS_ACCEPT_BAD_MALLOC; return NULL; } if ((newciptr->fd = accept (ciptr->fd, - (struct sockaddr *) &sockname, &namelen)) < 0) + (struct sockaddr *) &sockname, (void *)&namelen)) < 0) { - PRMSG (1, "TRANS(SocketUNIXAccept): accept() failed\n", 0, 0, 0); - free (newciptr); + PRMSG (1, "SocketUNIXAccept: accept() failed\n", 0, 0, 0); + xfree (newciptr); *status = TRANS_ACCEPT_FAILED; return NULL; } @@ -1161,13 +1184,13 @@ int *status; * since this is unix domain. */ - if ((newciptr->addr = (char *) malloc (ciptr->addrlen)) == NULL) + if ((newciptr->addr = (char *) xalloc (ciptr->addrlen)) == NULL) { PRMSG (1, - "TRANS(SocketUNIXAccept): Can't allocate space for the addr\n", + "SocketUNIXAccept: Can't allocate space for the addr\n", 0, 0, 0); close (newciptr->fd); - free (newciptr); + xfree (newciptr); *status = TRANS_ACCEPT_BAD_MALLOC; return NULL; } @@ -1176,14 +1199,14 @@ int *status; newciptr->addrlen = ciptr->addrlen; memcpy (newciptr->addr, ciptr->addr, newciptr->addrlen); - if ((newciptr->peeraddr = (char *) malloc (ciptr->addrlen)) == NULL) + if ((newciptr->peeraddr = (char *) xalloc (ciptr->addrlen)) == NULL) { PRMSG (1, - "TRANS(SocketUNIXAccept): Can't allocate space for the addr\n", + "SocketUNIXAccept: Can't allocate space for the addr\n", 0, 0, 0); close (newciptr->fd); - if (newciptr->addr) free (newciptr->addr); - free (newciptr); + if (newciptr->addr) xfree (newciptr->addr); + xfree (newciptr); *status = TRANS_ACCEPT_BAD_MALLOC; return NULL; } @@ -1207,27 +1230,31 @@ int *status; #ifdef TCPCONN static int -TRANS(SocketINETConnect) (ciptr, host, port) - -XtransConnInfo ciptr; -char *host; -char *port; +TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port) { struct sockaddr_in sockname; - int namelen = sizeof(sockname); +#if defined(SVR4) || defined(SCO325) + size_t namelen = sizeof sockname; +#else + int namelen = sizeof sockname; +#endif +#ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgethostbynameparams hparams; _Xgetservbynameparams sparams; +#endif struct hostent *hostp; struct servent *servp; +#ifdef X11_t char portbuf[PORTBUFSIZE]; +#endif long tmpport; unsigned long tmpaddr; char hostnamebuf[256]; /* tmp space */ - PRMSG (2,"TRANS(SocketINETConnect) (%d,%s,%s)\n", ciptr->fd, host, port); + PRMSG (2,"SocketINETConnect(%d,%s,%s)\n", ciptr->fd, host, port); if (!host) { @@ -1249,7 +1276,7 @@ char *port; if (is_numeric (port)) { tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10); - sprintf (portbuf, "%u", tmpport); + sprintf (portbuf, "%lu", tmpport); port = portbuf; } #endif @@ -1275,21 +1302,21 @@ char *port; tmpaddr = -1; } - PRMSG (4,"TRANS(SocketINETConnect) inet_addr(%s) = %x\n", + PRMSG (4,"SocketINETConnect: inet_addr(%s) = %x\n", host, tmpaddr, 0); if (tmpaddr == -1) { if ((hostp = _XGethostbyname(host,hparams)) == NULL) { - PRMSG (1,"TRANS(SocketINETConnect) () can't get address for %s\n", + PRMSG (1,"SocketINETConnect: Can't get address for %s\n", host, 0, 0); ESET(EINVAL); return TRANS_CONNECT_FAILED; } if (hostp->h_addrtype != AF_INET) /* is IP host? */ { - PRMSG (1,"TRANS(SocketINETConnect) () not INET host%s\n", + PRMSG (1,"SocketINETConnect: not INET host%s\n", host, 0, 0); ESET(EPROTOTYPE); return TRANS_CONNECT_FAILED; @@ -1328,7 +1355,7 @@ else { if ((servp = _XGetservbyname (port,"tcp",sparams)) == NULL) { - PRMSG (1,"TRANS(SocketINETConnect) () can't get service for %s\n", + PRMSG (1,"SocketINETConnect: can't get service for %s\n", port, 0, 0); return TRANS_CONNECT_FAILED; } @@ -1342,7 +1369,7 @@ else sockname.sin_port = htons (((unsigned short) tmpport)); } - PRMSG (4,"TRANS(SocketINETConnect) sockname.sin_port = %d\n", + PRMSG (4,"SocketINETConnect: sockname.sin_port = %d\n", ntohs(sockname.sin_port), 0, 0); /* @@ -1374,21 +1401,28 @@ else int olderrno = errno; #endif - PRMSG (1,"TRANS(SocketINETConnect) () can't connect: errno = %d\n", - EGET(),0, 0); - /* * If the error was ECONNREFUSED, the server may be overloaded * and we should try again. * + * If the error was EWOULDBLOCK or EINPROGRESS then the socket + * was non-blocking and we should poll using select + * * If the error was EINTR, the connect was interrupted and we * should try again. */ if (olderrno == ECONNREFUSED || olderrno == EINTR) return TRANS_TRY_CONNECT_AGAIN; + else if (olderrno == EWOULDBLOCK || olderrno == EINPROGRESS) + return TRANS_IN_PROGRESS; else + { + PRMSG (2,"SocketINETConnect: Can't connect: errno = %d\n", + olderrno,0, 0); + return TRANS_CONNECT_FAILED; + } } @@ -1399,7 +1433,7 @@ else if (TRANS(SocketINETGetAddr) (ciptr) < 0) { PRMSG (1, - "TRANS(SocketINETConnect): TRANS(SocketINETGetAddr) () failed:\n", + "SocketINETConnect: ...SocketINETGetAddr() failed:\n", 0, 0, 0); return TRANS_CONNECT_FAILED; } @@ -1407,7 +1441,7 @@ else if (TRANS(SocketINETGetPeerAddr) (ciptr) < 0) { PRMSG (1, - "TRANS(SocketINETConnect): TRANS(SocketINETGetPeerAddr) () failed:\n", + "SocketINETConnect: ...SocketINETGetPeerAddr() failed:\n", 0, 0, 0); return TRANS_CONNECT_FAILED; } @@ -1426,9 +1460,7 @@ else */ static int -UnixHostReallyLocal (host) - -char *host; +UnixHostReallyLocal (char *host) { char hostnamebuf[256]; @@ -1450,7 +1482,9 @@ char *host; */ char specified_local_addr_list[10][4]; int scount, equiv, i, j; +#ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgethostbynameparams hparams; +#endif struct hostent *hostp; if ((hostp = _XGethostbyname (host,hparams)) == NULL) @@ -1512,11 +1546,7 @@ char *host; } static int -TRANS(SocketUNIXConnect) (ciptr, host, port) - -XtransConnInfo ciptr; -char *host; -char *port; +TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port) { struct sockaddr_un sockname; @@ -1528,7 +1558,7 @@ char *port; #endif - PRMSG (2,"TRANS(SocketUNIXConnect) (%d,%s,%s)\n", ciptr->fd, host, port); + PRMSG (2,"SocketUNIXConnect(%d,%s,%s)\n", ciptr->fd, host, port); /* * Make sure 'host' is really local. If not, we return failure. @@ -1541,7 +1571,7 @@ char *port; if (strcmp (host, "unix") != 0 && !UnixHostReallyLocal (host)) { PRMSG (1, - "TRANS(SocketUNIXConnect): Cannot connect to non-local host %s\n", + "SocketUNIXConnect: Cannot connect to non-local host %s\n", host, 0, 0); return TRANS_CONNECT_FAILED; } @@ -1553,7 +1583,7 @@ char *port; if (!port || !*port) { - PRMSG (1,"TRANS(SocketUNIXConnect): Missing port specification\n", + PRMSG (1,"SocketUNIXConnect: Missing port specification\n", 0, 0, 0); return TRANS_CONNECT_FAILED; } @@ -1569,7 +1599,7 @@ char *port; return TRANS_CONNECT_FAILED; } -#ifdef BSD44SOCKETS +#if defined(BSD44SOCKETS) && !defined(Lynx) sockname.sun_len = strlen (sockname.sun_path); namelen = SUN_LEN (&sockname); #else @@ -1582,10 +1612,9 @@ char *port; * This is gross, but it was in Xlib */ old_sockname.sun_family = AF_UNIX; - if (*port == '/') { /* a full pathname */ - sprintf (old_sockname.sun_path, "%s", port); - } else { - sprintf (old_sockname.sun_path, "%s%s", OLD_UNIX_PATH, port); + if (set_sun_path(port, OLD_UNIX_PATH, old_sockname.sun_path) != 0) { + PRMSG (1, "SocketUNIXConnect: path too long\n", 0, 0, 0); + return TRANS_CONNECT_FAILED; } old_namelen = strlen (old_sockname.sun_path) + sizeof (old_sockname.sun_family); @@ -1617,13 +1646,28 @@ char *port; { errno = olderrno; - PRMSG (1,"TRANS(SocketUNIXConnect) () can't connect: errno = %d\n", - EGET(),0, 0); + /* + * If the error was ENOENT, the server may be starting up + * and we should try again. + * + * If the error was EWOULDBLOCK or EINPROGRESS then the socket + * was non-blocking and we should poll using select + * + * If the error was EINTR, the connect was interrupted and we + * should try again. + */ if (olderrno == ENOENT || olderrno == EINTR) return TRANS_TRY_CONNECT_AGAIN; + else if (olderrno == EWOULDBLOCK || olderrno == EINPROGRESS) + return TRANS_IN_PROGRESS; else + { + PRMSG (2,"SocketUNIXConnect: Can't connect: errno = %d\n", + EGET(),0, 0); + return TRANS_CONNECT_FAILED; + } } } @@ -1632,11 +1676,11 @@ char *port; * since this is unix domain. */ - if ((ciptr->addr = (char *) malloc(namelen)) == NULL || - (ciptr->peeraddr = (char *) malloc(namelen)) == NULL) + if ((ciptr->addr = (char *) xalloc(namelen)) == NULL || + (ciptr->peeraddr = (char *) xalloc(namelen)) == NULL) { PRMSG (1, - "TRANS(SocketUNIXCreateListener): Can't allocate space for the addr\n", + "SocketUNIXCreateListener: Can't allocate space for the addr\n", 0, 0, 0); return TRANS_CONNECT_FAILED; } @@ -1656,38 +1700,37 @@ char *port; static int -TRANS(SocketBytesReadable) (ciptr, pend) - -XtransConnInfo ciptr; -BytesReadable_t *pend; +TRANS(SocketBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend) { - PRMSG (2,"TRANS(SocketBytesReadable) (%x,%d,%x)\n", + PRMSG (2,"SocketBytesReadable(%x,%d,%x)\n", ciptr, ciptr->fd, pend); - +#if defined(QNX4) + *pend = 0L; /* FIONREAD only returns a short. Zero out upper bits */ +#endif #ifdef WIN32 return ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend); #else #if (defined(i386) && defined(SYSV) && !defined(sco)) || (defined(_SEQUENT_) && _SOCKET_VERSION == 1) return ioctl (ciptr->fd, I_NREAD, (char *) pend); +#else +#if defined(__UNIXOS2__) + return ioctl (ciptr->fd, FIONREAD, (char*) pend, sizeof(int)); #else return ioctl (ciptr->fd, FIONREAD, (char *) pend); +#endif /* __UNIXOS2__ */ #endif /* i386 && SYSV || _SEQUENT_ && _SOCKET_VERSION == 1 */ #endif /* WIN32 */ } static int -TRANS(SocketRead) (ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +TRANS(SocketRead) (XtransConnInfo ciptr, char *buf, int size) { - PRMSG (2,"TRANS(SocketRead) (%d,%x,%d)\n", ciptr->fd, buf, size); + PRMSG (2,"SocketRead(%d,%x,%d)\n", ciptr->fd, buf, size); -#ifdef WIN32 +#if defined(WIN32) || defined(__UNIXOS2__) return recv ((SOCKET)ciptr->fd, buf, size, 0); #else return read (ciptr->fd, buf, size); @@ -1696,16 +1739,12 @@ int size; static int -TRANS(SocketWrite) (ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +TRANS(SocketWrite) (XtransConnInfo ciptr, char *buf, int size) { - PRMSG (2,"TRANS(SocketWrite) (%d,%x,%d)\n", ciptr->fd, buf, size); + PRMSG (2,"SocketWrite(%d,%x,%d)\n", ciptr->fd, buf, size); -#ifdef WIN32 +#if defined(WIN32) || defined(__UNIXOS2__) return send ((SOCKET)ciptr->fd, buf, size, 0); #else return write (ciptr->fd, buf, size); @@ -1714,40 +1753,30 @@ int size; static int -TRANS(SocketReadv) (ciptr, buf, size) - -XtransConnInfo ciptr; -struct iovec *buf; -int size; +TRANS(SocketReadv) (XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG (2,"TRANS(SocketReadv) (%d,%x,%d)\n", ciptr->fd, buf, size); + PRMSG (2,"SocketReadv(%d,%x,%d)\n", ciptr->fd, buf, size); return READV (ciptr, buf, size); } static int -TRANS(SocketWritev) (ciptr, buf, size) - -XtransConnInfo ciptr; -struct iovec *buf; -int size; +TRANS(SocketWritev) (XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG (2,"TRANS(SocketWritev) (%d,%x,%d)\n", ciptr->fd, buf, size); + PRMSG (2,"SocketWritev(%d,%x,%d)\n", ciptr->fd, buf, size); return WRITEV (ciptr, buf, size); } static int -TRANS(SocketDisconnect) (ciptr) - -XtransConnInfo ciptr; +TRANS(SocketDisconnect) (XtransConnInfo ciptr) { - PRMSG (2,"TRANS(SocketDisconnect) (%x,%d)\n", ciptr, ciptr->fd, 0); + PRMSG (2,"SocketDisconnect(%x,%d)\n", ciptr, ciptr->fd, 0); return shutdown (ciptr->fd, 2); /* disallow further sends and receives */ } @@ -1755,12 +1784,10 @@ XtransConnInfo ciptr; #ifdef TCPCONN static int -TRANS(SocketINETClose) (ciptr) - -XtransConnInfo ciptr; +TRANS(SocketINETClose) (XtransConnInfo ciptr) { - PRMSG (2,"TRANS(SocketINETClose) (%x,%d)\n", ciptr, ciptr->fd, 0); + PRMSG (2,"SocketINETClose(%x,%d)\n", ciptr, ciptr->fd, 0); return close (ciptr->fd); } @@ -1770,9 +1797,7 @@ XtransConnInfo ciptr; #ifdef UNIXCONN static int -TRANS(SocketUNIXClose) (ciptr) - -XtransConnInfo ciptr; +TRANS(SocketUNIXClose) (XtransConnInfo ciptr) { /* @@ -1784,7 +1809,7 @@ XtransConnInfo ciptr; char path[200]; /* > sizeof sun_path +1 */ int ret; - PRMSG (2,"TRANS(SocketUNIXClose) (%x,%d)\n", ciptr, ciptr->fd, 0); + PRMSG (2,"SocketUNIXClose(%x,%d)\n", ciptr, ciptr->fd, 0); ret = close(ciptr->fd); @@ -1795,16 +1820,15 @@ XtransConnInfo ciptr; { strncpy (path, sockname->sun_path, ciptr->addrlen - sizeof (sockname->sun_family)); - unlink (path); + if (!(ciptr->flags & TRANS_NOUNLINK)) + unlink (path); } return ret; } static int -TRANS(SocketUNIXCloseForCloning) (ciptr) - -XtransConnInfo ciptr; +TRANS(SocketUNIXCloseForCloning) (XtransConnInfo ciptr) { /* @@ -1813,7 +1837,7 @@ XtransConnInfo ciptr; int ret; - PRMSG (2,"TRANS(SocketUNIXCloseForCloning) (%x,%d)\n", + PRMSG (2,"SocketUNIXCloseForCloning(%x,%d)\n", ciptr, ciptr->fd, 0); ret = close(ciptr->fd); diff --git a/Xtranstli.c b/Xtranstli.c index b7daf70..e189323 100644 --- a/Xtranstli.c +++ b/Xtranstli.c @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/xtrans/Xtranstli.c,v 3.11 2002/12/15 01:28:33 dawes Exp $ */ /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * @@ -121,18 +122,16 @@ static TLItrans2dev TLItrans2devtab[] = { */ static int -TRANS(TLISelectFamily)(family) - -char *family; +TRANS(TLISelectFamily)(char *family) { int i; - PRMSG(3,"TRANS(TLISelectFamily)(%s)\n", family, 0,0 ); + PRMSG(3,"TLISelectFamily(%s)\n", family, 0,0 ); for(i=0;ifd,&netbuf,LOCALNAME) < 0 ) { - PRMSG(1,"TRANS(TLIGetAddr): t_getname(LOCALNAME) failed: %d\n", + PRMSG(1,"TLIGetAddr: t_getname(LOCALNAME) failed: %d\n", errno, 0,0 ); return -1; } - PRMSG(4,"TRANS(TLIGetAddr): got family %d len %d\n", + PRMSG(4,"TLIGetAddr: got family %d len %d\n", ((struct sockaddr *) &sockname)->sa_family ,netbuf.len, 0 ); /* @@ -174,13 +171,13 @@ XtransConnInfo ciptr; */ if( ciptr->addr ) - free(ciptr->addr); + xfree(ciptr->addr); - if( (ciptr->addr=(char *)malloc(netbuf.len)) == NULL ) + if( (ciptr->addr=(char *)xalloc(netbuf.len)) == NULL ) { - PRMSG(1, "TRANS(TLIGetAddr): Can't allocate space for the addr\n", + PRMSG(1, "TLIGetAddr: Can't allocate space for the addr\n", 0,0,0); - return -1; + return -1; } ciptr->family=((struct sockaddr *) &sockname)->sa_family; @@ -197,15 +194,13 @@ XtransConnInfo ciptr; */ static int -TRANS(TLIGetPeerAddr)(ciptr) - -XtransConnInfo ciptr; +TRANS(TLIGetPeerAddr)(XtransConnInfo ciptr) { Xtransaddr sockname; struct netbuf netbuf; - PRMSG(3,"TRANS(TLIGetPeerAddr)(%x)\n", ciptr, 0,0 ); + PRMSG(3,"TLIGetPeerAddr(%x)\n", ciptr, 0,0 ); netbuf.buf=(char *)&sockname; netbuf.len=sizeof(sockname); @@ -213,12 +208,12 @@ XtransConnInfo ciptr; if( t_getname(ciptr->fd,&netbuf,REMOTENAME) < 0 ) { - PRMSG(1,"TRANS(TLIGetPeerAddr): t_getname(REMOTENAME) failed: %d\n", + PRMSG(1,"TLIGetPeerAddr: t_getname(REMOTENAME) failed: %d\n", errno, 0,0 ); return -1; } - PRMSG(4,"TRANS(TLIGetPeerAddr): got family %d len %d\n", + PRMSG(4,"TLIGetPeerAddr: got family %d len %d\n", ((struct sockaddr *) &sockname)->sa_family ,netbuf.len, 0 ); /* @@ -226,14 +221,14 @@ XtransConnInfo ciptr; */ if( ciptr->peeraddr ) - free(ciptr->peeraddr); + xfree(ciptr->peeraddr); - if( (ciptr->peeraddr=(char *)malloc(netbuf.len)) == NULL ) + if( (ciptr->peeraddr=(char *)xalloc(netbuf.len)) == NULL ) { - PRMSG(1, - "TRANS(TLIGetPeerAddr): Can't allocate space for the addr\n", + PRMSG(1, + "TLIGetPeerAddr: Can't allocate space for the addr\n", 0,0,0); - return -1; + return -1; } ciptr->peeraddrlen=netbuf.len; @@ -254,24 +249,20 @@ XtransConnInfo ciptr; */ static int -TRANS(TLITLIBindLocal)(fd,family,port) - -int fd; -int family; -char *port; +TRANS(TLITLIBindLocal)(int fd, int family, char *port) { struct sockaddr_un *sunaddr=NULL; struct t_bind *req=NULL; - PRMSG(2, "TRANS(TLITLIBindLocal)(%d,%d,%s)\n", fd, family, port); + PRMSG(2, "TLITLIBindLocal(%d,%d,%s)\n", fd, family, port); if( family == AF_UNIX ) { - if( (req=(struct t_bind *)t_alloc(fd,T_BIND,T_OPT|T_UDATA)) == NULL ) + if( (req=(struct t_bind *)t_alloc(fd,T_BIND,0)) == NULL ) { PRMSG(1, - "TRANS(TLITLIBindLocal)() failed to allocate a t_bind\n", + "TLITLIBindLocal() failed to allocate a t_bind\n", 0,0,0 ); return -1; } @@ -280,7 +271,7 @@ char *port; malloc(sizeof(struct sockaddr_un))) == NULL ) { PRMSG(1, - "TRANS(TLITLIBindLocal): failed to allocate a sockaddr_un\n", + "TLITLIBindLocal: failed to allocate a sockaddr_un\n", 0,0,0 ); t_free((char *)req,T_BIND); return -1; @@ -299,7 +290,7 @@ char *port; (void) sprintf(sunaddr->sun_path,"%s%d", TLINODENAME, getpid()^time(NULL) ); - PRMSG(4, "TRANS(TLITLIBindLocal): binding to %s\n", + PRMSG(4, "TLITLIBindLocal: binding to %s\n", sunaddr->sun_path, 0,0); req->addr.buf=(char *)sunaddr; @@ -310,7 +301,7 @@ char *port; if( t_bind(fd, req, NULL) < 0 ) { PRMSG(1, - "TRANS(TLIBindLocal): Unable to bind TLI device to %s\n", + "TLIBindLocal: Unable to bind TLI device to %s\n", port, 0,0 ); if (sunaddr) free((char *) sunaddr); @@ -322,24 +313,22 @@ char *port; } static XtransConnInfo -TRANS(TLIOpen)(device) - -char *device; +TRANS(TLIOpen)(char *device) { XtransConnInfo ciptr; - PRMSG(3,"TRANS(TLIOpen)(%s)\n", device, 0,0 ); + PRMSG(3,"TLIOpen(%s)\n", device, 0,0 ); - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { - PRMSG(1, "TRANS(TLIOpen): calloc failed\n", 0,0,0 ); + PRMSG(1, "TLIOpen: calloc failed\n", 0,0,0 ); return NULL; } if( (ciptr->fd=t_open( device, O_RDWR, NULL )) < 0 ) { - PRMSG(1, "TRANS(TLIOpen): t_open failed for %s\n", device, 0,0 ); + PRMSG(1, "TLIOpen: t_open failed for %s\n", device, 0,0 ); free(ciptr); return NULL; } @@ -351,26 +340,22 @@ char *device; #ifdef TRANS_REOPEN static XtransConnInfo -TRANS(TLIReopen)(device, fd, port) - -char *device; -int fd; -char *port; +TRANS(TLIReopen)(char *device, int fd, char *port) { XtransConnInfo ciptr; - PRMSG(3,"TRANS(TLIReopen)(%s,%d, %s)\n", device, fd, port ); + PRMSG(3,"TLIReopen(%s,%d, %s)\n", device, fd, port ); if (t_sync (fd) < 0) { - PRMSG(1, "TRANS(TLIReopen): t_sync failed\n", 0,0,0 ); + PRMSG(1, "TLIReopen: t_sync failed\n", 0,0,0 ); return NULL; } - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { - PRMSG(1, "TRANS(TLIReopen): calloc failed\n", 0,0,0 ); + PRMSG(1, "TLIReopen: calloc failed\n", 0,0,0 ); return NULL; } @@ -383,12 +368,8 @@ char *port; static int -TRANS(TLIAddrToNetbuf)(tlifamily, host, port, netbufp) - -int tlifamily; -char *host; -char *port; -struct netbuf *netbufp; +TRANS(TLIAddrToNetbuf)(int tlifamily, char *host, char *port, + struct netbuf *netbufp) { struct netconfig *netconfigp; @@ -397,7 +378,7 @@ struct netbuf *netbufp; void *handlep; long lport; - PRMSG(3,"TRANS(TLIAddrToNetbuf)(%d,%s,%s)\n", tlifamily, host, port ); + PRMSG(3,"TLIAddrToNetbuf(%d,%s,%s)\n", tlifamily, host, port ); if( (handlep=setnetconfig()) == NULL ) return -1; @@ -418,14 +399,14 @@ struct netbuf *netbufp; if( strcmp(netconfigp->nc_protofmly, TLItrans2devtab[tlifamily].protofamily) != 0 ) continue; - PRMSG(5,"Trying to resolve %s.%s for %s\n", + PRMSG(5,"TLIAddrToNetbuf: Trying to resolve %s.%s for %s\n", host, port, TLItrans2devtab[tlifamily].protofamily ); if( netdir_getbyname(netconfigp,&nd_hostserv, &nd_addrlistp) == 0 ) { /* we have at least one address to use */ - PRMSG(5, "found address for %s.%s\n", host, port, 0 ); - PRMSG(5, "%s\n",taddr2uaddr(netconfigp,nd_addrlistp->n_addrs), + PRMSG(5, "TLIAddrToNetbuf: found address for %s.%s\n", host, port, 0 ); + PRMSG(5, "TLIAddrToNetbuf: %s\n",taddr2uaddr(netconfigp,nd_addrlistp->n_addrs), 0,0 ); memcpy(netbufp->buf,nd_addrlistp->n_addrs->buf, @@ -447,29 +428,25 @@ struct netbuf *netbufp; #ifdef TRANS_CLIENT static XtransConnInfo -TRANS(TLIOpenCOTSClient)(thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(TLIOpenCOTSClient)(Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; int i; - PRMSG(2,"TRANS(TLIOpenCOTSClient)(%s,%s,%s)\n", protocol, host, port ); + PRMSG(2,"TLIOpenCOTSClient(%s,%s,%s)\n", protocol, host, port ); if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 ) { - PRMSG(1,"TRANS(TLIOpenCOTSClient): Unable to determine device for %s\n", + PRMSG(1,"TLIOpenCOTSClient: Unable to determine device for %s\n", thistrans->TransName, 0,0 ); return NULL; } if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL ) { - PRMSG(1,"TRANS(TLIOpenCOTSClient): Unable to open device for %s\n", + PRMSG(1,"TLIOpenCOTSClient: Unable to open device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -477,20 +454,20 @@ char *port; if( TRANS(TLITLIBindLocal)(ciptr->fd,TLItrans2devtab[i].family,port) < 0 ) { PRMSG(1, - "TRANS(TLIOpenCOTSClient): TRANS(TLITLIBindLocal)() failed: %d\n", + "TLIOpenCOTSClient: ...TLITLIBindLocal() failed: %d\n", errno, 0,0 ); t_close(ciptr->fd); - free(ciptr); + xfree(ciptr); return NULL; } if( TRANS(TLIGetAddr)(ciptr) < 0 ) { PRMSG(1, - "TRANS(TLIOpenCOTSClient): TRANS(TLIGetAddr)() failed: %d\n", + "TLIOpenCOTSClient: ...TLIGetAddr() failed: %d\n", errno, 0,0 ); t_close(ciptr->fd); - free(ciptr); + xfree(ciptr); return NULL; } @@ -506,23 +483,19 @@ char *port; #ifdef TRANS_SERVER static XtransConnInfo -TRANS(TLIOpenCOTSServer)(thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(TLIOpenCOTSServer)(Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; int i; - PRMSG(2,"TRANS(TLIOpenCOTSServer)(%s,%s,%s)\n", protocol, host, port ); + PRMSG(2,"TLIOpenCOTSServer(%s,%s,%s)\n", protocol, host, port ); if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 ) { PRMSG(1, - "TRANS(TLIOpenCOTSServer): Unable to determine device for %s\n", + "TLIOpenCOTSServer: Unable to determine device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -530,7 +503,7 @@ char *port; if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL ) { PRMSG(1, - "TRANS(TLIOpenCOTSServer): Unable to open device for %s\n", + "TLIOpenCOTSServer: Unable to open device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -553,23 +526,19 @@ char *port; #ifdef TRANS_CLIENT static XtransConnInfo -TRANS(TLIOpenCLTSClient)(thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(TLIOpenCLTSClient)(Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; int i; - PRMSG(2,"TRANS(TLIOpenCLTSClient)(%s,%s,%s)\n", protocol, host, port ); + PRMSG(2,"TLIOpenCLTSClient(%s,%s,%s)\n", protocol, host, port ); if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 ) { PRMSG(1, - "TRANS(TLIOpenCLTSClient): Unable to determine device for %s\n", + "TLIOpenCLTSClient: Unable to determine device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -577,7 +546,7 @@ char *port; if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcltsname)) == NULL ) { PRMSG(1, - "TRANS(TLIOpenCLTSClient): Unable to open device for %s\n", + "TLIOpenCLTSClient: Unable to open device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -585,20 +554,20 @@ char *port; if( TRANS(TLITLIBindLocal)(ciptr->fd,TLItrans2devtab[i].family,port) < 0 ) { PRMSG(1, - "TRANS(TLIOpenCLTSClient): TRANS(TLITLIBindLocal)() failed: %d\n", + "TLIOpenCLTSClient: ...TLITLIBindLocal() failed: %d\n", errno, 0,0 ); t_close(ciptr->fd); - free(ciptr); + xfree(ciptr); return NULL; } if( TRANS(TLIGetAddr)(ciptr) < 0 ) { PRMSG(1, - "TRANS(TLIOpenCLTSClient): TRANS(TLIGetPeerAddr)() failed: %d\n", + "TLIOpenCLTSClient: ...TLIGetPeerAddr() failed: %d\n", errno, 0,0 ); t_close(ciptr->fd); - free(ciptr); + xfree(ciptr); return NULL; } @@ -611,23 +580,19 @@ char *port; #ifdef TRANS_SERVER static XtransConnInfo -TRANS(TLIOpenCLTSServer)(thistrans, protocol, host, port) - -Xtransport *thistrans; -char *protocol; -char *host; -char *port; +TRANS(TLIOpenCLTSServer)(Xtransport *thistrans, char *protocol, + char *host, char *port) { XtransConnInfo ciptr; int i; - PRMSG(2,"TRANS(TLIOpenCLTSServer)(%s,%s,%s)\n", protocol, host, port ); + PRMSG(2,"TLIOpenCLTSServer(%s,%s,%s)\n", protocol, host, port ); if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 ) { PRMSG(1, - "TRANS(TLIOpenCLTSServer): Unable to determine device for %s\n", + "TLIOpenCLTSServer: Unable to determine device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -635,7 +600,7 @@ char *port; if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcltsname)) == NULL ) { PRMSG(1, - "TRANS(TLIOpenCLTSServer): Unable to open device for %s\n", + "TLIOpenCLTSServer: Unable to open device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -649,22 +614,18 @@ char *port; #ifdef TRANS_REOPEN static XtransConnInfo -TRANS(TLIReopenCOTSServer)(thistrans, fd, port) - -Xtransport *thistrans; -int fd; -char *port; +TRANS(TLIReopenCOTSServer)(Xtransport *thistrans, int fd, char *port) { XtransConnInfo ciptr; int i; - PRMSG(2,"TRANS(TLIReopenCOTSServer)(%d, %s)\n", fd, port, 0 ); + PRMSG(2,"TLIReopenCOTSServer(%d, %s)\n", fd, port, 0 ); if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 ) { PRMSG(1, - "TRANS(TLIReopenCOTSServer): Unable to determine device for %s\n", + "TLIReopenCOTSServer: Unable to determine device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -673,7 +634,7 @@ char *port; TLItrans2devtab[i].devcotsname, fd, port)) == NULL ) { PRMSG(1, - "TRANS(TLIReopenCOTSServer): Unable to open device for %s\n", + "TLIReopenCOTSServer: Unable to open device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -687,22 +648,18 @@ char *port; static XtransConnInfo -TRANS(TLIReopenCLTSServer)(thistrans, fd, port) - -Xtransport *thistrans; -int fd; -char *port; +TRANS(TLIReopenCLTSServer)(Xtransport *thistrans, int fd, char *port) { XtransConnInfo ciptr; int i; - PRMSG(2,"TRANS(TLIReopenCLTSServer)(%d, %s)\n", fd, port, 0 ); + PRMSG(2,"TLIReopenCLTSServer(%d, %s)\n", fd, port, 0 ); if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 ) { PRMSG(1, - "TRANS(TLIReopenCLTSServer): Unable to determine device for %s\n", + "TLIReopenCLTSServer: Unable to determine device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -711,7 +668,7 @@ char *port; TLItrans2devtab[i].devcltsname, fd, port)) == NULL ) { PRMSG(1, - "TRANS(TLIReopenCLTSServer): Unable to open device for %s\n", + "TLIReopenCLTSServer: Unable to open device for %s\n", thistrans->TransName, 0,0 ); return NULL; } @@ -724,15 +681,11 @@ char *port; #endif /* TRANS_REOPEN */ -static -TRANS(TLISetOption)(ciptr, option, arg) - -XtransConnInfo ciptr; -int option; -int arg; +static int +TRANS(TLISetOption)(XtransConnInfo ciptr, int option, int arg) { - PRMSG(2,"TRANS(TLISetOption)(%d,%d,%d)\n", ciptr->fd, option, arg ); + PRMSG(2,"TLISetOption(%d,%d,%d)\n", ciptr->fd, option, arg ); return -1; } @@ -740,20 +693,17 @@ int arg; #ifdef TRANS_SERVER -static -TRANS(TLICreateListener)(ciptr, req) - -XtransConnInfo ciptr; -struct t_bind *req; +static int +TRANS(TLICreateListener)(XtransConnInfo ciptr, struct t_bind *req) { struct t_bind *ret; - PRMSG(2,"TRANS(TLICreateListener)(%x->%d,%x)\n", ciptr, ciptr->fd, req ); + PRMSG(2,"TLICreateListener(%x->%d,%x)\n", ciptr, ciptr->fd, req ); if( (ret=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,T_ALL)) == NULL ) { - PRMSG(1, "TRANS(TLICreateListener): failed to allocate a t_bind\n", + PRMSG(1, "TLICreateListener: failed to allocate a t_bind\n", 0,0,0 ); t_free((char *)req,T_BIND); return TRANS_CREATE_LISTENER_FAILED; @@ -761,7 +711,7 @@ struct t_bind *req; if( t_bind(ciptr->fd, req, ret) < 0 ) { - PRMSG(1, "TRANS(TLICreateListener): t_bind failed\n", 0,0,0 ); + PRMSG(1, "TLICreateListener: t_bind failed\n", 0,0,0 ); t_free((char *)req,T_BIND); t_free((char *)ret,T_BIND); return TRANS_CREATE_LISTENER_FAILED; @@ -769,7 +719,7 @@ struct t_bind *req; if( memcmp(req->addr.buf,ret->addr.buf,req->addr.len) != 0 ) { - PRMSG(1, "TRANS(TLICreateListener): unable to bind to %x\n", + PRMSG(1, "TLICreateListener: unable to bind to %x\n", req, 0,0 ); t_free((char *)req,T_BIND); t_free((char *)ret,T_BIND); @@ -780,10 +730,10 @@ struct t_bind *req; * Everything looks good: fill in the XtransConnInfo structure. */ - if( (ciptr->addr=(char *)malloc(ret->addr.len)) == NULL ) + if( (ciptr->addr=(char *)xalloc(ret->addr.len)) == NULL ) { PRMSG(1, - "TRANS(TLICreateListener): Unable to allocate space for the address\n", + "TLICreateListener: Unable to allocate space for the address\n", 0,0,0 ); t_free((char *)req,T_BIND); t_free((char *)ret, T_BIND); @@ -800,11 +750,8 @@ struct t_bind *req; } -static -TRANS(TLIINETCreateListener)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +static int +TRANS(TLIINETCreateListener)(XtransConnInfo ciptr, char *port) { char portbuf[PORTBUFSIZE]; @@ -812,7 +759,7 @@ char *port; struct sockaddr_in *sinaddr; long tmpport; - PRMSG(2,"TRANS(TLIINETCreateListener)(%x->%d,%s)\n", ciptr, + PRMSG(2,"TLIINETCreateListener(%x->%d,%s)\n", ciptr, ciptr->fd, port ? port : "NULL" ); #ifdef X11_t @@ -836,7 +783,7 @@ char *port; if( (req=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,T_ALL)) == NULL ) { PRMSG(1, - "TRANS(TLIINETCreateListener): failed to allocate a t_bind\n", + "TLIINETCreateListener: failed to allocate a t_bind\n", 0,0,0 ); return TRANS_CREATE_LISTENER_FAILED; } @@ -845,7 +792,7 @@ char *port; if(TRANS(TLIAddrToNetbuf)(ciptr->index,HOST_SELF,port,&(req->addr)) < 0) { PRMSG(1, - "TRANS(TLIINETCreateListener): can't resolve name:HOST_SELF.%s\n", + "TLIINETCreateListener: can't resolve name:HOST_SELF.%s\n", port, 0,0 ); t_free((char *)req,T_BIND); return TRANS_CREATE_LISTENER_FAILED; @@ -865,24 +812,21 @@ char *port; } -static -TRANS(TLITLICreateListener)(ciptr, port) - -XtransConnInfo ciptr; -char *port; +static int +TRANS(TLITLICreateListener)(XtransConnInfo ciptr, char *port) { struct t_bind *req; struct sockaddr_un *sunaddr; int ret_value; - PRMSG(2,"TRANS(TLITLICreateListener)(%x->%d,%s)\n", ciptr, ciptr->fd, + PRMSG(2,"TLITLICreateListener(%x->%d,%s)\n", ciptr, ciptr->fd, port ? port : "NULL"); - if( (req=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,T_OPT|T_UDATA)) == NULL ) + if( (req=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,0)) == NULL ) { PRMSG(1, - "TRANS(TLITLICreateListener): failed to allocate a t_bind\n", + "TLITLICreateListener: failed to allocate a t_bind\n", 0,0,0 ); return TRANS_CREATE_LISTENER_FAILED; } @@ -891,7 +835,7 @@ char *port; malloc(sizeof(struct sockaddr_un))) == NULL ) { PRMSG(1, - "TRANS(TLITLICreateListener): failed to allocate a sockaddr_un\n", + "TLITLICreateListener: failed to allocate a sockaddr_un\n", 0,0,0 ); t_free((char *)req,T_BIND); return TRANS_CREATE_LISTENER_FAILED; @@ -925,21 +869,18 @@ char *port; static XtransConnInfo -TRANS(TLIAccept)(ciptr, status) - -XtransConnInfo ciptr; -int *status; +TRANS(TLIAccept)(XtransConnInfo ciptr, int *status) { struct t_call *call; XtransConnInfo newciptr; int i; - PRMSG(2,"TRANS(TLIAccept)(%x->%d)\n", ciptr, ciptr->fd, 0 ); + PRMSG(2,"TLIAccept(%x->%d)\n", ciptr, ciptr->fd, 0 ); if( (call=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_ALL)) == NULL ) { - PRMSG(1, "TRANS(TLIAccept)() failed to allocate a t_call\n", 0,0,0 ); + PRMSG(1, "TLIAccept() failed to allocate a t_call\n", 0,0,0 ); *status = TRANS_ACCEPT_BAD_MALLOC; return NULL; } @@ -948,8 +889,8 @@ int *status; { extern char *t_errlist[]; extern int t_errno; - PRMSG(1, "TRANS(TLIAccept)() t_listen() failed\n", 0,0,0 ); - PRMSG(1, "%s\n", t_errlist[t_errno], 0,0 ); + PRMSG(1, "TLIAccept() t_listen() failed\n", 0,0,0 ); + PRMSG(1, "TLIAccept: %s\n", t_errlist[t_errno], 0,0 ); t_free((char *)call,T_CALL); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; @@ -963,7 +904,7 @@ int *status; if( (newciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL ) { - PRMSG(1, "TRANS(TLIAccept)() failed to open a new endpoint\n", 0,0,0 ); + PRMSG(1, "TLIAccept() failed to open a new endpoint\n", 0,0,0 ); t_free((char *)call,T_CALL); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; @@ -972,11 +913,11 @@ int *status; if( TRANS(TLITLIBindLocal)(newciptr->fd,TLItrans2devtab[i].family,"") < 0 ) { PRMSG(1, - "TRANS(TLIAccept): TRANS(TLITLIBindLocal)() failed: %d\n", + "TLIAccept: TRANS(TLITLIBindLocal)() failed: %d\n", errno, 0,0 ); t_free((char *)call,T_CALL); t_close(newciptr->fd); - free(newciptr); + xfree(newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; } @@ -986,8 +927,25 @@ int *status; { extern char *t_errlist[]; extern int t_errno; - PRMSG(1, "TRANS(TLIAccept)() t_accept() failed\n", 0,0,0 ); - PRMSG(1, "%s\n", t_errlist[t_errno], 0,0 ); + PRMSG(1, "TLIAccept() t_accept() failed\n", 0,0,0 ); + PRMSG(1, "TLIAccept: %s\n", t_errlist[t_errno], 0,0 ); + if( t_errno == TLOOK ) + { + int evtype = t_look(ciptr->fd); + PRMSG(1, "TLIAccept() t_look() returned %d\n", evtype,0,0 ); + switch( evtype ) + { + case T_DISCONNECT: + if( t_rcvdis(ciptr->fd, NULL) < 0 ) + { + PRMSG(1, "TLIAccept() t_rcvdis() failed\n", 0,0,0 ); + PRMSG(1, "TLIAccept: %s\n", t_errlist[t_errno], 0,0 ); + } + break; + default: + break; + } + } t_free((char *)call,T_CALL); t_close(newciptr->fd); free(newciptr); @@ -1000,10 +958,10 @@ int *status; if( TRANS(TLIGetAddr)(newciptr) < 0 ) { PRMSG(1, - "TRANS(TLIAccept): TRANS(TLIGetAddr)() failed: %d\n", + "TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n", errno, 0,0 ); t_close(newciptr->fd); - free(newciptr); + xfree(newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; } @@ -1011,33 +969,33 @@ int *status; if( TRANS(TLIGetPeerAddr)(newciptr) < 0 ) { PRMSG(1, - "TRANS(TLIAccept): TRANS(TLIGetPeerAddr)() failed: %d\n", + "TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n", errno, 0,0 ); t_close(newciptr->fd); - free(newciptr->addr); - free(newciptr); + xfree(newciptr->addr); + xfree(newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; } if( ioctl(newciptr->fd, I_POP,"timod") < 0 ) { - PRMSG(1, "TRANS(TLIAccept)() ioctl(I_POP, \"timod\") failed %d\n", + PRMSG(1, "TLIAccept() ioctl(I_POP, \"timod\") failed %d\n", errno,0,0 ); t_close(newciptr->fd); - free(newciptr->addr); - free(newciptr); + xfree(newciptr->addr); + xfree(newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; } if( ioctl(newciptr->fd, I_PUSH,"tirdwr") < 0 ) { - PRMSG(1, "TRANS(TLIAccept)() ioctl(I_PUSH,\"tirdwr\") failed %d\n", + PRMSG(1, "TLIAccept() ioctl(I_PUSH,\"tirdwr\") failed %d\n", errno,0,0 ); t_close(newciptr->fd); - free(newciptr->addr); - free(newciptr); + xfree(newciptr->addr); + xfree(newciptr); *status = TRANS_ACCEPT_MISC_ERROR; return NULL; } @@ -1052,21 +1010,18 @@ int *status; #ifdef TRANS_CLIENT -static -TRANS(TLIConnect)(ciptr, sndcall ) - -XtransConnInfo ciptr; -struct t_call *sndcall; +static int +TRANS(TLIConnect)(XtransConnInfo ciptr, struct t_call *sndcall ) { - PRMSG(2, "TRANS(TLIConnect)(%x->%d,%x)\n", ciptr, ciptr->fd, sndcall); + PRMSG(2, "TLIConnect(%x->%d,%x)\n", ciptr, ciptr->fd, sndcall); if( t_connect(ciptr->fd,sndcall,NULL) < 0 ) { extern char *t_errlist[]; extern int t_errno; - PRMSG(1, "TRANS(TLIConnect)() t_connect() failed\n", 0,0,0 ); - PRMSG(1, "%s\n", t_errlist[t_errno], 0,0 ); + PRMSG(1, "TLIConnect() t_connect() failed\n", 0,0,0 ); + PRMSG(1, "TLIConnect: %s\n", t_errlist[t_errno], 0,0 ); t_free((char *)sndcall,T_CALL); if (t_errno == TLOOK && t_look(ciptr->fd) == T_DISCONNECT) { @@ -1086,7 +1041,7 @@ struct t_call *sndcall; if( TRANS(TLIGetAddr)(ciptr) < 0 ) { PRMSG(1, - "TRANS(TLIConnect): TRANS(TLIGetAddr)() failed: %d\n", + "TLIConnect: ...TLIGetAddr() failed: %d\n", errno, 0,0 ); return TRANS_CONNECT_FAILED; } @@ -1094,21 +1049,21 @@ struct t_call *sndcall; if( TRANS(TLIGetPeerAddr)(ciptr) < 0 ) { PRMSG(1, - "TRANS(TLIConnect): TRANS(TLIGetPeerAddr)() failed: %d\n", + "TLIConnect: ...TLIGetPeerAddr() failed: %d\n", errno, 0,0 ); return TRANS_CONNECT_FAILED; } if( ioctl(ciptr->fd, I_POP,"timod") < 0 ) { - PRMSG(1, "TRANS(TLIConnect)() ioctl(I_POP,\"timod\") failed %d\n", + PRMSG(1, "TLIConnect() ioctl(I_POP,\"timod\") failed %d\n", errno,0,0 ); return TRANS_CONNECT_FAILED; } if( ioctl(ciptr->fd, I_PUSH,"tirdwr") < 0 ) { - PRMSG(1, "TRANS(TLIConnect)() ioctl(I_PUSH,\"tirdwr\") failed %d\n", + PRMSG(1, "TLIConnect() ioctl(I_PUSH,\"tirdwr\") failed %d\n", errno,0,0 ); return TRANS_CONNECT_FAILED; } @@ -1117,19 +1072,15 @@ struct t_call *sndcall; } -static -TRANS(TLIINETConnect)(ciptr, host, port) - -XtransConnInfo ciptr; -char *host; -char *port; +static int +TRANS(TLIINETConnect)(XtransConnInfo ciptr, char *host, char *port) { char portbuf[PORTBUFSIZE]; struct t_call *sndcall; long tmpport; - PRMSG(2, "TRANS(TLIINETConnect)(%s,%s)\n", host, port, 0); + PRMSG(2, "TLIINETConnect(%s,%s)\n", host, port, 0); #ifdef X11_t /* @@ -1151,13 +1102,13 @@ char *port; if( (sndcall=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_ALL)) == NULL ) { - PRMSG(1, "TRANS(TLIINETConnect)() failed to allocate a t_call\n", 0,0,0 ); + PRMSG(1, "TLIINETConnect() failed to allocate a t_call\n", 0,0,0 ); return TRANS_CONNECT_FAILED; } if( TRANS(TLIAddrToNetbuf)(ciptr->index, host, port, &(sndcall->addr) ) < 0 ) { - PRMSG(1, "TRANS(TLIINETConnect)() unable to resolve name:%s.%s\n", + PRMSG(1, "TLIINETConnect() unable to resolve name:%s.%s\n", host, port, 0 ); t_free((char *)sndcall,T_CALL); return TRANS_CONNECT_FAILED; @@ -1167,23 +1118,19 @@ char *port; } -static -TRANS(TLITLIConnect)(ciptr, host, port) - -XtransConnInfo ciptr; -char *host; -char *port; +static int +TRANS(TLITLIConnect)(XtransConnInfo ciptr, char *host, char *port) { struct t_call *sndcall; struct sockaddr_un *sunaddr; int ret_value; - PRMSG(2, "TRANS(TLITLIConnect)(%s,%s)\n", host, port, 0); + PRMSG(2, "TLITLIConnect(%s,%s)\n", host, port, 0); if( (sndcall=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_OPT|T_UDATA)) == NULL ) { - PRMSG(1, "TRANS(TLITLIConnect)() failed to allocate a t_call\n", 0,0,0 ); + PRMSG(1, "TLITLIConnect() failed to allocate a t_call\n", 0,0,0 ); return TRANS_CONNECT_FAILED; } @@ -1191,7 +1138,7 @@ char *port; malloc(sizeof(struct sockaddr_un))) == NULL ) { PRMSG(1, - "TRANS(TLITLIConnect): failed to allocate a sockaddr_un\n", + "TLITLIConnect: failed to allocate a sockaddr_un\n", 0,0,0 ); t_free((char *)sndcall,T_CALL); return TRANS_CONNECT_FAILED; @@ -1220,17 +1167,14 @@ char *port; #endif /* TRANS_CLIENT */ -static -TRANS(TLIBytesReadable)(ciptr, pend) - -XtransConnInfo ciptr; -BytesReadable_t *pend; +static int +TRANS(TLIBytesReadable)(XtransConnInfo ciptr, BytesReadable_t *pend) { int ret; struct pollfd filedes; - PRMSG(2, "TRANS(TLIByteReadable)(%x->%d,%x)\n", ciptr, ciptr->fd, pend ); + PRMSG(2, "TLIByteReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend ); /* * This function should detect hangup conditions. Use poll to check @@ -1268,69 +1212,51 @@ BytesReadable_t *pend; } -static -TRANS(TLIRead)(ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +static int +TRANS(TLIRead)(XtransConnInfo ciptr, char *buf, int size) { - PRMSG(2, "TRANS(TLIRead)(%d,%x,%d)\n", ciptr->fd, buf, size ); + PRMSG(2, "TLIRead(%d,%x,%d)\n", ciptr->fd, buf, size ); return read(ciptr->fd,buf,size); } -static -TRANS(TLIWrite)(ciptr, buf, size) - -XtransConnInfo ciptr; -char *buf; -int size; +static int +TRANS(TLIWrite)(XtransConnInfo ciptr, char *buf, int size) { - PRMSG(2, "TRANS(TLIWrite)(%d,%x,%d)\n", ciptr->fd, buf, size ); + PRMSG(2, "TLIWrite(%d,%x,%d)\n", ciptr->fd, buf, size ); return write(ciptr->fd,buf,size); } -static -TRANS(TLIReadv)(ciptr, buf, size) - -XtransConnInfo ciptr; -struct iovec *buf; -int size; +static int +TRANS(TLIReadv)(XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG(2, "TRANS(TLIReadv)(%d,%x,%d)\n", ciptr->fd, buf, size ); + PRMSG(2, "TLIReadv(%d,%x,%d)\n", ciptr->fd, buf, size ); return READV(ciptr,buf,size); } -static -TRANS(TLIWritev)(ciptr, buf, size) - -XtransConnInfo ciptr; -struct iovec *buf; -int size; +static int +TRANS(TLIWritev)(XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG(2, "TRANS(TLIWritev)(%d,%x,%d)\n", ciptr->fd, buf, size ); + PRMSG(2, "TLIWritev(%d,%x,%d)\n", ciptr->fd, buf, size ); return WRITEV(ciptr,buf,size); } -static -TRANS(TLIDisconnect)(ciptr) - -XtransConnInfo ciptr; +static int +TRANS(TLIDisconnect)(XtransConnInfo ciptr) { - PRMSG(2, "TRANS(TLIDisconnect)(%x->%d)\n", ciptr, ciptr->fd, 0 ); + PRMSG(2, "TLIDisconnect(%x->%d)\n", ciptr, ciptr->fd, 0 ); /* * Restore the TLI modules so that the connection can be properly shutdown. @@ -1346,13 +1272,11 @@ XtransConnInfo ciptr; } -static -TRANS(TLIClose)(ciptr) - -XtransConnInfo ciptr; +static int +TRANS(TLIClose)(XtransConnInfo ciptr) { - PRMSG(2, "TRANS(TLIClose)(%x->%d)\n", ciptr, ciptr->fd, 0 ); + PRMSG(2, "TLIClose(%x->%d)\n", ciptr, ciptr->fd, 0 ); t_unbind(ciptr->fd); @@ -1360,17 +1284,15 @@ XtransConnInfo ciptr; } -static -TRANS(TLICloseForCloning)(ciptr) - -XtransConnInfo ciptr; +static int +TRANS(TLICloseForCloning)(XtransConnInfo ciptr) { /* * Don't unbind. */ - PRMSG(2, "TRANS(TLICloseForCloning)(%x->%d)\n", ciptr, ciptr->fd, 0 ); + PRMSG(2, "TLICloseForCloning(%x->%d)\n", ciptr, ciptr->fd, 0 ); return (t_close(ciptr->fd)); } @@ -1379,7 +1301,7 @@ XtransConnInfo ciptr; Xtransport TRANS(TLITCPFuncs) = { /* TLI Interface */ "tcp", - 0, + 0, #ifdef TRANS_CLIENT TRANS(TLIOpenCOTSClient), #endif /* TRANS_CLIENT */ diff --git a/Xtransutil.c b/Xtransutil.c index e2809b3..7130d99 100644 --- a/Xtransutil.c +++ b/Xtransutil.c @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/xtrans/Xtransutil.c,v 3.23 2003/02/12 15:01:38 alanh Exp $ */ /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * @@ -85,13 +86,11 @@ from The Open Group. */ int -TRANS(ConvertAddress)(familyp,addrlenp,addrp) -int *familyp; -int *addrlenp; -Xtransaddr **addrp; +TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp) + { - PRMSG(2,"TRANS(ConvertAddress)(%d,%d,%x)\n",*familyp,*addrlenp,*addrp); + PRMSG(2,"ConvertAddress(%d,%d,%x)\n",*familyp,*addrlenp,*addrp); switch( *familyp ) { @@ -156,23 +155,9 @@ Xtransaddr **addrp; } #endif /* defined(UNIXCONN) || defined(LOCALCONN) */ -#if defined(AMRPCCONN) - case AF_AMOEBA: - { - *familyp=FamilyAmoeba; - break; - } -#endif -#if defined(AMTCPCONN) && !(defined(TCPCONN) || defined(STREAMSCONN)) - case AF_INET: - { - *familyp=FamilyInternet; - break; - } -#endif default: - PRMSG(1,"TRANS(ConvertFamily) Unknown family type %d\n", + PRMSG(1,"ConvertAddress: Unknown family type %d\n", *familyp, 0,0 ); return -1; } @@ -191,11 +176,11 @@ Xtransaddr **addrp; if (len > 0) { if (*addrp && *addrlenp < (len + 1)) { - free ((char *) *addrp); + xfree ((char *) *addrp); *addrp = NULL; } if (!*addrp) - *addrp = (Xtransaddr *) malloc (len + 1); + *addrp = (Xtransaddr *) xalloc (len + 1); if (*addrp) { strcpy ((char *) *addrp, hostnamebuf); *addrlenp = len; @@ -206,7 +191,7 @@ Xtransaddr **addrp; else { if (*addrp) - free ((char *) *addrp); + xfree ((char *) *addrp); *addrp = NULL; *addrlenp = 0; } @@ -222,13 +207,10 @@ Xtransaddr **addrp; #include char * -TRANS(GetMyNetworkId) (ciptr) - -XtransConnInfo ciptr; +TRANS(GetMyNetworkId) (XtransConnInfo ciptr) { int family = ciptr->family; - int addrlen = ciptr->addrlen; char *addr = ciptr->addr; char hostnamebuf[256]; char *networkId = NULL; @@ -245,7 +227,7 @@ XtransConnInfo ciptr; case AF_UNIX: { struct sockaddr_un *saddr = (struct sockaddr_un *) addr; - networkId = (char *) malloc (3 + strlen (transName) + + networkId = (char *) xalloc (3 + strlen (transName) + strlen (hostnamebuf) + strlen (saddr->sun_path)); sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, saddr->sun_path); @@ -260,7 +242,7 @@ XtransConnInfo ciptr; char portnumbuf[10]; sprintf (portnumbuf, "%d", ntohs (saddr->sin_port)); - networkId = (char *) malloc (3 + strlen (transName) + + networkId = (char *) xalloc (3 + strlen (transName) + strlen (hostnamebuf) + strlen (portnumbuf)); sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf); break; @@ -272,7 +254,7 @@ XtransConnInfo ciptr; { struct sockaddr_dn *saddr = (struct sockaddr_dn *) addr; - networkId = (char *) malloc ( + networkId = (char *) xalloc ( 13 + strlen (hostnamebuf) + saddr->sdn_objnamel); sprintf (networkId, "dnet/%s::%s", hostnamebuf, saddr->sdn_objname); @@ -299,7 +281,7 @@ int #else void #endif -nameserver_lost(sig) +nameserver_lost(int sig) { nameserver_timedout = 1; longjmp (env, -1); @@ -312,16 +294,12 @@ nameserver_lost(sig) char * -TRANS(GetPeerNetworkId) (ciptr) - -XtransConnInfo ciptr; +TRANS(GetPeerNetworkId) (XtransConnInfo ciptr) { int family = ciptr->family; - int peer_addrlen = ciptr->peeraddrlen; char *peer_addr = ciptr->peeraddr; char *hostname; - char *networkId = NULL; char addrbuf[256]; char *addr = NULL; @@ -341,12 +319,10 @@ XtransConnInfo ciptr; case AF_INET: { struct sockaddr_in *saddr = (struct sockaddr_in *) peer_addr; +#ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgethostbynameparams hparams; - struct hostent * hostp; - -#ifndef WIN32 - char *inet_ntoa(); #endif + struct hostent * volatile hostp = NULL; #ifdef SIGALRM /* @@ -394,31 +370,12 @@ XtransConnInfo ciptr; } #endif /* defined(DNETCONN) */ -#if defined(AMRPCCONN) - case AF_AMOEBA: - { - addr = "Amoeba"; /* not really used */ - break; - } -#endif -#if defined(AMTCPCONN) && !(defined(TCPCONN) || defined(STREAMSCONN)) - case AF_INET: - { - if (gethostname (addrbuf, sizeof (addrbuf)) == 0) { - addr = addrbuf; - } else { - addr = ""; - } - break; - } -#endif - default: return (NULL); } - hostname = (char *) malloc ( + hostname = (char *) xalloc ( strlen (ciptr->transptr->TransName) + strlen (addr) + 2); strcpy (hostname, ciptr->transptr->TransName); strcat (hostname, "/"); @@ -433,11 +390,11 @@ XtransConnInfo ciptr; #if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN)) int -TRANS(WSAStartup) () +TRANS(WSAStartup) (void) { static WSADATA wsadata; - PRMSG (2,"TRANS(WSAStartup)()\n", 0, 0, 0); + PRMSG (2,"WSAStartup()\n", 0, 0, 0); if (!wsadata.wVersion && WSAStartup(MAKEWORD(1,1), &wsadata)) return 1; @@ -447,9 +404,7 @@ TRANS(WSAStartup) () static int -is_numeric (str) - -char *str; +is_numeric (char *str) { int i; @@ -460,3 +415,104 @@ char *str; return (1); } + +#ifdef TRANS_SERVER +#include +#include +#include + +#if !defined(S_IFLNK) && !defined(S_ISLNK) +#define lstat(a,b) stat(a,b) +#endif + +static int +trans_mkdir(char *path, int mode) +{ + struct stat buf; + + if (mkdir(path, mode) == 0) { + chmod(path, mode); + return 0; + } + /* If mkdir failed with EEXIST, test if it is a directory with + the right modes, else fail */ + if (errno == EEXIST) { + if (lstat(path, &buf) != 0) { + PRMSG(1, "mkdir: (l)stat failed for %s (%d)\n", + path, errno, 0); + return -1; + } + if (S_ISDIR(buf.st_mode)) { + int updateOwner = 0; + int updateMode = 0; + int updatedOwner = 0; + int updatedMode = 0; + /* Check if the directory's ownership is OK. */ + if (buf.st_uid != 0) + updateOwner = 1; + /* + * Check if the directory's mode is OK. An exact match isn't + * required, just a mode that isn't more permissive than the + * one requested. + */ + if ((~mode) & 0077 & buf.st_mode) + updateMode = 1; + if ((mode & 01000) && + (buf.st_mode & 0002) && !(buf.st_mode & 01000)) + updateMode = 1; +#ifdef HAS_FCHOWN + /* + * If fchown(2) and fchmod(2) are available, try to correct the + * directory's owner and mode. Otherwise it isn't safe to attempt + * to do this. + */ + if (updateMode || updateOwner) { + int fd = -1; + struct stat fbuf; + if ((fd = open(path, O_RDONLY)) != -1) { + if (fstat(fd, &fbuf) == -1) { + PRMSG(1, "mkdir: fstat failed for %s (%d)\n", + path, errno, 0); + return -1; + } + /* + * Verify that we've opened the same directory as was + * checked above. + */ + if (!S_ISDIR(fbuf.st_mode) || + buf.st_dev != fbuf.st_dev || + buf.st_ino != fbuf.st_ino) { + PRMSG(1, "mkdir: inode for %s changed\n", + path, 0, 0); + return -1; + } + if (updateOwner && fchown(fd, 0, 0) == 0) + updatedOwner = 1; + if (updateMode && fchmod(fd, mode) == 0) + updatedMode = 1; + close(fd); + } + } +#endif + if (updateOwner && !updatedOwner) { + PRMSG(1, "mkdir: Owner of %s should be set to root\n", + path, 0, 0); +#if !defined(__CYGWIN__) + sleep(5); +#endif + } + if (updateMode && !updatedMode) { + PRMSG(1, "mkdir: Mode of %s should be set to %04o\n", + path, mode, 0); +#if !defined(__CYGWIN__) + sleep(5); +#endif + } + return 0; + } + } + /* In all other cases, fail */ + return -1; +} + +#endif /* TRANS_SERVER */ diff --git a/transport.c b/transport.c index be46eca..3cc7149 100644 --- a/transport.c +++ b/transport.c @@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/xtrans/transport.c,v 3.9 2002/05/31 18:45:51 dawes Exp $ */ /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * @@ -50,6 +51,16 @@ from The Open Group. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef XSERV_t +#include "os.h" +#else +#include +#define xalloc(_size) malloc(_size) +#define xcalloc(_num,_size) calloc(_num,_size) +#define xrealloc(_ptr,_size) realloc(_ptr,_size) +#define xfree(_ptr) free(_ptr) +#endif + #include "Xtransint.h" #ifdef DNETCONN @@ -64,8 +75,5 @@ from The Open Group. #ifdef STREAMSCONN #include "Xtranstli.c" #endif -#if defined(AMRPCCONN) || defined(AMTCPCONN) -#include "Xtransam.c" -#endif #include "Xtrans.c" #include "Xtransutil.c" -- cgit v1.2.3