diff options
author | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:48:50 +0000 |
---|---|---|
committer | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:48:50 +0000 |
commit | 3bd236a07c0ebaabb7337dd5d56bc57a028a9c0e (patch) | |
tree | 4b89b1daf6c5cde1f7f5c59939745d235583cfb3 /Xtranslcl.c | |
parent | 26781c4f009a4b448dca3ab4912cbf01182e3d92 (diff) |
XFree86 4.3.0.1xf86-4_3_0_1PRE_xf86-4_3_0_1
Diffstat (limited to 'Xtranslcl.c')
-rw-r--r-- | Xtranslcl.c | 1165 |
1 files changed, 574 insertions, 591 deletions
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 <sys/signal.h> #include <sys/ioctl.h> #include <sys/stat.h> -#if 0 -#include <sys/ptms.h> /* Maybe for SVR4 only?? */ -#endif -#ifdef SVR4 +#if defined(SVR4) +#if !defined(DGUX) #include <sys/filio.h> +#else /* DGUX */ +#include <sys/stream.h> +#include <sys/ptms.h> +#endif #endif #include <sys/stropts.h> #include <sys/wait.h> @@ -96,8 +99,14 @@ from The Open Group. */ #include <sys/socket.h> +#ifndef X_NO_SYS_UN #include <sys/un.h> +#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<NUMTRANSPORTS;i++) { /* @@ -1876,18 +1909,18 @@ TRANS(LocalGetNextTransport)() for(j=0;j<TYPEBUFSIZE;j++) if (isupper(typebuf[j])) typebuf[j]=tolower(typebuf[j]); - + /* Now, see if they match */ if(!strcmp(LOCALtrans2devtab[i].transname,typebuf)) return &LOCALtrans2devtab[i]; } } +#if 0 /*NOTREACHED*/ return NULL; +#endif } -#ifdef TRANS_CLIENT - #ifdef NEED_UTSNAME #include <sys/utsname.h> #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;i<NUMTRANSPORTS;i++) { if( strcmp(protocol,LOCALtrans2devtab[i].transname) != 0 ) @@ -2069,7 +2089,7 @@ char *port; case XTRANS_OPEN_COTS_CLIENT: case XTRANS_OPEN_CLTS_CLIENT: PRMSG(1, - "TRANS(LocalOpenServer): Should not be opening a client with this function\n", + "LocalOpenServer: Should not be opening a client with this function\n", 0,0,0); break; case XTRANS_OPEN_COTS_SERVER: @@ -2079,18 +2099,18 @@ char *port; ciptr->fd=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;index<NUMTRANSPORTS;index++) { if( strcmp(thistrans->TransName, 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;index<NUMTRANSPORTS;index++) { if( strcmp(thistrans->TransName, 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", |