aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/xtrans/Xtranslcl.c
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2016-10-31 02:29:18 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-11-02 19:46:36 +0100
commite65b106a8989bf5d71de613f5f8b9dcbd559d382 (patch)
treebdd95de44084c0460bef9c90bcfb82736e3ff834 /nx-X11/lib/xtrans/Xtranslcl.c
parent793d587b46a7ec47ea62d99920de4dc607514604 (diff)
downloadnx-libs-e65b106a8989bf5d71de613f5f8b9dcbd559d382.tar.gz
nx-libs-e65b106a8989bf5d71de613f5f8b9dcbd559d382.tar.bz2
nx-libs-e65b106a8989bf5d71de613f5f8b9dcbd559d382.zip
Xtrans: update to Xorg/xtrans upstream (1.3.5+)
This lifts xtrans to the state of this commit: commit 560d7550e23e9b14056b4a9b2569c2f256015f8a Author: Jeremy Huddleston Sequoia <jeremyhu@apple.com> Date: Sat Sep 10 22:09:51 2016 -0700 Update strlcpy macro check to also check HAVE_STRLCPY xorg-server moved from HAS_STRLCPY to HAVE_STRLCPY in 2011 cf-xserver: d829a7c5cb42c979b58f3547136df5b05d906423 Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Diffstat (limited to 'nx-X11/lib/xtrans/Xtranslcl.c')
-rw-r--r--nx-X11/lib/xtrans/Xtranslcl.c855
1 files changed, 353 insertions, 502 deletions
diff --git a/nx-X11/lib/xtrans/Xtranslcl.c b/nx-X11/lib/xtrans/Xtranslcl.c
index cf11cc2fa..7231d2a83 100644
--- a/nx-X11/lib/xtrans/Xtranslcl.c
+++ b/nx-X11/lib/xtrans/Xtranslcl.c
@@ -75,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>
@@ -99,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.
@@ -111,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;
@@ -120,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;
@@ -128,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;
@@ -140,7 +169,7 @@ 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");
return 0;
@@ -150,6 +179,7 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
if (strlen(sun_path) > sizeof(sunaddr->sun_path) - 1) {
prmsg(1, "FillAddrInfo: path too long\n");
+ free((char *) sunaddr);
return 0;
}
strcpy (sunaddr->sun_path, sun_path);
@@ -161,12 +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");
- free ((char *) sunaddr);
+ free (sunaddr);
ciptr->addr = NULL;
return 0;
@@ -176,6 +205,7 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
if (strlen(peer_sun_path) > sizeof(p_sunaddr->sun_path) - 1) {
prmsg(1, "FillAddrInfo: peer path too long\n");
+ free((char *) p_sunaddr);
return 0;
}
strcpy (p_sunaddr->sun_path, peer_sun_path);
@@ -190,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
@@ -206,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
@@ -222,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.
@@ -264,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"
@@ -279,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
@@ -303,12 +338,14 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
#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());
}
@@ -328,6 +365,7 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
if ((fd = open(DEV_PTMX, O_RDWR)) < 0) {
prmsg(1,"PTSOpenClient: failed to open %s\n", DEV_PTMX);
+ close(server);
return(-1);
}
@@ -432,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
@@ -591,7 +629,7 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
*/
newciptr->addrlen=ciptr->addrlen;
- if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) {
+ 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;
@@ -601,7 +639,7 @@ 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 ) {
+ if( (sunaddr = malloc(newciptr->peeraddrlen)) == NULL ) {
prmsg(1,"PTSAccept: failed to allocate memory for peer addr\n");
free(newciptr->addr);
close(newfd);
@@ -623,24 +661,26 @@ 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);
@@ -651,29 +691,32 @@ TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, char *port)
#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 ((fd = open(server_path, O_RDWR)) < 0) {
+ prmsg(1,"NAMEDOpenClient: Cannot open %s for NAMED connection\n", server_path);
+ return -1;
}
- if (stat(server_path, &filestat) < 0 ) {
- prmsg(1,"NAMEDOpenClient: No device %s for NAMED connection\n", server_path);
+ if (fstat(fd, &filestat) < 0 ) {
+ prmsg(1,"NAMEDOpenClient: Cannot stat %s for NAMED connection\n", server_path);
+ (void) close(fd);
return -1;
}
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 ((fd = open(server_path, O_RDWR)) < 0) {
- prmsg(1,"NAMEDOpenClient: Cannot open %s for NAMED connection\n", server_path);
- return -1;
- }
if (isastream(fd) <= 0) {
prmsg(1,"NAMEDOpenClient: %s is not a streams device\n", server_path);
@@ -702,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);
-
-#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) 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;
@@ -735,7 +762,7 @@ 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",
+ prmsg (1, "NAMEDOpenPipe: mkdir(%s) failed, errno = %d\n",
X_STREAMS_DIR, errno);
return(-1);
}
@@ -743,39 +770,74 @@ TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, char *port)
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);
+ 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);
+ prmsg(1, "NAMEDOpenPipe: Can't open %s\n", server_path);
return(-1);
}
} else {
- prmsg(1, "NAMEDOpenServer: stat on %s failed\n", server_path);
+ 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);
+ 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);
+ 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);
+ 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.
*/
@@ -783,21 +845,50 @@ TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, char *port)
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 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);
+ 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);
@@ -808,11 +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 ) {
+ if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) {
prmsg(1,
- "NAMEDAccept: failed to allocate memory for peer addr\n");
+ "NAMEDAccept: failed to allocate memory for pipe addr\n");
close(str.fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -821,7 +912,7 @@ 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 ) {
+ if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) {
prmsg(1,
"NAMEDAccept: failed to allocate memory for peer addr\n");
free(newciptr->addr);
@@ -839,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)
@@ -871,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
@@ -897,291 +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);
-
-#if !defined(ISCDEVNODENAME)
- prmsg(1,"ISCOpenClient: Protocol is not supported by a ISC connection\n");
- 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);
- 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);
- }
- }
- }
-
- 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);
- }
- }
- }
- }
-
- if (server < 0) {
- prmsg(1,"ISCOpenClient: can't open either device %s or %s\n",
- server_path, server_dev_path);
- 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);
- (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");
- (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");
- 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);
-
-#if !defined(ISCDEVNODENAME)
- prmsg(1,"ISCOpenServer: Protocol is not supported by a ISC connection\n");
- 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);
- 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);
- 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);
- return -1;
- }
-
- if( (connect_spipe(fds, fd) < 0) ||
- (named_spipe(fds, server_path) < 0)) {
- prmsg(1,"ISCOpenServer: failed connect pipes\n");
- 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);
- 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);
- /*
- * 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);
- /*
- * 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");
- 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);
-
- while (ioctl(ciptr->fd, I_RECVFD, &str) < 0) {
- if (errno != EAGAIN) {
- prmsg(1,"ISCAccept: Can't read fildes");
- *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");
- 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");
- 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 */
/*
@@ -1202,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;
@@ -1290,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];
@@ -1318,6 +1130,10 @@ 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);
+ if (fds >= 0)
+ close(fds);
+ if (fdr >= 0)
+ close(fdr);
return -1;
}
@@ -1357,7 +1173,7 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port)
}
fdr = open (serverR_path, O_RDWR | O_NDELAY);
- if (fds < 0) {
+ if (fdr < 0) {
prmsg(1,"SCOOpenServer: failed to open %s\n", serverR_path);
close (fds);
return -1;
@@ -1423,7 +1239,7 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
*/
newciptr->addrlen=ciptr->addrlen;
- if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) {
+ if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) {
prmsg(1,
"SCOAccept: failed to allocate memory for peer addr\n");
close(fd);
@@ -1437,7 +1253,7 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
#endif
newciptr->peeraddrlen=newciptr->addrlen;
- if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) {
+ if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) {
prmsg(1,
"SCOAccept: failed to allocate memory for peer addr\n");
free(newciptr->addr);
@@ -1454,15 +1270,15 @@ 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
@@ -1477,12 +1293,14 @@ TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, char *port)
#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)
@@ -1496,10 +1314,12 @@ 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
@@ -1514,12 +1334,14 @@ TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd, char *port)
#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)
@@ -1533,39 +1355,12 @@ 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);
-
-#if !defined(ISCDEVNODENAME)
- prmsg(1,"ISCReopenServer: Protocol is not supported by a ISC connection\n");
- 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");
- return 0;
- }
+#endif /* LOCAL_TRANS_NAMED */
- 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
@@ -1597,7 +1392,7 @@ TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port)
#endif /* SCORNODENAME */
}
-#endif /* !sun */
+#endif /* LOCAL_TRANS_SCO */
#endif /* TRANS_REOPEN */
@@ -1609,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 */
@@ -1622,7 +1417,7 @@ typedef struct _LOCALtrans2dev {
#ifdef TRANS_SERVER
int (*devcotsopenserver)(
- XtransConnInfo, char * /*port*/
+ XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_SERVER */
@@ -1630,7 +1425,7 @@ typedef struct _LOCALtrans2dev {
#ifdef TRANS_CLIENT
int (*devcltsopenclient)(
- XtransConnInfo, char * /*port*/
+ XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_CLIENT */
@@ -1638,7 +1433,7 @@ typedef struct _LOCALtrans2dev {
#ifdef TRANS_SERVER
int (*devcltsopenserver)(
- XtransConnInfo, char * /*port*/
+ XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_SERVER */
@@ -1648,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 *
);
@@ -1670,7 +1469,7 @@ typedef struct _LOCALtrans2dev {
} LOCALtrans2dev;
static LOCALtrans2dev LOCALtrans2devtab[] = {
-#ifndef sun
+#ifdef LOCAL_TRANS_PTS
{"",
#ifdef TRANS_CLIENT
TRANS(PTSOpenClient),
@@ -1689,6 +1488,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ NULL, /* ResetListener */
TRANS(PTSAccept)
#endif /* TRANS_SERVER */
},
@@ -1711,6 +1511,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ NULL, /* ResetListener */
TRANS(PTSAccept)
#endif /* TRANS_SERVER */
},
@@ -1733,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),
@@ -1755,6 +1557,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ TRANS(NAMEDResetListener),
TRANS(NAMEDAccept)
#endif /* TRANS_SERVER */
},
@@ -1777,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),
@@ -1801,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),
@@ -1822,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),
@@ -1849,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;
@@ -1865,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);
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);
}
}
@@ -1925,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);
@@ -1953,7 +1759,7 @@ TRANS(LocalGetNextTransport)(void)
*/
static int
-HostReallyLocal (char *host)
+HostReallyLocal (const char *host)
{
/*
@@ -1983,7 +1789,8 @@ 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;
@@ -2021,9 +1828,9 @@ 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",
+ prmsg(1,"LocalOpenClient: calloc(1,%lu) failed\n",
sizeof(struct _XtransConnInfo));
return NULL;
}
@@ -2074,7 +1881,8 @@ 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;
@@ -2091,9 +1899,9 @@ 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",
+ prmsg(1,"LocalOpenServer: calloc(1,%lu) failed\n",
sizeof(struct _XtransConnInfo));
return NULL;
}
@@ -2133,7 +1941,7 @@ 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;
@@ -2141,9 +1949,9 @@ TRANS(LocalReopenServer)(int type, int index, int fd, char *port)
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",
+ prmsg(1,"LocalReopenServer: calloc(1,%lu) failed\n",
sizeof(struct _XtransConnInfo));
return NULL;
}
@@ -2182,8 +1990,8 @@ 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);
@@ -2197,8 +2005,8 @@ 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;
@@ -2240,7 +2048,7 @@ TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, char *protocol,
#ifdef TRANS_REOPEN
static XtransConnInfo
-TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, char *port)
+TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, const char *port)
{
int index;
@@ -2280,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)
@@ -2295,13 +2120,13 @@ TRANS(LocalAccept)(XtransConnInfo ciptr, int *status)
XtransConnInfo newciptr;
LOCALtrans2dev *transptr;
- prmsg(2,"LocalAccept(%x->%d)\n", ciptr, ciptr->fd);
+ 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",
+ prmsg(1,"LocalAccept: calloc(1,%lu) failed\n",
sizeof(struct _XtransConnInfo));
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
@@ -2329,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;
}
@@ -2344,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);
@@ -2357,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);
}
@@ -2366,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);
}
@@ -2375,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);
}
@@ -2384,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);
}
@@ -2393,7 +2219,7 @@ static int
TRANS(LocalDisconnect)(XtransConnInfo ciptr)
{
- prmsg(2,"LocalDisconnect(%x->%d)\n", ciptr, ciptr->fd);
+ prmsg(2,"LocalDisconnect(%p->%d)\n", ciptr, ciptr->fd);
return 0;
}
@@ -2405,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 );
+ prmsg(2,"LocalClose(%p->%d)\n", ciptr, ciptr->fd );
ret=close(ciptr->fd);
@@ -2427,7 +2253,7 @@ TRANS(LocalCloseForCloning)(XtransConnInfo ciptr)
{
int ret;
- prmsg(2,"LocalCloseForCloning(%x->%d)\n", ciptr, ciptr->fd );
+ prmsg(2,"LocalCloseForCloning(%p->%d)\n", ciptr, ciptr->fd );
/* Don't unlink path */
@@ -2448,15 +2274,15 @@ TRANS(LocalCloseForCloning)(XtransConnInfo ciptr)
*/
#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 };
@@ -2479,7 +2305,7 @@ Xtransport TRANS(LocalFuncs) = {
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2490,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 */
@@ -2514,7 +2344,7 @@ Xtransport TRANS(PTSFuncs) = {
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2525,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 */
@@ -2549,7 +2385,7 @@ Xtransport TRANS(NAMEDFuncs) = {
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2560,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 */
@@ -2584,7 +2423,7 @@ Xtransport TRANS(ISCFuncs) = {
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2595,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",
@@ -2617,7 +2464,7 @@ Xtransport TRANS(SCOFuncs) = {
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2628,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 */