diff options
Diffstat (limited to 'nx-X11/lib/xtrans/Xtranslcl.c')
-rw-r--r-- | nx-X11/lib/xtrans/Xtranslcl.c | 1223 |
1 files changed, 478 insertions, 745 deletions
diff --git a/nx-X11/lib/xtrans/Xtranslcl.c b/nx-X11/lib/xtrans/Xtranslcl.c index f504338aa..7231d2a83 100644 --- a/nx-X11/lib/xtrans/Xtranslcl.c +++ b/nx-X11/lib/xtrans/Xtranslcl.c @@ -24,9 +24,7 @@ not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. -*/ - -/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA * * All Rights Reserved * @@ -51,7 +49,7 @@ from The Open Group. /* * - * The connection code/ideas in lib/X and server/os for SVR4/Intel + * The connection code/ideas in lib/X and server/os for SVR4/Intel * environments was contributed by the following companies/groups: * * MetroLink Inc @@ -63,12 +61,12 @@ from The Open Group. * * The goal is to have common connection code among all SVR4/Intel vendors. * - * ALL THE ABOVE COMPANIES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, - * IN NO EVENT SHALL THESE COMPANIES * BE LIABLE FOR ANY SPECIAL, INDIRECT - * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE + * ALL THE ABOVE COMPANIES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, + * IN NO EVENT SHALL THESE COMPANIES * BE LIABLE FOR ANY SPECIAL, INDIRECT + * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE * OR PERFORMANCE OF THIS SOFTWARE. */ @@ -77,15 +75,14 @@ from The Open Group. #include <sys/signal.h> #include <sys/ioctl.h> #include <sys/stat.h> -#if defined(SVR4) -#if !defined(DGUX) +#if defined(SVR4) || defined(__SVR4) #include <sys/filio.h> -#else /* DGUX */ -#include <sys/stream.h> -#include <sys/ptms.h> -#endif #endif +#ifdef __sun +# include <stropts.h> +#else #include <sys/stropts.h> +#endif #include <sys/wait.h> #include <sys/types.h> @@ -101,10 +98,23 @@ from The Open Group. #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 */ + +/* Types of local connections supported: + * - PTS + * - named pipes + * - SCO + */ +#if !defined(__sun) +# define LOCAL_TRANS_PTS #endif +#if defined(SVR4) || defined(__SVR4) +# define LOCAL_TRANS_NAMED +#endif +#if defined(__SCO__) || defined(__UNIXWARE__) +# define LOCAL_TRANS_SCO +#endif + +static int TRANS(LocalClose)(XtransConnInfo ciptr); /* * These functions actually implement the local connection mechanisms. @@ -113,7 +123,7 @@ typedef unsigned short mode_t; /* Type Not Supported */ static int -TRANS(OpenFail)(XtransConnInfo ciptr, char *port) +TRANS(OpenFail)(XtransConnInfo ciptr _X_UNUSED, const char *port _X_UNUSED) { return -1; @@ -122,7 +132,8 @@ TRANS(OpenFail)(XtransConnInfo ciptr, char *port) #ifdef TRANS_REOPEN static int -TRANS(ReopenFail)(XtransConnInfo ciptr, int fd, char *port) +TRANS(ReopenFail)(XtransConnInfo ciptr _X_UNUSED, int fd _X_UNUSED, + const char *port _X_UNUSED) { return 0; @@ -130,10 +141,26 @@ TRANS(ReopenFail)(XtransConnInfo ciptr, int fd, char *port) #endif /* TRANS_REOPEN */ +#if XTRANS_SEND_FDS +static int +TRANS(LocalRecvFdInvalid)(XtransConnInfo ciptr) +{ + errno = EINVAL; + return -1; +} + +static int +TRANS(LocalSendFdInvalid)(XtransConnInfo ciptr, int fd, int do_close) +{ + errno = EINVAL; + return -1; +} +#endif static int -TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path) +TRANS(FillAddrInfo)(XtransConnInfo ciptr, + const char *sun_path, const char *peer_sun_path) { struct sockaddr_un *sunaddr; @@ -142,20 +169,21 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, 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 = malloc (ciptr->addrlen)) == NULL) { - PRMSG(1,"FillAddrInfo: failed to allocate memory for addr\n", 0, 0, 0); + prmsg(1,"FillAddrInfo: failed to allocate memory for addr\n"); 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); + prmsg(1, "FillAddrInfo: path too long\n"); + free((char *) sunaddr); return 0; } strcpy (sunaddr->sun_path, sun_path); -#if defined(BSD44SOCKETS) && !defined(Lynx) +#if defined(BSD44SOCKETS) sunaddr->sun_len = strlen (sunaddr->sun_path); #endif @@ -163,13 +191,11 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path) ciptr->peeraddrlen = sizeof (struct sockaddr_un); - if ((p_sunaddr = (struct sockaddr_un *) malloc ( - ciptr->peeraddrlen)) == NULL) + if ((p_sunaddr = malloc (ciptr->peeraddrlen)) == NULL) { - PRMSG(1, - "FillAddrInfo: failed to allocate memory for peer addr\n", - 0,0,0); - free ((char *) sunaddr); + prmsg(1, + "FillAddrInfo: failed to allocate memory for peer addr\n"); + free (sunaddr); ciptr->addr = NULL; return 0; @@ -178,11 +204,12 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, 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); + prmsg(1, "FillAddrInfo: peer path too long\n"); + free((char *) p_sunaddr); return 0; } strcpy (p_sunaddr->sun_path, peer_sun_path); -#if defined(BSD44SOCKETS) && !defined(Lynx) +#if defined(BSD44SOCKETS) p_sunaddr->sun_len = strlen (p_sunaddr->sun_path); #endif @@ -193,9 +220,10 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path) +#ifdef LOCAL_TRANS_PTS /* PTS */ -#if defined(SYSV) && !defined(__SCO__) && !defined(ISC) +#if defined(SYSV) && !defined(__SCO__) #define SIGNAL_T int #else #define SIGNAL_T void @@ -209,12 +237,13 @@ extern char *ptsname( int ); -static void _dummy(int sig) +static void _dummy(int sig _X_UNUSED) { } +#endif /* LOCAL_TRANS_PTS */ -#ifndef sun +#ifndef __sun #define X_STREAMS_DIR "/dev/X" #define DEV_SPX "/dev/spx" #else @@ -225,39 +254,34 @@ static void _dummy(int sig) #endif #endif -#ifdef _AIX -#define DEV_PTMX "/dev/ptc" -#else #define DEV_PTMX "/dev/ptmx" -#endif #if defined(X11_t) #define PTSNODENAME "/dev/X/server." -#ifndef sun -#define NAMEDNODENAME "/dev/X/Nserver." -#else +#ifdef __sun #define NAMEDNODENAME "/tmp/.X11-pipe/X" -#endif - -/* - * ISC is only defined for X11 since they are there for - * backwards binary compatability only. - */ +#else +#define NAMEDNODENAME "/dev/X/Nserver." -#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" #define SCOSNODENAME "/dev/X%1sS" +#endif /* !__sun */ #endif #if defined(XIM_t) +#ifdef __sun +#define NAMEDNODENAME "/tmp/.XIM-pipe/XIM" +#else #define PTSNODENAME "/dev/X/XIM." #define NAMEDNODENAME "/dev/X/NXIM." #define SCORNODENAME "/dev/XIM.%sR" #define SCOSNODENAME "/dev/XIM.%sS" #endif +#endif #if defined(FS_t) || defined (FONT_t) +#ifdef __sun +#define NAMEDNODENAME "/tmp/.font-pipe/fs" +#else /* * USL has already defined something here. We need to check with them * and see if their choice is usable here. @@ -267,13 +291,21 @@ static void _dummy(int sig) #define SCORNODENAME "/dev/fontserver.%sR" #define SCOSNODENAME "/dev/fontserver.%sS" #endif +#endif #if defined(ICE_t) +#ifdef __sun +#define NAMEDNODENAME "/tmp/.ICE-pipe/" +#else #define PTSNODENAME "/dev/X/ICE." #define NAMEDNODENAME "/dev/X/NICE." #define SCORNODENAME "/dev/ICE.%sR" #define SCOSNODENAME "/dev/ICE.%sS" #endif +#endif #if defined(TEST_t) +#ifdef __sun +#define NAMEDNODENAME "/tmp/.Test-unix/test" +#endif #define PTSNODENAME "/dev/X/transtest." #define NAMEDNODENAME "/dev/X/Ntranstest." #define SCORNODENAME "/dev/transtest.%sR" @@ -282,11 +314,11 @@ static void _dummy(int sig) -#ifndef sun +#ifdef LOCAL_TRANS_PTS #ifdef TRANS_CLIENT static int -TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) +TRANS(PTSOpenClient)(XtransConnInfo ciptr, const char *port) { #ifdef PTSNODENAME @@ -298,20 +330,22 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) pid_t saved_pid; #endif - PRMSG(2,"PTSOpenClient(%s)\n", port, 0,0 ); + prmsg(2,"PTSOpenClient(%s)\n", port); #if !defined(PTSNODENAME) - PRMSG(1,"PTSOpenClient: Protocol is not supported by a pts connection\n", 0,0,0); + prmsg(1,"PTSOpenClient: Protocol is not supported by a pts connection\n"); return -1; #else if (port && *port ) { if( *port == '/' ) { /* A full pathname */ - (void) sprintf(server_path, "%s", port); + snprintf(server_path, sizeof(server_path), "%s", port); } else { - (void) sprintf(server_path, "%s%s", PTSNODENAME, port); + snprintf(server_path, sizeof(server_path), "%s%s", + PTSNODENAME, port); } } else { - (void) sprintf(server_path, "%s%d", PTSNODENAME, getpid()); + snprintf(server_path, sizeof(server_path), "%s%d", + PTSNODENAME, getpid()); } @@ -320,7 +354,7 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) */ if ((server = open (server_path, O_RDWR)) < 0) { - PRMSG(1,"PTSOpenClient: failed to open %s\n", server_path, 0,0); + prmsg(1,"PTSOpenClient: failed to open %s\n", server_path); return -1; } @@ -330,7 +364,8 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) */ if ((fd = open(DEV_PTMX, O_RDWR)) < 0) { - PRMSG(1,"PTSOpenClient: failed to open %s\n", DEV_PTMX, 0,0); + prmsg(1,"PTSOpenClient: failed to open %s\n", DEV_PTMX); + close(server); return(-1); } @@ -340,7 +375,7 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) slave = ptsname(fd); /* get name */ if( slave == NULL ) { - PRMSG(1,"PTSOpenClient: failed to get ptsname()\n", 0,0,0); + prmsg(1,"PTSOpenClient: failed to get ptsname()\n"); close(fd); close(server); return -1; @@ -373,14 +408,14 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) if (WIFEXITED(exitval) && WEXITSTATUS(exitval) != 0) { close(fd); close(server); - PRMSG(1, "PTSOpenClient: cannot set the owner of %s\n", - slave, 0, 0); + prmsg(1, "PTSOpenClient: cannot set the owner of %s\n", + slave); return(-1); } if (chmod(slave, 0666) < 0) { close(fd); close(server); - PRMSG(1,"PTSOpenClient: Cannot chmod %s\n", slave, 0,0); + prmsg(1,"PTSOpenClient: Cannot chmod %s\n", slave); return(-1); } @@ -407,8 +442,8 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) (void) signal(SIGALRM, savef); if (ret != 1) { - PRMSG(1, - "PTSOpenClient: failed to get acknoledgement from server\n", 0, 0, 0); + prmsg(1, + "PTSOpenClient: failed to get acknoledgement from server\n"); (void) close(fd); fd = -1; } @@ -419,7 +454,7 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) if (TRANS(FillAddrInfo) (ciptr, slave, server_path) == 0) { - PRMSG(1,"PTSOpenClient: failed to fill in addr info\n", 0, 0, 0); + prmsg(1,"PTSOpenClient: failed to fill in addr info\n"); close(fd); return -1; } @@ -435,7 +470,7 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port) #ifdef TRANS_SERVER static int -TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port) +TRANS(PTSOpenServer)(XtransConnInfo ciptr, const char *port) { #ifdef PTSNODENAME @@ -444,10 +479,10 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port) int mode; #endif - PRMSG(2,"PTSOpenServer(%s)\n", port, 0,0 ); + prmsg(2,"PTSOpenServer(%s)\n", port); #if !defined(PTSNODENAME) - PRMSG(1,"PTSOpenServer: Protocol is not supported by a pts connection\n", 0,0,0); + prmsg(1,"PTSOpenServer: Protocol is not supported by a pts connection\n"); return -1; #else if (port && *port ) { @@ -466,8 +501,8 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port) 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); + prmsg (1, "PTSOpenServer: mkdir(%s) failed, errno = %d\n", + X_STREAMS_DIR, errno); return(-1); } @@ -478,8 +513,8 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port) * 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 ); + prmsg(1, "PTSOpenServer: A server is already running on port %s\n", port); + prmsg(1, "PTSOpenServer: Remove %s if this is incorrect.\n", server_path); close(fd); return(-1); } @@ -490,7 +525,7 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port) unlink(server_path); if( (fd=open(DEV_PTMX, O_RDWR)) < 0) { - PRMSG(1, "PTSOpenServer: Unable to open %s\n", DEV_PTMX, 0,0 ); + prmsg(1, "PTSOpenServer: Unable to open %s\n", DEV_PTMX); return(-1); } @@ -498,25 +533,25 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port) unlockpt(fd); if( (slave=ptsname(fd)) == NULL) { - PRMSG(1, "PTSOpenServer: Unable to get slave device name\n", 0,0,0 ); + prmsg(1, "PTSOpenServer: Unable to get slave device name\n"); close(fd); return(-1); } if( link(slave,server_path) < 0 ) { - PRMSG(1, "PTSOpenServer: Unable to link %s to %s\n", slave, server_path,0 ); + prmsg(1, "PTSOpenServer: Unable to link %s to %s\n", slave, server_path); close(fd); return(-1); } if( chmod(server_path, 0666) < 0 ) { - PRMSG(1, "PTSOpenServer: Unable to chmod %s to 0666\n", server_path,0,0 ); + prmsg(1, "PTSOpenServer: Unable to chmod %s to 0666\n", server_path); close(fd); return(-1); } if( (server=open(server_path, O_RDWR)) < 0 ) { - PRMSG(1, "PTSOpenServer: Unable to open server device %s\n", server_path,0,0 ); + prmsg(1, "PTSOpenServer: Unable to open server device %s\n", server_path); close(fd); return(-1); } @@ -529,7 +564,7 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port) if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"PTSOpenServer: failed to fill in addr info\n", 0, 0, 0); + prmsg(1,"PTSOpenServer: failed to fill in addr info\n"); close(fd); return -1; } @@ -549,17 +584,17 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) char buf[256]; struct sockaddr_un *sunaddr; - PRMSG(2,"PTSAccept(%x->%d)\n",ciptr,ciptr->fd,0); + prmsg(2,"PTSAccept(%x->%d)\n",ciptr,ciptr->fd); if( (in=read(ciptr->fd,&length,1)) <= 0 ){ if( !in ) { - PRMSG(2, - "PTSAccept: Incoming connection closed\n",0,0,0); + prmsg(2, + "PTSAccept: Incoming connection closed\n"); } else { - PRMSG(1, + prmsg(1, "PTSAccept: Error reading incoming connection. errno=%d \n", - errno,0,0); + errno); } *status = TRANS_ACCEPT_MISC_ERROR; return -1; @@ -567,13 +602,13 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) if( (in=read(ciptr->fd,buf,length)) <= 0 ){ if( !in ) { - PRMSG(2, - "PTSAccept: Incoming connection closed\n",0,0,0); + prmsg(2, + "PTSAccept: Incoming connection closed\n"); } else { - PRMSG(1, + prmsg(1, "PTSAccept: Error reading device name for new connection. errno=%d \n", - errno,0,0); + errno); } *status = TRANS_ACCEPT_MISC_ERROR; return -1; @@ -582,7 +617,7 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) buf[length] = '\0'; if( (newfd=open(buf,O_RDWR)) < 0 ) { - PRMSG(1, "PTSAccept: Failed to open %s\n",buf,0,0); + prmsg(1, "PTSAccept: Failed to open %s\n",buf); *status = TRANS_ACCEPT_MISC_ERROR; return -1; } @@ -594,9 +629,8 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) */ newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { - PRMSG(1,"PTSAccept: failed to allocate memory for peer addr\n", - 0,0,0); + if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) { + prmsg(1,"PTSAccept: failed to allocate memory for peer addr\n"); close(newfd); *status = TRANS_ACCEPT_BAD_MALLOC; return -1; @@ -605,9 +639,8 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, 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,"PTSAccept: failed to allocate memory for peer addr\n", - 0,0,0); + if( (sunaddr = malloc(newciptr->peeraddrlen)) == NULL ) { + prmsg(1,"PTSAccept: failed to allocate memory for peer addr\n"); free(newciptr->addr); close(newfd); *status = TRANS_ACCEPT_BAD_MALLOC; @@ -616,7 +649,7 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) sunaddr->sun_family=AF_UNIX; strcpy(sunaddr->sun_path,buf); -#if defined(BSD44SOCKETS) && !defined(Lynx) +#if defined(BSD44SOCKETS) sunaddr->sun_len=strlen(sunaddr->sun_path); #endif @@ -628,60 +661,65 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) } #endif /* TRANS_SERVER */ -#endif /* sun */ +#endif /* LOCAL_TRANS_PTS */ -#ifdef SVR4 +#ifdef LOCAL_TRANS_NAMED /* NAMED */ #ifdef TRANS_CLIENT static int -TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, char *port) +TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, const char *port) { #ifdef NAMEDNODENAME int fd; char server_path[64]; struct stat filestat; - extern int isastream(); +# ifndef __sun + extern int isastream(int); +# endif #endif - PRMSG(2,"NAMEDOpenClient(%s)\n", port, 0,0 ); + prmsg(2,"NAMEDOpenClient(%s)\n", port); #if !defined(NAMEDNODENAME) - PRMSG(1,"NAMEDOpenClient: Protocol is not supported by a NAMED connection\n", 0,0,0); + prmsg(1,"NAMEDOpenClient: Protocol is not supported by a NAMED connection\n"); return -1; #else if ( port && *port ) { if( *port == '/' ) { /* A full pathname */ - (void) sprintf(server_path, "%s", port); + (void) snprintf(server_path, sizeof(server_path), "%s", port); } else { - (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port); + (void) snprintf(server_path, sizeof(server_path), "%s%s", NAMEDNODENAME, port); } } else { - (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid()); + (void) snprintf(server_path, sizeof(server_path), "%s%ld", NAMEDNODENAME, (long)getpid()); } - if (stat(server_path, &filestat) < 0 ) { - PRMSG(1,"NAMEDOpenClient: No device %s for NAMED connection\n", server_path, 0,0 ); + if ((fd = open(server_path, O_RDWR)) < 0) { + prmsg(1,"NAMEDOpenClient: Cannot open %s for NAMED connection\n", server_path); return -1; } - if ((filestat.st_mode & S_IFMT) != S_IFIFO) { - PRMSG(1,"NAMEDOpenClient: Device %s is not a FIFO\n", server_path, 0,0 ); - /* Is this really a failure? */ + if (fstat(fd, &filestat) < 0 ) { + prmsg(1,"NAMEDOpenClient: Cannot stat %s for NAMED connection\n", server_path); + (void) close(fd); return -1; } - if ((fd = open(server_path, O_RDWR)) < 0) { - PRMSG(1,"NAMEDOpenClient: Cannot open %s for NAMED connection\n", server_path, 0,0 ); + if ((filestat.st_mode & S_IFMT) != S_IFIFO) { + prmsg(1,"NAMEDOpenClient: Device %s is not a FIFO\n", server_path); + /* Is this really a failure? */ + (void) close(fd); return -1; } + if (isastream(fd) <= 0) { - PRMSG(1,"NAMEDOpenClient: %s is not a streams device\n", server_path, 0,0 ); + prmsg(1,"NAMEDOpenClient: %s is not a streams device\n", server_path); (void) close(fd); return -1; } @@ -692,8 +730,7 @@ TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, char *port) if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"NAMEDOpenClient: failed to fill in addr info\n", - 0,0,0); + prmsg(1,"NAMEDOpenClient: failed to fill in addr info\n"); close(fd); return -1; } @@ -708,32 +745,16 @@ TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, char *port) #ifdef TRANS_SERVER -static int -TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, char *port) -{ #ifdef NAMEDNODENAME +static int +TRANS(NAMEDOpenPipe)(const char *server_path) +{ int fd, pipefd[2]; - char server_path[64]; struct stat sbuf; int mode; -#endif - PRMSG(2,"NAMEDOpenServer(%s)\n", port, 0,0 ); - -#if !defined(NAMEDNODENAME) - PRMSG(1,"NAMEDOpenServer: Protocol is not supported by a NAMED connection\n", 0,0,0); - return -1; -#else - if ( port && *port ) { - if( *port == '/' ) { /* A full pathname */ - (void) sprintf(server_path, "%s", port); - } else { - (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port); - } - } else { - (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid()); - } + prmsg(2,"NAMEDOpenPipe(%s)\n", server_path); #ifdef HAS_STICKY_DIR_BIT mode = 01777; @@ -741,72 +762,136 @@ TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, char *port) 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); + prmsg (1, "NAMEDOpenPipe: mkdir(%s) failed, errno = %d\n", + X_STREAMS_DIR, errno); return(-1); } if(stat(server_path, &sbuf) != 0) { if (errno == ENOENT) { if ((fd = creat(server_path, (mode_t)0666)) == -1) { - PRMSG(1, "NAMEDOpenServer: Can't open %s\n", server_path, 0,0 ); + prmsg(1, "NAMEDOpenPipe: Can't open %s\n", server_path); return(-1); } close(fd); if (chmod(server_path, (mode_t)0666) < 0) { - PRMSG(1, "NAMEDOpenServer: Can't open %s\n", server_path, 0,0 ); + prmsg(1, "NAMEDOpenPipe: Can't open %s\n", server_path); return(-1); } } else { - PRMSG(1, "NAMEDOpenServer: stat on %s failed\n", server_path, 0,0 ); + prmsg(1, "NAMEDOpenPipe: stat on %s failed\n", server_path); return(-1); } } if( pipe(pipefd) != 0) { - PRMSG(1, "NAMEDOpenServer: pipe() failed, errno=%d\n",errno, 0,0 ); + prmsg(1, "NAMEDOpenPipe: pipe() failed, errno=%d\n",errno); return(-1); } if( ioctl(pipefd[0], I_PUSH, "connld") != 0) { - PRMSG(1, "NAMEDOpenServer: ioctl(I_PUSH,\"connld\") failed, errno=%d\n",errno, 0,0 ); + prmsg(1, "NAMEDOpenPipe: ioctl(I_PUSH,\"connld\") failed, errno=%d\n",errno); close(pipefd[0]); close(pipefd[1]); return(-1); } if( fattach(pipefd[0], server_path) != 0) { - PRMSG(1, "NAMEDOpenServer: fattach(%s) failed, errno=%d\n", server_path,errno, 0 ); + prmsg(1, "NAMEDOpenPipe: fattach(%s) failed, errno=%d\n", server_path,errno); close(pipefd[0]); close(pipefd[1]); return(-1); } + return(pipefd[1]); +} +#endif + +static int +TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, const char *port) +{ +#ifdef NAMEDNODENAME + int fd; + char server_path[64]; +#endif + + prmsg(2,"NAMEDOpenServer(%s)\n", port); + +#if !defined(NAMEDNODENAME) + prmsg(1,"NAMEDOpenServer: Protocol is not supported by a NAMED connection\n"); + return -1; +#else + if ( port && *port ) { + if( *port == '/' ) { /* A full pathname */ + (void) snprintf(server_path, sizeof(server_path), "%s", port); + } else { + (void) snprintf(server_path, sizeof(server_path), "%s%s", + NAMEDNODENAME, port); + } + } else { + (void) snprintf(server_path, sizeof(server_path), "%s%ld", + NAMEDNODENAME, (long)getpid()); + } + + fd = TRANS(NAMEDOpenPipe)(server_path); + if (fd < 0) { + return -1; + } + /* * Everything looks good: fill in the XtransConnInfo structure. */ if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"NAMEDOpenServer: failed to fill in addr info\n", 0,0,0); + prmsg(1,"NAMEDOpenServer: failed to fill in addr info\n"); + TRANS(LocalClose)(ciptr); return -1; } - return(pipefd[1]); + return fd; #endif /* !NAMEDNODENAME */ } static int +TRANS(NAMEDResetListener) (XtransConnInfo ciptr) + +{ + struct sockaddr_un *sockname=(struct sockaddr_un *) ciptr->addr; + struct stat statb; + + prmsg(2,"NAMEDResetListener(%p, %d)\n", ciptr, ciptr->fd); + + if (ciptr->fd != -1) { + /* + * see if the pipe has disappeared + */ + + if (stat (sockname->sun_path, &statb) == -1 || + (statb.st_mode & S_IFMT) != S_IFIFO) { + prmsg(3, "Pipe %s trashed, recreating\n", sockname->sun_path); + TRANS(LocalClose)(ciptr); + ciptr->fd = TRANS(NAMEDOpenPipe)(sockname->sun_path); + if (ciptr->fd >= 0) + return TRANS_RESET_NEW_FD; + else + return TRANS_CREATE_LISTENER_FAILED; + } + } + return TRANS_RESET_NOOP; +} + +static int TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) { struct strrecvfd str; - PRMSG(2,"NAMEDAccept(%x->%d)\n", ciptr, ciptr->fd, 0 ); + prmsg(2,"NAMEDAccept(%p->%d)\n", ciptr, ciptr->fd); if( ioctl(ciptr->fd, I_RECVFD, &str ) < 0 ) { - PRMSG(1, "NAMEDAccept: ioctl(I_RECVFD) failed, errno=%d\n", errno, 0,0 ); + prmsg(1, "NAMEDAccept: ioctl(I_RECVFD) failed, errno=%d\n", errno); *status = TRANS_ACCEPT_MISC_ERROR; return(-1); } @@ -814,12 +899,11 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) /* * Everything looks good: fill in the XtransConnInfo structure. */ - + newciptr->family=ciptr->family; newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { - PRMSG(1, - "NAMEDAccept: failed to allocate memory for peer addr\n", - 0,0,0); + if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) { + prmsg(1, + "NAMEDAccept: failed to allocate memory for pipe addr\n"); close(str.fd); *status = TRANS_ACCEPT_BAD_MALLOC; return -1; @@ -828,10 +912,9 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen); newciptr->peeraddrlen=newciptr->addrlen; - if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) { - PRMSG(1, - "NAMEDAccept: failed to allocate memory for peer addr\n", - 0,0,0); + if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) { + prmsg(1, + "NAMEDAccept: failed to allocate memory for peer addr\n"); free(newciptr->addr); close(str.fd); *status = TRANS_ACCEPT_BAD_MALLOC; @@ -847,14 +930,14 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) #endif /* TRANS_SERVER */ -#endif /* SVR4 */ +#endif /* LOCAL_TRANS_NAMED */ -#ifndef sun +#if defined(LOCAL_TRANS_SCO) /* - * connect_spipe is used by the SCO and ISC connection types. + * connect_spipe is used by the SCO connection type. */ static int connect_spipe(int fd1, int fd2) @@ -879,7 +962,7 @@ connect_spipe(int fd1, int fd2) } /* - * named_spipe is used by the SCO and ISC connection types. + * named_spipe is used by the SCO connection type. */ static int @@ -905,294 +988,12 @@ named_spipe(int fd, char *path) return(ret); } -/* SCO doesnt use the ISC transport type - it causes problems */ -#if !defined(__SCO__) && !defined(__UNIXWARE__) +#endif /* defined(LOCAL_TRANS_SCO) */ -/* ISC */ - -#ifdef TRANS_CLIENT - -static int -TRANS(ISCOpenClient)(XtransConnInfo ciptr, char *port) - -{ -#ifdef ISCDEVNODENAME - int fd,fds,server; - char server_path[64]; - char server_dev_path[64]; - struct strfdinsert buf; - long temp; - mode_t spmode; - struct stat filestat; -#endif - - PRMSG(2,"ISCOpenClient(%s)\n", port, 0,0 ); - -#if !defined(ISCDEVNODENAME) - PRMSG(1,"ISCOpenClient: Protocol is not supported by a ISC connection\n", 0,0,0); - return -1; -#else - (void) sprintf(server_path, ISCTMPNODENAME, port); - (void) sprintf(server_dev_path, ISCDEVNODENAME, port); - - fd = fds = server = -1; - - if (stat(DEV_SPX, &filestat) == -1) { - PRMSG(1, "ISCOpenClient: stat(%s) failed, errno=%d\n", DEV_SPX, errno, 0 ); - return(-1); - } - - spmode = (filestat.st_mode & S_IFMT); - - if (stat(server_path, &filestat) != -1) { - if ((filestat.st_mode & S_IFMT) == spmode) { - if ((server = open(server_path, O_RDWR)) < 0) { - 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,"ISCOpenClient: failed to open %s\n", - server_dev_path, 0,0 ); - } - } - } - } - - if (server < 0) { - PRMSG(1,"ISCOpenClient: can't open either device %s or %s\n", - server_path, server_dev_path, 0 ); - return -1; - } - - if ((fds = open(DEV_SPX, O_RDWR)) < 0 || - (fd = open(DEV_SPX, O_RDWR)) < 0) { - /* Failed to open all of the devices */ - PRMSG(1,"ISCOpenClient: can't open %s\n", DEV_SPX, 0,0 ); - (void) close(server); - if (fds != -1) - (void) close(fds); - if (fd != -1) - (void) close(fd); - return -1; - } - - /* make a STREAMS-pipe */ - - buf.databuf.maxlen = -1; - buf.databuf.len = -1; - buf.databuf.buf = NULL; - buf.ctlbuf.maxlen = sizeof(long); - buf.ctlbuf.len = sizeof(long); - buf.ctlbuf.buf = (caddr_t)&temp; - buf.offset = 0; - buf.fildes = fd; - buf.flags = 0; - - if (ioctl(fds, I_FDINSERT, &buf) < 0 || - ioctl(server, I_SENDFD, fds) < 0) { - PRMSG(1,"ISCOpenClient: ioctl(I_FDINSERT or I_SENDFD) failed\n", - 0,0,0 ); - (void) close(server); - (void) close(fds); - (void) close(fd); - return -1; - } - - /* - * Everything looks good: fill in the XtransConnInfo structure. - */ - - if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) - { - PRMSG(1,"ISCOpenClient: failed to fill in addr info\n", 0, 0, 0); - close(fd); - return -1; - } - - return (fd); - -#endif /* !ISCDEVNODENAME */ -} - -#endif /* TRANS_CLIENT */ - - -#ifdef TRANS_SERVER - -static int -TRANS(ISCOpenServer)(XtransConnInfo ciptr, char *port) - -{ -#ifdef ISCDEVNODENAME - int fd = -1,fds = -1; - char server_path[64],server_unix_path[64]; - unsigned int mode = 0; -#endif - - PRMSG(2,"ISCOpenServer(%s)\n", port, 0,0 ); - -#if !defined(ISCDEVNODENAME) - 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 - mode = 01777; -#else - 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,"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,"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" - - 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,"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 ) -#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 - * is already established, and this just for compatability - */ -#endif /* SVR4 */ -#endif /* !UNIXCONN */ - /* - * Everything looks good: fill in the XtransConnInfo structure. - */ - if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) - { - PRMSG(1,"ISCOpenServer: failed to fill in addr info\n", 0, 0, 0); - close(fd); - return -1; - } - - return fd; - -#endif /* !ISCDEVNODENAME */ -} - -static int -TRANS(ISCAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) - -{ - struct strrecvfd str; - - PRMSG(2,"ISCAccept(%d)\n", ciptr->fd, 0,0 ); - - while (ioctl(ciptr->fd, I_RECVFD, &str) < 0) { - if (errno != EAGAIN) { - 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 ) { - PRMSG(1, - "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 ) { - PRMSG(1, - "ISCAccept: failed to allocate memory for peer addr\n", - 0,0,0); - free(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 /* !__SCO__ && !__UNIXWARE__ */ - - +#ifdef LOCAL_TRANS_SCO /* SCO */ /* @@ -1213,7 +1014,7 @@ TRANS(ISCAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) #ifdef TRANS_CLIENT static int -TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port) +TRANS(SCOOpenClient)(XtransConnInfo ciptr, const char *port) { #ifdef SCORNODENAME int fd, server, fl, ret; @@ -1225,23 +1026,23 @@ TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port) extern int getmsg(), putmsg(); #endif - PRMSG(2,"SCOOpenClient(%s)\n", port, 0,0 ); + prmsg(2,"SCOOpenClient(%s)\n", port); if (!port || !port[0]) port = "0"; #if !defined(SCORNODENAME) - PRMSG(2,"SCOOpenClient: Protocol is not supported by a SCO connection\n", 0,0,0); + prmsg(2,"SCOOpenClient: Protocol is not supported by a SCO connection\n"); return -1; #else (void) sprintf(server_path, SCORNODENAME, port); if ((server = open(server_path, O_RDWR)) < 0) { - PRMSG(1,"SCOOpenClient: failed to open %s\n", server_path, 0,0 ); + prmsg(1,"SCOOpenClient: failed to open %s\n", server_path); return -1; } if ((fd = open(DEV_SPX, O_RDWR)) < 0) { - PRMSG(1,"SCOOpenClient: failed to open %s\n", DEV_SPX, 0,0 ); + prmsg(1,"SCOOpenClient: failed to open %s\n", DEV_SPX); close(server); return -1; } @@ -1261,7 +1062,7 @@ TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port) (void) signal(SIGALRM, savef); if (ret < 0) { - PRMSG(1,"SCOOpenClient: error from getmsg\n", 0,0,0 ); + prmsg(1,"SCOOpenClient: error from getmsg\n"); close(fd); close(server); return -1; @@ -1285,7 +1086,7 @@ TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port) #endif if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"SCOOpenClient: failed to fill addr info\n", 0, 0, 0); + prmsg(1,"SCOOpenClient: failed to fill addr info\n"); close(fd); return -1; } @@ -1301,7 +1102,7 @@ TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port) #ifdef TRANS_SERVER static int -TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port) +TRANS(SCOOpenServer)(XtransConnInfo ciptr, const char *port) { #ifdef SCORNODENAME char serverR_path[64]; @@ -1311,12 +1112,12 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port) int fds = -1; #endif - PRMSG(2,"SCOOpenServer(%s)\n", port, 0,0 ); + prmsg(2,"SCOOpenServer(%s)\n", port); if (!port || !port[0]) port = "0"; #if !defined(SCORNODENAME) - PRMSG(1,"SCOOpenServer: Protocol is not supported by a SCO connection\n", 0,0,0); + prmsg(1,"SCOOpenServer: Protocol is not supported by a SCO connection\n"); return -1; #else (void) sprintf(serverR_path, SCORNODENAME, port); @@ -1328,19 +1129,23 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port) if ((fds = open(DEV_SPX, O_RDWR)) < 0 || (fdr = open(DEV_SPX, O_RDWR)) < 0 ) { - PRMSG(1,"SCOOpenServer: failed to open %s\n", DEV_SPX, 0,0 ); + prmsg(1,"SCOOpenServer: failed to open %s\n", DEV_SPX); + if (fds >= 0) + close(fds); + if (fdr >= 0) + close(fdr); return -1; } if (named_spipe (fds, serverS_path) == -1) { - PRMSG(1,"SCOOpenServer: failed to create %s\n", serverS_path, 0, 0); + prmsg(1,"SCOOpenServer: failed to create %s\n", serverS_path); close (fdr); close (fds); return -1; } if (named_spipe (fdr, serverR_path) == -1) { - PRMSG(1,"SCOOpenServer: failed to create %s\n", serverR_path, 0, 0); + prmsg(1,"SCOOpenServer: failed to create %s\n", serverR_path); close (fdr); close (fds); return -1; @@ -1349,7 +1154,7 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port) fds = open (serverS_path, O_RDWR | O_NDELAY); if (fds < 0) { - PRMSG(1,"SCOOpenServer: failed to open %s\n", serverS_path, 0, 0); + prmsg(1,"SCOOpenServer: failed to open %s\n", serverS_path); return -1; } @@ -1362,22 +1167,22 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port) mylock.l_start = 0; mylock.l_len = 0; if (fcntl (fds, F_SETLK, &mylock) < 0) { - PRMSG(1,"SCOOpenServer: failed to lock %s\n", serverS_path, 0, 0); + prmsg(1,"SCOOpenServer: failed to lock %s\n", serverS_path); close (fds); return -1; } fdr = open (serverR_path, O_RDWR | O_NDELAY); - if (fds < 0) { - PRMSG(1,"SCOOpenServer: failed to open %s\n", serverR_path, 0, 0); + if (fdr < 0) { + prmsg(1,"SCOOpenServer: failed to open %s\n", serverR_path); close (fds); return -1; } #endif /* X11_t */ if (connect_spipe(fds, fdr)) { - PRMSG(1,"SCOOpenServer: ioctl(I_FDINSERT) failed on %s\n", - serverS_path, 0, 0); + prmsg(1,"SCOOpenServer: ioctl(I_FDINSERT) failed on %s\n", + serverS_path); close (fdr); close (fds); return -1; @@ -1391,7 +1196,7 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port) ciptr->flags |= TRANS_NOUNLINK; #endif if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0) { - PRMSG(1,"SCOOpenServer: failed to fill in addr info\n", 0,0,0); + prmsg(1,"SCOOpenServer: failed to fill in addr info\n"); close(fds); close(fdr); return -1; @@ -1408,22 +1213,22 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) char c; int fd; - PRMSG(2,"SCOAccept(%d)\n", ciptr->fd, 0,0 ); + prmsg(2,"SCOAccept(%d)\n", ciptr->fd); if (read(ciptr->fd, &c, 1) < 0) { - PRMSG(1,"SCOAccept: can't read from client\n",0,0,0); + prmsg(1,"SCOAccept: can't read from client\n"); *status = TRANS_ACCEPT_MISC_ERROR; return(-1); } if( (fd = open(DEV_SPX, O_RDWR)) < 0 ) { - PRMSG(1,"SCOAccept: can't open \"%s\"\n",DEV_SPX, 0,0 ); + prmsg(1,"SCOAccept: can't open \"%s\"\n",DEV_SPX); *status = TRANS_ACCEPT_MISC_ERROR; return(-1); } if (connect_spipe (ciptr->fd, fd) < 0) { - PRMSG(1,"SCOAccept: ioctl(I_FDINSERT) failed\n", 0, 0, 0); + prmsg(1,"SCOAccept: ioctl(I_FDINSERT) failed\n"); close (fd); *status = TRANS_ACCEPT_MISC_ERROR; return -1; @@ -1434,10 +1239,9 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) */ newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { - PRMSG(1, - "SCOAccept: failed to allocate memory for peer addr\n", - 0,0,0); + if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) { + prmsg(1, + "SCOAccept: failed to allocate memory for peer addr\n"); close(fd); *status = TRANS_ACCEPT_BAD_MALLOC; return -1; @@ -1449,10 +1253,9 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) #endif newciptr->peeraddrlen=newciptr->addrlen; - if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) { - PRMSG(1, - "SCOAccept: failed to allocate memory for peer addr\n", - 0,0,0); + if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) { + prmsg(1, + "SCOAccept: failed to allocate memory for peer addr\n"); free(newciptr->addr); close(fd); *status = TRANS_ACCEPT_BAD_MALLOC; @@ -1467,41 +1270,42 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) } #endif /* TRANS_SERVER */ -#endif /* sun */ +#endif /* LOCAL_TRANS_SCO */ #ifdef TRANS_REOPEN -#ifndef sun +#ifdef LOCAL_TRANS_PTS static int -TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, char *port) +TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, const char *port) { #ifdef PTSNODENAME char server_path[64]; #endif - PRMSG(2,"PTSReopenServer(%d,%s)\n", fd, port, 0 ); + prmsg(2,"PTSReopenServer(%d,%s)\n", fd, port); #if !defined(PTSNODENAME) - PRMSG(1,"PTSReopenServer: Protocol is not supported by a pts connection\n", 0,0,0); + prmsg(1,"PTSReopenServer: Protocol is not supported by a pts connection\n"); return 0; #else if (port && *port ) { if( *port == '/' ) { /* A full pathname */ - (void) sprintf(server_path, "%s", port); + snprintf(server_path, sizeof(server_path), "%s", port); } else { - (void) sprintf(server_path, "%s%s", PTSNODENAME, port); + snprintf(server_path, sizeof(server_path), "%s%s", + PTSNODENAME, port); } } else { - (void) sprintf(server_path, "%s%ld", PTSNODENAME, (long)getpid()); + snprintf(server_path, sizeof(server_path), "%s%ld", + PTSNODENAME, (long)getpid()); } if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"PTSReopenServer: failed to fill in addr info\n", - 0,0,0); + prmsg(1,"PTSReopenServer: failed to fill in addr info\n"); return 0; } @@ -1510,36 +1314,39 @@ TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, char *port) #endif /* !PTSNODENAME */ } -#endif /* !sun */ +#endif /* LOCAL_TRANS_PTS */ + +#ifdef LOCAL_TRANS_NAMED static int -TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd, char *port) +TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd _X_UNUSED, const char *port) { #ifdef NAMEDNODENAME char server_path[64]; #endif - PRMSG(2,"NAMEDReopenServer(%s)\n", port, 0,0 ); + prmsg(2,"NAMEDReopenServer(%s)\n", port); #if !defined(NAMEDNODENAME) - PRMSG(1,"NAMEDReopenServer: Protocol is not supported by a NAMED connection\n", 0,0,0); + prmsg(1,"NAMEDReopenServer: Protocol is not supported by a NAMED connection\n"); return 0; #else if ( port && *port ) { if( *port == '/' ) { /* A full pathname */ - (void) sprintf(server_path, "%s", port); + snprintf(server_path, sizeof(server_path),"%s", port); } else { - (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port); + snprintf(server_path, sizeof(server_path), "%s%s", + NAMEDNODENAME, port); } } else { - (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid()); + snprintf(server_path, sizeof(server_path), "%s%ld", + NAMEDNODENAME, (long)getpid()); } if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) { - PRMSG(1,"NAMEDReopenServer: failed to fill in addr info\n", - 0,0,0); + prmsg(1,"NAMEDReopenServer: failed to fill in addr info\n"); return 0; } @@ -1548,51 +1355,24 @@ TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd, char *port) #endif /* !NAMEDNODENAME */ } -#ifndef sun -#if !defined(__SCO__) && !defined(__UNIXWARE__) -static int -TRANS(ISCReopenServer)(XtransConnInfo ciptr, int fd, char *port) - -{ -#ifdef ISCDEVNODENAME - char server_path[64], server_unix_path[64]; -#endif - - PRMSG(2,"ISCReopenServer(%s)\n", port, 0,0 ); +#endif /* LOCAL_TRANS_NAMED */ -#if !defined(ISCDEVNODENAME) - PRMSG(1,"ISCReopenServer: Protocol is not supported by a ISC connection\n", 0,0,0); - return 0; -#else - (void) sprintf(server_path, ISCDEVNODENAME, port); - (void) sprintf(server_unix_path, ISCTMPNODENAME, port); - - if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0) - { - PRMSG(1, "ISCReopenServer: failed to fill in addr info\n", 0,0,0); - return 0; - } - - return 1; - -#endif /* !ISCDEVNODENAME */ -} -#endif /* !__SCO__ && !__UNIXWARE__ */ +#ifdef LOCAL_TRANS_SCO static int -TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port) +TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, const char *port) { #ifdef SCORNODENAME char serverR_path[64], serverS_path[64]; #endif - PRMSG(2,"SCOReopenServer(%s)\n", port, 0,0 ); + prmsg(2,"SCOReopenServer(%s)\n", port); if (!port || !port[0]) port = "0"; #if !defined(SCORNODENAME) - PRMSG(2,"SCOReopenServer: Protocol is not supported by a SCO connection\n", 0,0,0); + prmsg(2,"SCOReopenServer: Protocol is not supported by a SCO connection\n"); return 0; #else (void) sprintf(serverR_path, SCORNODENAME, port); @@ -1603,7 +1383,7 @@ TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port) #endif if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0) { - PRMSG(1, "SCOReopenServer: failed to fill in addr info\n", 0,0,0); + prmsg(1, "SCOReopenServer: failed to fill in addr info\n"); return 0; } @@ -1612,7 +1392,7 @@ TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port) #endif /* SCORNODENAME */ } -#endif /* !sun */ +#endif /* LOCAL_TRANS_SCO */ #endif /* TRANS_REOPEN */ @@ -1624,12 +1404,12 @@ TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port) */ typedef struct _LOCALtrans2dev { - char *transname; + const char *transname; #ifdef TRANS_CLIENT int (*devcotsopenclient)( - XtransConnInfo, char * /*port*/ + XtransConnInfo, const char * /*port*/ ); #endif /* TRANS_CLIENT */ @@ -1637,7 +1417,7 @@ typedef struct _LOCALtrans2dev { #ifdef TRANS_SERVER int (*devcotsopenserver)( - XtransConnInfo, char * /*port*/ + XtransConnInfo, const char * /*port*/ ); #endif /* TRANS_SERVER */ @@ -1645,7 +1425,7 @@ typedef struct _LOCALtrans2dev { #ifdef TRANS_CLIENT int (*devcltsopenclient)( - XtransConnInfo, char * /*port*/ + XtransConnInfo, const char * /*port*/ ); #endif /* TRANS_CLIENT */ @@ -1653,7 +1433,7 @@ typedef struct _LOCALtrans2dev { #ifdef TRANS_SERVER int (*devcltsopenserver)( - XtransConnInfo, char * /*port*/ + XtransConnInfo, const char * /*port*/ ); #endif /* TRANS_SERVER */ @@ -1663,19 +1443,23 @@ typedef struct _LOCALtrans2dev { int (*devcotsreopenserver)( XtransConnInfo, int, /* fd */ - char * /* port */ + const char * /* port */ ); int (*devcltsreopenserver)( XtransConnInfo, int, /* fd */ - char * /* port */ + const char * /* port */ ); #endif /* TRANS_REOPEN */ #ifdef TRANS_SERVER + int (*devreset)( + XtransConnInfo /* ciptr */ +); + int (*devaccept)( XtransConnInfo, XtransConnInfo, int * ); @@ -1685,7 +1469,7 @@ typedef struct _LOCALtrans2dev { } LOCALtrans2dev; static LOCALtrans2dev LOCALtrans2devtab[] = { -#ifndef sun +#ifdef LOCAL_TRANS_PTS {"", #ifdef TRANS_CLIENT TRANS(PTSOpenClient), @@ -1704,6 +1488,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { TRANS(ReopenFail), #endif #ifdef TRANS_SERVER + NULL, /* ResetListener */ TRANS(PTSAccept) #endif /* TRANS_SERVER */ }, @@ -1726,6 +1511,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { TRANS(ReopenFail), #endif #ifdef TRANS_SERVER + NULL, /* ResetListener */ TRANS(PTSAccept) #endif /* TRANS_SERVER */ }, @@ -1748,10 +1534,11 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { TRANS(ReopenFail), #endif #ifdef TRANS_SERVER + NULL, /* ResetListener */ TRANS(PTSAccept) #endif /* TRANS_SERVER */ }, -#else /* sun */ +#else /* !LOCAL_TRANS_PTS */ {"", #ifdef TRANS_CLIENT TRANS(NAMEDOpenClient), @@ -1770,6 +1557,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { TRANS(ReopenFail), #endif #ifdef TRANS_SERVER + TRANS(NAMEDResetListener), TRANS(NAMEDAccept) #endif /* TRANS_SERVER */ }, @@ -1792,12 +1580,13 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { TRANS(ReopenFail), #endif #ifdef TRANS_SERVER + TRANS(NAMEDResetListener), TRANS(NAMEDAccept) #endif /* TRANS_SERVER */ }, -#endif /* sun */ +#endif /* !LOCAL_TRANS_PTS */ -#ifdef SVR4 +#ifdef LOCAL_TRANS_NAMED {"named", #ifdef TRANS_CLIENT TRANS(NAMEDOpenClient), @@ -1816,19 +1605,18 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { TRANS(ReopenFail), #endif #ifdef TRANS_SERVER + TRANS(NAMEDResetListener), TRANS(NAMEDAccept) #endif /* TRANS_SERVER */ }, -#endif /* SVR4 */ -#ifndef sun -#if !defined(__SCO__) && !defined(__UNIXWARE__) -{"isc", +#ifdef __sun /* Alias "pipe" to named, since that's what Solaris called it */ +{"pipe", #ifdef TRANS_CLIENT - TRANS(ISCOpenClient), + TRANS(NAMEDOpenClient), #endif /* TRANS_CLIENT */ #ifdef TRANS_SERVER - TRANS(ISCOpenServer), + TRANS(NAMEDOpenServer), #endif /* TRANS_SERVER */ #ifdef TRANS_CLIENT TRANS(OpenFail), @@ -1837,15 +1625,19 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { TRANS(OpenFail), #endif /* TRANS_SERVER */ #ifdef TRANS_REOPEN - TRANS(ISCReopenServer), + TRANS(NAMEDReopenServer), TRANS(ReopenFail), #endif #ifdef TRANS_SERVER - TRANS(ISCAccept) + TRANS(NAMEDResetListener), + TRANS(NAMEDAccept) #endif /* TRANS_SERVER */ }, -#endif /* !__SCO__ && !__UNIXWARE__ */ +#endif /* __sun */ +#endif /* LOCAL_TRANS_NAMED */ + +#ifdef LOCAL_TRANS_SCO {"sco", #ifdef TRANS_CLIENT TRANS(SCOOpenClient), @@ -1864,15 +1656,16 @@ static LOCALtrans2dev LOCALtrans2devtab[] = { TRANS(ReopenFail), #endif #ifdef TRANS_SERVER + NULL, /* ResetListener */ TRANS(SCOAccept) #endif /* TRANS_SERVER */ }, -#endif /* sun */ +#endif /* LOCAL_TRANS_SCO */ }; #define NUMTRANSPORTS (sizeof(LOCALtrans2devtab)/sizeof(LOCALtrans2dev)) -static char *XLOCAL=NULL; +static const char *XLOCAL=NULL; static char *workingXLOCAL=NULL; static char *freeXLOCAL=NULL; @@ -1880,29 +1673,27 @@ static char *freeXLOCAL=NULL; #define DEF_XLOCAL "SCO:UNIX:PTS" #elif defined(__UNIXWARE__) #define DEF_XLOCAL "UNIX:PTS:NAMED:SCO" +#elif defined(__sun) +#define DEF_XLOCAL "UNIX:NAMED" #else -#define DEF_XLOCAL "UNIX:PTS:NAMED:ISC:SCO" +#define DEF_XLOCAL "UNIX:PTS:NAMED:SCO" #endif static void -TRANS(LocalInitTransports)(char *protocol) +TRANS(LocalInitTransports)(const char *protocol) { - PRMSG(3,"LocalInitTransports(%s)\n", protocol, 0,0 ); + prmsg(3,"LocalInitTransports(%s)\n", protocol); if( strcmp(protocol,"local") && strcmp(protocol,"LOCAL") ) { - workingXLOCAL=freeXLOCAL=(char *)malloc (strlen (protocol) + 1); - if (workingXLOCAL) - strcpy (workingXLOCAL, protocol); + workingXLOCAL = freeXLOCAL = strdup (protocol); } else { XLOCAL=(char *)getenv("XLOCAL"); if(XLOCAL==NULL) XLOCAL=DEF_XLOCAL; - workingXLOCAL=freeXLOCAL=(char *)malloc (strlen (XLOCAL) + 1); - if (workingXLOCAL) - strcpy (workingXLOCAL, XLOCAL); + workingXLOCAL = freeXLOCAL = strdup (XLOCAL); } } @@ -1910,7 +1701,7 @@ static void TRANS(LocalEndTransports)(void) { - PRMSG(3,"LocalEndTransports()\n", 0,0,0 ); + prmsg(3,"LocalEndTransports()\n"); free(freeXLOCAL); } @@ -1925,7 +1716,7 @@ TRANS(LocalGetNextTransport)(void) int i,j; char *typetocheck; char typebuf[TYPEBUFSIZE]; - PRMSG(3,"LocalGetNextTransport()\n", 0,0,0 ); + prmsg(3,"LocalGetNextTransport()\n"); while(1) { @@ -1940,7 +1731,7 @@ TRANS(LocalGetNextTransport)(void) for(i=0;i<NUMTRANSPORTS;i++) { /* - * This is equivilent to a case insensitive strcmp(), + * This is equivalent to a case insensitive strcmp(), * but should be more portable. */ strncpy(typebuf,typetocheck,TYPEBUFSIZE); @@ -1968,7 +1759,7 @@ TRANS(LocalGetNextTransport)(void) */ static int -HostReallyLocal (char *host) +HostReallyLocal (const char *host) { /* @@ -1998,14 +1789,15 @@ HostReallyLocal (char *host) static XtransConnInfo -TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port) +TRANS(LocalOpenClient)(int type, const char *protocol, + const char *host, const char *port) { LOCALtrans2dev *transptr; XtransConnInfo ciptr; int index; - PRMSG(3,"LocalOpenClient()\n", 0,0,0 ); + prmsg(3,"LocalOpenClient()\n"); /* * Make sure 'host' is really local. If not, we return failure. @@ -2017,9 +1809,9 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port) if (strcmp (host, "unix") != 0 && !HostReallyLocal (host)) { - PRMSG (1, + prmsg (1, "LocalOpenClient: Cannot connect to non-local host %s\n", - host, 0, 0); + host); return NULL; } @@ -2036,10 +1828,10 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port) */ #endif /* X11_t */ - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { - PRMSG(1,"LocalOpenClient: calloc(1,%d) failed\n", - sizeof(struct _XtransConnInfo),0,0 ); + prmsg(1,"LocalOpenClient: calloc(1,%lu) failed\n", + sizeof(struct _XtransConnInfo)); return NULL; } @@ -2056,19 +1848,14 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port) case XTRANS_OPEN_COTS_CLIENT: ciptr->fd=transptr->devcotsopenclient(ciptr,port); break; - case XTRANS_OPEN_CLTS_CLIENT: - ciptr->fd=transptr->devcltsopenclient(ciptr,port); - break; case XTRANS_OPEN_COTS_SERVER: - case XTRANS_OPEN_CLTS_SERVER: - PRMSG(1, - "LocalOpenClient: Should not be opening a server with this function\n", - 0,0,0); + prmsg(1, + "LocalOpenClient: Should not be opening a server with this function\n"); break; default: - PRMSG(1, + prmsg(1, "LocalOpenClient: Unknown Open type %d\n", - type, 0,0 ); + type); } if( ciptr->fd >= 0 ) break; @@ -2094,13 +1881,14 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port) #ifdef TRANS_SERVER static XtransConnInfo -TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port) +TRANS(LocalOpenServer)(int type, const char *protocol, + const char *host _X_UNUSED, const char *port) { int i; XtransConnInfo ciptr; - PRMSG(2,"LocalOpenServer(%d,%s,%s)\n", type, protocol, port); + prmsg(2,"LocalOpenServer(%d,%s,%s)\n", type, protocol, port); #if defined(X11_t) /* @@ -2111,10 +1899,10 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port) */ #endif /* X11_t */ - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { - PRMSG(1,"LocalOpenServer: calloc(1,%d) failed\n", - sizeof(struct _XtransConnInfo),0,0 ); + prmsg(1,"LocalOpenServer: calloc(1,%lu) failed\n", + sizeof(struct _XtransConnInfo)); return NULL; } @@ -2125,20 +1913,15 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port) switch( type ) { case XTRANS_OPEN_COTS_CLIENT: - case XTRANS_OPEN_CLTS_CLIENT: - PRMSG(1, - "LocalOpenServer: Should not be opening a client with this function\n", - 0,0,0); + prmsg(1, + "LocalOpenServer: Should not be opening a client with this function\n"); break; case XTRANS_OPEN_COTS_SERVER: ciptr->fd=LOCALtrans2devtab[i].devcotsopenserver(ciptr,port); break; - case XTRANS_OPEN_CLTS_SERVER: - ciptr->fd=LOCALtrans2devtab[i].devcltsopenserver(ciptr,port); - break; default: - PRMSG(1,"LocalOpenServer: Unknown Open type %d\n", - type ,0,0); + prmsg(1,"LocalOpenServer: Unknown Open type %d\n", + type ); } if( ciptr->fd >= 0 ) { ciptr->priv=(char *)&LOCALtrans2devtab[i]; @@ -2158,18 +1941,18 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port) #ifdef TRANS_REOPEN static XtransConnInfo -TRANS(LocalReopenServer)(int type, int index, int fd, char *port) +TRANS(LocalReopenServer)(int type, int index, int fd, const char *port) { XtransConnInfo ciptr; int stat = 0; - PRMSG(2,"LocalReopenServer(%d,%d,%d)\n", type, index, fd); + prmsg(2,"LocalReopenServer(%d,%d,%d)\n", type, index, fd); - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { - PRMSG(1,"LocalReopenServer: calloc(1,%d) failed\n", - sizeof(struct _XtransConnInfo),0,0 ); + prmsg(1,"LocalReopenServer: calloc(1,%lu) failed\n", + sizeof(struct _XtransConnInfo)); return NULL; } @@ -2180,12 +1963,9 @@ TRANS(LocalReopenServer)(int type, int index, int fd, char *port) case XTRANS_OPEN_COTS_SERVER: stat = LOCALtrans2devtab[index].devcotsreopenserver(ciptr,fd,port); break; - case XTRANS_OPEN_CLTS_SERVER: - stat = LOCALtrans2devtab[index].devcltsreopenserver(ciptr,fd,port); - break; - default: - PRMSG(1,"LocalReopenServer: Unknown Open type %d\n", - type ,0,0); + default: + prmsg(1,"LocalReopenServer: Unknown Open type %d\n", + type ); } if( stat > 0 ) { @@ -2210,11 +1990,11 @@ TRANS(LocalReopenServer)(int type, int index, int fd, char *port) #ifdef TRANS_CLIENT static XtransConnInfo -TRANS(LocalOpenCOTSClient)(Xtransport *thistrans, char *protocol, - char *host, char *port) +TRANS(LocalOpenCOTSClient)(Xtransport *thistrans _X_UNUSED, const char *protocol, + const char *host, const char *port) { - PRMSG(2,"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); } @@ -2225,15 +2005,15 @@ TRANS(LocalOpenCOTSClient)(Xtransport *thistrans, char *protocol, #ifdef TRANS_SERVER static XtransConnInfo -TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, char *protocol, - char *host, char *port) +TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, const char *protocol, + const char *host, const char *port) { char *typetocheck = NULL; int found = 0; char typebuf[TYPEBUFSIZE]; - PRMSG(2,"LocalOpenCOTSServer(%s,%s,%s)\n",protocol,host,port); + prmsg(2,"LocalOpenCOTSServer(%s,%s,%s)\n",protocol,host,port); /* Check if this local type is in the XLOCAL list */ TRANS(LocalInitTransports)("local"); @@ -2255,7 +2035,7 @@ TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, char *protocol, TRANS(LocalEndTransports)(); if (!found) { - PRMSG(3,"LocalOpenCOTSServer: disabling %s\n",thistrans->TransName,0,0); + prmsg(3,"LocalOpenCOTSServer: disabling %s\n",thistrans->TransName); thistrans->flags |= TRANS_DISABLED; return NULL; } @@ -2265,46 +2045,15 @@ TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, char *protocol, #endif /* TRANS_SERVER */ - -#ifdef TRANS_CLIENT - -static XtransConnInfo -TRANS(LocalOpenCLTSClient)(Xtransport *thistrans, char *protocol, - char *host, char *port) - -{ - PRMSG(2,"LocalOpenCLTSClient(%s,%s,%s)\n",protocol,host,port); - - return TRANS(LocalOpenClient)(XTRANS_OPEN_CLTS_CLIENT, protocol, host, port); -} - -#endif /* TRANS_CLIENT */ - - -#ifdef TRANS_SERVER - -static XtransConnInfo -TRANS(LocalOpenCLTSServer)(Xtransport *thistrans, char *protocol, - char *host, char *port) - -{ - PRMSG(2,"LocalOpenCLTSServer(%s,%s,%s)\n",protocol,host,port); - - return TRANS(LocalOpenServer)(XTRANS_OPEN_CLTS_SERVER, protocol, host, port); -} - -#endif /* TRANS_SERVER */ - - #ifdef TRANS_REOPEN static XtransConnInfo -TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, char *port) +TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, const char *port) { int index; - PRMSG(2,"LocalReopenCOTSServer(%d,%s)\n", fd, port, 0); + prmsg(2,"LocalReopenCOTSServer(%d,%s)\n", fd, port); for(index=1;index<NUMTRANSPORTS;index++) { @@ -2322,30 +2071,6 @@ TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, char *port) index, fd, port); } -static XtransConnInfo -TRANS(LocalReopenCLTSServer)(Xtransport *thistrans, int fd, char *port) - -{ - int index; - - 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); - } - - return TRANS(LocalReopenServer)(XTRANS_OPEN_CLTS_SERVER, - index, fd, port); -} - #endif /* TRANS_REOPEN */ @@ -2354,7 +2079,7 @@ static int TRANS(LocalSetOption)(XtransConnInfo ciptr, int option, int arg) { - PRMSG(2,"LocalSetOption(%d,%d,%d)\n",ciptr->fd,option,arg); + prmsg(2,"LocalSetOption(%d,%d,%d)\n",ciptr->fd,option,arg); return -1; } @@ -2363,14 +2088,31 @@ TRANS(LocalSetOption)(XtransConnInfo ciptr, int option, int arg) #ifdef TRANS_SERVER static int -TRANS(LocalCreateListener)(XtransConnInfo ciptr, char *port, unsigned int flags) +TRANS(LocalCreateListener)(XtransConnInfo ciptr, const char *port, + unsigned int flags _X_UNUSED) { - PRMSG(2,"LocalCreateListener(%x->%d,%s)\n",ciptr,ciptr->fd,port); + prmsg(2,"LocalCreateListener(%p->%d,%s)\n",ciptr,ciptr->fd,port); return 0; } +static int +TRANS(LocalResetListener)(XtransConnInfo ciptr) + +{ + LOCALtrans2dev *transptr; + + prmsg(2,"LocalResetListener(%p)\n",ciptr); + + transptr=(LOCALtrans2dev *)ciptr->priv; + if (transptr->devreset != NULL) { + return transptr->devreset(ciptr); + } + return TRANS_RESET_NOOP; +} + + static XtransConnInfo TRANS(LocalAccept)(XtransConnInfo ciptr, int *status) @@ -2378,14 +2120,14 @@ TRANS(LocalAccept)(XtransConnInfo ciptr, int *status) XtransConnInfo newciptr; LOCALtrans2dev *transptr; - PRMSG(2,"LocalAccept(%x->%d)\n", ciptr, ciptr->fd,0); + prmsg(2,"LocalAccept(%p->%d)\n", ciptr, ciptr->fd); transptr=(LOCALtrans2dev *)ciptr->priv; - if( (newciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo)))==NULL ) + if( (newciptr = calloc(1,sizeof(struct _XtransConnInfo)))==NULL ) { - PRMSG(1,"LocalAccept: calloc(1,%d) failed\n", - sizeof(struct _XtransConnInfo),0,0 ); + prmsg(1,"LocalAccept: calloc(1,%lu) failed\n", + sizeof(struct _XtransConnInfo)); *status = TRANS_ACCEPT_BAD_MALLOC; return NULL; } @@ -2412,10 +2154,11 @@ TRANS(LocalAccept)(XtransConnInfo ciptr, int *status) #ifdef TRANS_CLIENT static int -TRANS(LocalConnect)(XtransConnInfo ciptr, char *host, char *port) +TRANS(LocalConnect)(XtransConnInfo ciptr, + const char *host _X_UNUSED, const char *port) { - PRMSG(2,"LocalConnect(%x->%d,%s)\n", ciptr, ciptr->fd, port); + prmsg(2,"LocalConnect(%p->%d,%s)\n", ciptr, ciptr->fd, port); return 0; } @@ -2427,9 +2170,9 @@ static int TRANS(LocalBytesReadable)(XtransConnInfo ciptr, BytesReadable_t *pend ) { - PRMSG(2,"LocalBytesReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend); + prmsg(2,"LocalBytesReadable(%p->%d,%p)\n", ciptr, ciptr->fd, pend); -#if defined(ISC) || defined(SCO325) +#if defined(SCO325) return ioctl(ciptr->fd, I_NREAD, (char *)pend); #else return ioctl(ciptr->fd, FIONREAD, (char *)pend); @@ -2440,7 +2183,7 @@ static int TRANS(LocalRead)(XtransConnInfo ciptr, char *buf, int size) { - PRMSG(2,"LocalRead(%d,%x,%d)\n", ciptr->fd, buf, size ); + prmsg(2,"LocalRead(%d,%p,%d)\n", ciptr->fd, buf, size ); return read(ciptr->fd,buf,size); } @@ -2449,7 +2192,7 @@ static int TRANS(LocalWrite)(XtransConnInfo ciptr, char *buf, int size) { - PRMSG(2,"LocalWrite(%d,%x,%d)\n", ciptr->fd, buf, size ); + prmsg(2,"LocalWrite(%d,%p,%d)\n", ciptr->fd, buf, size ); return write(ciptr->fd,buf,size); } @@ -2458,7 +2201,7 @@ static int TRANS(LocalReadv)(XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG(2,"LocalReadv(%d,%x,%d)\n", ciptr->fd, buf, size ); + prmsg(2,"LocalReadv(%d,%p,%d)\n", ciptr->fd, buf, size ); return READV(ciptr,buf,size); } @@ -2467,7 +2210,7 @@ static int TRANS(LocalWritev)(XtransConnInfo ciptr, struct iovec *buf, int size) { - PRMSG(2,"LocalWritev(%d,%x,%d)\n", ciptr->fd, buf, size ); + prmsg(2,"LocalWritev(%d,%p,%d)\n", ciptr->fd, buf, size ); return WRITEV(ciptr,buf,size); } @@ -2476,7 +2219,7 @@ static int TRANS(LocalDisconnect)(XtransConnInfo ciptr) { - PRMSG(2,"LocalDisconnect(%x->%d)\n", ciptr, ciptr->fd, 0); + prmsg(2,"LocalDisconnect(%p->%d)\n", ciptr, ciptr->fd); return 0; } @@ -2488,7 +2231,7 @@ TRANS(LocalClose)(XtransConnInfo ciptr) struct sockaddr_un *sockname=(struct sockaddr_un *) ciptr->addr; int ret; - PRMSG(2,"LocalClose(%x->%d)\n", ciptr, ciptr->fd ,0); + prmsg(2,"LocalClose(%p->%d)\n", ciptr, ciptr->fd ); ret=close(ciptr->fd); @@ -2510,7 +2253,7 @@ TRANS(LocalCloseForCloning)(XtransConnInfo ciptr) { int ret; - PRMSG(2,"LocalCloseForCloning(%x->%d)\n", ciptr, ciptr->fd ,0); + prmsg(2,"LocalCloseForCloning(%p->%d)\n", ciptr, ciptr->fd ); /* Don't unlink path */ @@ -2524,22 +2267,22 @@ TRANS(LocalCloseForCloning)(XtransConnInfo ciptr) * MakeAllCOTSServerListeners() will go through the entire Xtransports[] * array defined in Xtrans.c and try to OpenCOTSServer() for each entry. * We will add duplicate entries to that table so that the OpenCOTSServer() - * function will get called once for each type of local transport. + * function will get called once for each type of local transport. * * The TransName is in lowercase, so it will never match during a normal * call to SelectTransport() in Xtrans.c. */ #ifdef TRANS_SERVER -static char * local_aliases[] = { -# ifndef sun +static const char * local_aliases[] = { +# ifdef LOCAL_TRANS_PTS "pts", # endif "named", -# ifndef sun -# if !defined(__SCO__) && !defined(__UNIXWARE__) - "isc", +# ifdef __sun + "pipe", /* compatibility with Solaris Xlib */ # endif +# ifdef LOCAL_TRANS_SCO "sco", # endif NULL }; @@ -2556,20 +2299,13 @@ Xtransport TRANS(LocalFuncs) = { local_aliases, TRANS(LocalOpenCOTSServer), #endif /* TRANS_SERVER */ -#ifdef TRANS_CLIENT - TRANS(LocalOpenCLTSClient), -#endif /* TRANS_CLIENT */ -#ifdef TRANS_SERVER - TRANS(LocalOpenCLTSServer), -#endif /* TRANS_SERVER */ #ifdef TRANS_REOPEN TRANS(LocalReopenCOTSServer), - TRANS(LocalReopenCLTSServer), #endif TRANS(LocalSetOption), #ifdef TRANS_SERVER TRANS(LocalCreateListener), - NULL, /* ResetListener */ + TRANS(LocalResetListener), TRANS(LocalAccept), #endif /* TRANS_SERVER */ #ifdef TRANS_CLIENT @@ -2580,12 +2316,16 @@ Xtransport TRANS(LocalFuncs) = { TRANS(LocalWrite), TRANS(LocalReadv), TRANS(LocalWritev), +#if XTRANS_SEND_FDS + TRANS(LocalSendFdInvalid), + TRANS(LocalRecvFdInvalid), +#endif TRANS(LocalDisconnect), TRANS(LocalClose), TRANS(LocalCloseForCloning), }; -#ifndef sun +#ifdef LOCAL_TRANS_PTS Xtransport TRANS(PTSFuncs) = { /* Local Interface */ @@ -2598,20 +2338,13 @@ Xtransport TRANS(PTSFuncs) = { NULL, TRANS(LocalOpenCOTSServer), #endif /* TRANS_SERVER */ -#ifdef TRANS_CLIENT - TRANS(LocalOpenCLTSClient), -#endif /* TRANS_CLIENT */ -#ifdef TRANS_SERVER - TRANS(LocalOpenCLTSServer), -#endif /* TRANS_SERVER */ #ifdef TRANS_REOPEN TRANS(LocalReopenCOTSServer), - TRANS(LocalReopenCLTSServer), #endif TRANS(LocalSetOption), #ifdef TRANS_SERVER TRANS(LocalCreateListener), - NULL, /* ResetListener */ + TRANS(LocalResetListener), TRANS(LocalAccept), #endif /* TRANS_SERVER */ #ifdef TRANS_CLIENT @@ -2622,12 +2355,18 @@ Xtransport TRANS(PTSFuncs) = { TRANS(LocalWrite), TRANS(LocalReadv), TRANS(LocalWritev), +#if XTRANS_SEND_FDS + TRANS(LocalSendFdInvalid), + TRANS(LocalRecvFdInvalid), +#endif TRANS(LocalDisconnect), TRANS(LocalClose), TRANS(LocalCloseForCloning), }; -#endif /* sun */ +#endif /* LOCAL_TRANS_PTS */ + +#ifdef LOCAL_TRANS_NAMED Xtransport TRANS(NAMEDFuncs) = { /* Local Interface */ @@ -2640,20 +2379,13 @@ Xtransport TRANS(NAMEDFuncs) = { NULL, TRANS(LocalOpenCOTSServer), #endif /* TRANS_SERVER */ -#ifdef TRANS_CLIENT - TRANS(LocalOpenCLTSClient), -#endif /* TRANS_CLIENT */ -#ifdef TRANS_SERVER - TRANS(LocalOpenCLTSServer), -#endif /* TRANS_SERVER */ #ifdef TRANS_REOPEN TRANS(LocalReopenCOTSServer), - TRANS(LocalReopenCLTSServer), #endif TRANS(LocalSetOption), #ifdef TRANS_SERVER TRANS(LocalCreateListener), - NULL, /* ResetListener */ + TRANS(LocalResetListener), TRANS(LocalAccept), #endif /* TRANS_SERVER */ #ifdef TRANS_CLIENT @@ -2664,17 +2396,20 @@ Xtransport TRANS(NAMEDFuncs) = { TRANS(LocalWrite), TRANS(LocalReadv), TRANS(LocalWritev), +#if XTRANS_SEND_FDS + TRANS(LocalSendFdInvalid), + TRANS(LocalRecvFdInvalid), +#endif TRANS(LocalDisconnect), TRANS(LocalClose), TRANS(LocalCloseForCloning), }; -#ifndef sun -#if !defined(__SCO__) && !defined(__UNIXWARE__) -Xtransport TRANS(ISCFuncs) = { +#ifdef __sun +Xtransport TRANS(PIPEFuncs) = { /* Local Interface */ - "isc", - TRANS_LOCAL, + "pipe", + TRANS_ALIAS | TRANS_LOCAL, #ifdef TRANS_CLIENT TRANS(LocalOpenCOTSClient), #endif /* TRANS_CLIENT */ @@ -2682,20 +2417,13 @@ Xtransport TRANS(ISCFuncs) = { NULL, TRANS(LocalOpenCOTSServer), #endif /* TRANS_SERVER */ -#ifdef TRANS_CLIENT - TRANS(LocalOpenCLTSClient), -#endif /* TRANS_CLIENT */ -#ifdef TRANS_SERVER - TRANS(LocalOpenCLTSServer), -#endif /* TRANS_SERVER */ #ifdef TRANS_REOPEN TRANS(LocalReopenCOTSServer), - TRANS(LocalReopenCLTSServer), #endif TRANS(LocalSetOption), #ifdef TRANS_SERVER TRANS(LocalCreateListener), - NULL, /* ResetListener */ + TRANS(LocalResetListener), TRANS(LocalAccept), #endif /* TRANS_SERVER */ #ifdef TRANS_CLIENT @@ -2706,11 +2434,19 @@ Xtransport TRANS(ISCFuncs) = { TRANS(LocalWrite), TRANS(LocalReadv), TRANS(LocalWritev), +#if XTRANS_SEND_FDS + TRANS(LocalSendFdInvalid), + TRANS(LocalRecvFdInvalid), +#endif TRANS(LocalDisconnect), TRANS(LocalClose), TRANS(LocalCloseForCloning), }; -#endif /* !__SCO__ && !__UNIXWARE__ */ +#endif /* __sun */ +#endif /* LOCAL_TRANS_NAMED */ + + +#ifdef LOCAL_TRANS_SCO Xtransport TRANS(SCOFuncs) = { /* Local Interface */ "sco", @@ -2722,20 +2458,13 @@ Xtransport TRANS(SCOFuncs) = { NULL, TRANS(LocalOpenCOTSServer), #endif /* TRANS_SERVER */ -#ifdef TRANS_CLIENT - TRANS(LocalOpenCLTSClient), -#endif /* TRANS_CLIENT */ -#ifdef TRANS_SERVER - TRANS(LocalOpenCLTSServer), -#endif /* TRANS_SERVER */ #ifdef TRANS_REOPEN TRANS(LocalReopenCOTSServer), - TRANS(LocalReopenCLTSServer), #endif TRANS(LocalSetOption), #ifdef TRANS_SERVER TRANS(LocalCreateListener), - NULL, /* ResetListener */ + TRANS(LocalResetListener), TRANS(LocalAccept), #endif /* TRANS_SERVER */ #ifdef TRANS_CLIENT @@ -2746,8 +2475,12 @@ Xtransport TRANS(SCOFuncs) = { TRANS(LocalWrite), TRANS(LocalReadv), TRANS(LocalWritev), +#if XTRANS_SEND_FDS + TRANS(LocalSendFdInvalid), + TRANS(LocalRecvFdInvalid), +#endif TRANS(LocalDisconnect), TRANS(LocalClose), TRANS(LocalCloseForCloning), }; -#endif /* sun */ +#endif /* LOCAL_TRANS_SCO */ |