aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/xtrans
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
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')
-rw-r--r--nx-X11/lib/xtrans/Xtrans.c309
-rw-r--r--nx-X11/lib/xtrans/Xtrans.h117
-rw-r--r--nx-X11/lib/xtrans/Xtransint.h82
-rw-r--r--nx-X11/lib/xtrans/Xtranslcl.c855
-rw-r--r--nx-X11/lib/xtrans/Xtranssock.c826
-rw-r--r--nx-X11/lib/xtrans/Xtransutil.c60
-rw-r--r--nx-X11/lib/xtrans/transport.c15
7 files changed, 1352 insertions, 912 deletions
diff --git a/nx-X11/lib/xtrans/Xtrans.c b/nx-X11/lib/xtrans/Xtrans.c
index f21ec3618..8a88cd4a6 100644
--- a/nx-X11/lib/xtrans/Xtrans.c
+++ b/nx-X11/lib/xtrans/Xtrans.c
@@ -48,6 +48,11 @@ from The Open Group.
*/
#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_SYSTEMD_DAEMON
+#include <systemd/sd-daemon.h>
+#endif
/*
* The transport table contains a definition for every transport (protocol)
@@ -72,9 +77,10 @@ from The Open Group.
#define TRANS_LOCAL_LOCAL_INDEX 9
#define TRANS_LOCAL_PTS_INDEX 10
#define TRANS_LOCAL_NAMED_INDEX 11
-#define TRANS_LOCAL_ISC_INDEX 12
+/* 12 used to be ISC, but that's gone. */
#define TRANS_LOCAL_SCO_INDEX 13
#define TRANS_SOCKET_INET6_INDEX 14
+#define TRANS_LOCAL_PIPE_INDEX 15
static
@@ -94,18 +100,18 @@ Xtransport_table Xtransports[] = {
#endif /* UNIXCONN */
#if defined(LOCALCONN)
{ &TRANS(LocalFuncs), TRANS_LOCAL_LOCAL_INDEX },
-#ifndef sun
+#ifndef __sun
{ &TRANS(PTSFuncs), TRANS_LOCAL_PTS_INDEX },
-#endif /* sun */
-#ifdef SVR4
+#endif /* __sun */
+#if defined(SVR4) || defined(__SVR4)
{ &TRANS(NAMEDFuncs), TRANS_LOCAL_NAMED_INDEX },
#endif
-#ifndef sun
-#if !defined(__SCO__) && !defined(__UNIXWARE__)
- { &TRANS(ISCFuncs), TRANS_LOCAL_ISC_INDEX },
-#endif
+#ifdef __sun
+ { &TRANS(PIPEFuncs), TRANS_LOCAL_PIPE_INDEX },
+#endif /* __sun */
+#if defined(__SCO__) || defined(__UNIXWARE__)
{ &TRANS(SCOFuncs), TRANS_LOCAL_SCO_INDEX },
-#endif /* sun */
+#endif /* __SCO__ || __UNIXWARE__ */
#endif /* LOCALCONN */
};
@@ -137,14 +143,14 @@ TRANS(FreeConnInfo) (XtransConnInfo ciptr)
if (ciptr->port)
free (ciptr->port);
- free ((char *) ciptr);
+ free (ciptr);
}
#define PROTOBUFSIZE 20
static Xtransport *
-TRANS(SelectTransport) (char *protocol)
+TRANS(SelectTransport) (const char *protocol)
{
char protobuf[PROTOBUFSIZE];
@@ -161,8 +167,8 @@ TRANS(SelectTransport) (char *protocol)
protobuf[PROTOBUFSIZE-1] = '\0';
for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++)
- if (isupper (protobuf[i]))
- protobuf[i] = tolower (protobuf[i]);
+ if (isupper ((unsigned char)protobuf[i]))
+ protobuf[i] = tolower ((unsigned char)protobuf[i]);
/* Look at all of the configured protocols */
@@ -179,7 +185,8 @@ TRANS(SelectTransport) (char *protocol)
static
#endif /* TEST_t */
int
-TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
+TRANS(ParseAddress) (const char *address,
+ char **protocol, char **host, char **port)
{
/*
@@ -193,10 +200,12 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*
* If the protocol part is missing, then assume TCP.
* If the protocol part and host part are missing, then assume local.
+ * If a "::" is found then assume DNET.
*/
char *mybuf, *tmpptr;
- char *_protocol, *_host, *_port;
+ const char *_protocol;
+ char *_host, *_port;
char hostnamebuf[256];
int _host_len;
@@ -204,8 +213,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
/* Copy the string so it can be changed */
- tmpptr = mybuf = (char *) malloc (strlen (address) + 1);
- strcpy (mybuf, address);
+ tmpptr = mybuf = strdup (address);
/* Parse the string to get each component */
@@ -324,12 +332,21 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*/
#endif
+#ifdef HAVE_LAUNCHD
+ /* launchd sockets will look like 'local//tmp/launch-XgkNns/:0' */
+ if(address != NULL && strlen(address)>8 && (!strncmp(address,"local//",7))) {
+ _protocol="local";
+ _host="";
+ _port=address+6;
+ }
+#endif
+
/*
* Now that we have all of the components, allocate new
* string space for them.
*/
- if ((*protocol = (char *) malloc(strlen (_protocol) + 1)) == NULL)
+ if ((*protocol = strdup (_protocol)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -338,10 +355,8 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
free (tmpptr);
return 0;
}
- else
- strcpy (*protocol, _protocol);
- if ((*host = (char *) malloc (strlen (_host) + 1)) == NULL)
+ if ((*host = strdup (_host)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -351,10 +366,8 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
free (tmpptr);
return 0;
}
- else
- strcpy (*host, _host);
- if ((*port = (char *) malloc (strlen (_port) + 1)) == NULL)
+ if ((*port = strdup (_port)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -365,8 +378,6 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
free (tmpptr);
return 0;
}
- else
- strcpy (*port, _port);
free (tmpptr);
@@ -381,7 +392,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*/
static XtransConnInfo
-TRANS(Open) (int type, char *address)
+TRANS(Open) (int type, const char *address)
{
char *protocol = NULL, *host = NULL, *port = NULL;
@@ -469,7 +480,7 @@ TRANS(Open) (int type, char *address)
*/
static XtransConnInfo
-TRANS(Reopen) (int type, int trans_id, int fd, char *port)
+TRANS(Reopen) (int type, int trans_id, int fd, const char *port)
{
XtransConnInfo ciptr = NULL;
@@ -496,15 +507,13 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
return NULL;
}
- if ((save_port = (char *) malloc (strlen (port) + 1)) == NULL)
+ if ((save_port = strdup (port)) == NULL)
{
prmsg (1,"Reopen: Unable to malloc port string\n");
return NULL;
}
- strcpy (save_port, port);
-
/* Get a new XtransConnInfo object */
switch (type)
@@ -519,6 +528,7 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
if (ciptr == NULL)
{
prmsg (1,"Reopen: transport open failed\n");
+ free (save_port);
return NULL;
}
@@ -541,7 +551,7 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
#ifdef TRANS_CLIENT
XtransConnInfo
-TRANS(OpenCOTSClient) (char *address)
+TRANS(OpenCOTSClient) (const char *address)
{
prmsg (2,"OpenCOTSClient(%s)\n", address);
@@ -554,7 +564,7 @@ TRANS(OpenCOTSClient) (char *address)
#ifdef TRANS_SERVER
XtransConnInfo
-TRANS(OpenCOTSServer) (char *address)
+TRANS(OpenCOTSServer) (const char *address)
{
prmsg (2,"OpenCOTSServer(%s)\n", address);
@@ -567,7 +577,7 @@ TRANS(OpenCOTSServer) (char *address)
#ifdef TRANS_REOPEN
XtransConnInfo
-TRANS(ReopenCOTSServer) (int trans_id, int fd, char *port)
+TRANS(ReopenCOTSServer) (int trans_id, int fd, const char *port)
{
prmsg (2,"ReopenCOTSServer(%d, %d, %s)\n", trans_id, fd, port);
@@ -587,13 +597,10 @@ TRANS(GetReopenInfo) (XtransConnInfo ciptr,
*trans_id = Xtransports[i].transport_id;
*fd = ciptr->fd;
- if ((*port = (char *) malloc (strlen (ciptr->port) + 1)) == NULL)
+ if ((*port = strdup (ciptr->port)) == NULL)
return 0;
else
- {
- strcpy (*port, ciptr->port);
return 1;
- }
}
return 0;
@@ -631,7 +638,7 @@ TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
break;
case 1: /* Set to non-blocking mode */
-#if defined(O_NONBLOCK) && (!defined(ultrix) && !defined(uniosu) && !defined(SCO325))
+#if defined(O_NONBLOCK) && !defined(SCO325)
ret = fcntl (fd, F_GETFL, 0);
if (ret != -1)
ret = fcntl (fd, F_SETFL, ret | O_NONBLOCK);
@@ -643,7 +650,7 @@ TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
ret = ioctl (fd, FIOSNBIO, &arg);
}
#else
-#if (defined(uniosu) || defined(WIN32)) && defined(FIONBIO)
+#if defined(WIN32)
{
#ifdef WIN32
u_long arg;
@@ -662,7 +669,7 @@ TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
#else
ret = fcntl (fd, F_SETFL, ret | O_NDELAY);
#endif
-#endif /* uniosu */
+#endif /* AIXV3 || uniosu */
#endif /* FIOSNBIO */
#endif /* O_NONBLOCK */
break;
@@ -688,14 +695,42 @@ TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
#ifdef TRANS_SERVER
int
-TRANS(CreateListener) (XtransConnInfo ciptr, char *port, unsigned int flags)
+TRANS(CreateListener) (XtransConnInfo ciptr, const char *port, unsigned int flags)
{
return ciptr->transptr->CreateListener (ciptr, port, flags);
}
int
-TRANS(NoListen) (char * protocol)
+TRANS(Received) (const char * protocol)
+
+{
+ Xtransport *trans;
+ int i = 0, ret = 0;
+
+ prmsg (5, "Received(%s)\n", protocol);
+
+ if ((trans = TRANS(SelectTransport)(protocol)) == NULL)
+ {
+ prmsg (1,"Received: unable to find transport: %s\n",
+ protocol);
+
+ return -1;
+ }
+ if (trans->flags & TRANS_ALIAS) {
+ if (trans->nolisten)
+ while (trans->nolisten[i]) {
+ ret |= TRANS(Received)(trans->nolisten[i]);
+ i++;
+ }
+ }
+
+ trans->flags |= TRANS_RECEIVED;
+ return ret;
+}
+
+int
+TRANS(NoListen) (const char * protocol)
{
Xtransport *trans;
@@ -721,6 +756,47 @@ TRANS(NoListen) (char * protocol)
}
int
+TRANS(Listen) (const char * protocol)
+{
+ Xtransport *trans;
+ int i = 0, ret = 0;
+
+ if ((trans = TRANS(SelectTransport)(protocol)) == NULL)
+ {
+ prmsg (1,"TransListen: unable to find transport: %s\n",
+ protocol);
+
+ return -1;
+ }
+ if (trans->flags & TRANS_ALIAS) {
+ if (trans->nolisten)
+ while (trans->nolisten[i]) {
+ ret |= TRANS(Listen)(trans->nolisten[i]);
+ i++;
+ }
+ }
+
+ trans->flags &= ~TRANS_NOLISTEN;
+ return ret;
+}
+
+int
+TRANS(IsListening) (const char * protocol)
+{
+ Xtransport *trans;
+
+ if ((trans = TRANS(SelectTransport)(protocol)) == NULL)
+ {
+ prmsg (1,"TransIsListening: unable to find transport: %s\n",
+ protocol);
+
+ return 0;
+ }
+
+ return !(trans->flags & TRANS_NOLISTEN);
+}
+
+int
TRANS(ResetListener) (XtransConnInfo ciptr)
{
@@ -753,7 +829,7 @@ TRANS(Accept) (XtransConnInfo ciptr, int *status)
#ifdef TRANS_CLIENT
int
-TRANS(Connect) (XtransConnInfo ciptr, char *address)
+TRANS(Connect) (XtransConnInfo ciptr, const char *address)
{
char *protocol;
@@ -770,6 +846,10 @@ TRANS(Connect) (XtransConnInfo ciptr, char *address)
return -1;
}
+#ifdef HAVE_LAUNCHD
+ if (!host) host=strdup("");
+#endif
+
if (!port || !*port)
{
prmsg (1,"Connect: Missing port specification in %s\n",
@@ -826,6 +906,20 @@ TRANS(Writev) (XtransConnInfo ciptr, struct iovec *buf, int size)
return ciptr->transptr->Writev (ciptr, buf, size);
}
+#if XTRANS_SEND_FDS
+int
+TRANS(SendFd) (XtransConnInfo ciptr, int fd, int do_close)
+{
+ return ciptr->transptr->SendFd(ciptr, fd, do_close);
+}
+
+int
+TRANS(RecvFd) (XtransConnInfo ciptr)
+{
+ return ciptr->transptr->RecvFd(ciptr);
+}
+#endif
+
int
TRANS(Disconnect) (XtransConnInfo ciptr)
@@ -870,10 +964,11 @@ TRANS(IsLocal) (XtransConnInfo ciptr)
return (ciptr->family == AF_UNIX);
}
-
+#ifdef NX_TRANS_SOCKET
+/* this is needed for pre-xcb X11 as we have in NX */
int
TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
- Xtransaddr **addrp)
+ Xtransaddr **addrp)
{
prmsg (2,"GetMyAddr(%d)\n", ciptr->fd);
@@ -883,13 +978,14 @@ TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
if ((*addrp = (Xtransaddr *) malloc (ciptr->addrlen)) == NULL)
{
- prmsg (1,"GetMyAddr: malloc failed\n");
- return -1;
+ prmsg (1,"GetMyAddr: malloc failed\n");
+ return -1;
}
memcpy(*addrp, ciptr->addr, ciptr->addrlen);
return 0;
}
+#endif
int
TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
@@ -901,7 +997,7 @@ TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
*familyp = ciptr->family;
*addrlenp = ciptr->peeraddrlen;
- if ((*addrp = (Xtransaddr *) malloc (ciptr->peeraddrlen)) == NULL)
+ if ((*addrp = malloc (ciptr->peeraddrlen)) == NULL)
{
prmsg (1,"GetPeerAddr: malloc failed\n");
return -1;
@@ -956,33 +1052,126 @@ complete_network_count (void)
}
+static int
+receive_listening_fds(const char* port, XtransConnInfo* temp_ciptrs,
+ int* count_ret)
+
+{
+#ifdef HAVE_SYSTEMD_DAEMON
+ XtransConnInfo ciptr;
+ int i, systemd_listen_fds;
+
+ systemd_listen_fds = sd_listen_fds(1);
+ if (systemd_listen_fds < 0)
+ {
+ prmsg (1, "receive_listening_fds: sd_listen_fds error: %s\n",
+ strerror(-systemd_listen_fds));
+ return -1;
+ }
+
+ for (i = 0; i < systemd_listen_fds && *count_ret < NUMTRANS; i++)
+ {
+ struct sockaddr_storage a;
+ int ti;
+ const char* tn;
+ socklen_t al;
+
+ al = sizeof(a);
+ if (getsockname(i + SD_LISTEN_FDS_START, (struct sockaddr*)&a, &al) < 0) {
+ prmsg (1, "receive_listening_fds: getsockname error: %s\n",
+ strerror(errno));
+ return -1;
+ }
+
+ switch (a.ss_family)
+ {
+ case AF_UNIX:
+ ti = TRANS_SOCKET_UNIX_INDEX;
+ if (*((struct sockaddr_un*)&a)->sun_path == '\0' &&
+ al > sizeof(sa_family_t))
+ tn = "local";
+ else
+ tn = "unix";
+ break;
+ case AF_INET:
+ ti = TRANS_SOCKET_INET_INDEX;
+ tn = "inet";
+ break;
+#if defined(IPv6) && defined(AF_INET6)
+ case AF_INET6:
+ ti = TRANS_SOCKET_INET6_INDEX;
+ tn = "inet6";
+ break;
+#endif /* IPv6 */
+ default:
+ prmsg (1, "receive_listening_fds:"
+ "Got unknown socket address family\n");
+ return -1;
+ }
+
+ ciptr = TRANS(ReopenCOTSServer)(ti, i + SD_LISTEN_FDS_START, port);
+ if (!ciptr)
+ {
+ prmsg (1, "receive_listening_fds:"
+ "Got NULL while trying to reopen socket received from systemd.\n");
+ return -1;
+ }
+
+ prmsg (5, "receive_listening_fds: received listener for %s, %d\n",
+ tn, ciptr->fd);
+ temp_ciptrs[(*count_ret)++] = ciptr;
+ TRANS(Received)(tn);
+ }
+#endif /* HAVE_SYSTEMD_DAEMON */
+ return 0;
+}
+
+#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD
+extern int xquartz_launchd_fd;
+#endif
int
-TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
- XtransConnInfo **ciptrs_ret)
+TRANS(MakeAllCOTSServerListeners) (const char *port, int *partial,
+ int *count_ret, XtransConnInfo **ciptrs_ret)
{
char buffer[256]; /* ??? What size ?? */
XtransConnInfo ciptr, temp_ciptrs[NUMTRANS];
int status, i, j;
+
#if defined(IPv6) && defined(AF_INET6)
int ipv6_succ = 0;
#endif
-
prmsg (2,"MakeAllCOTSServerListeners(%s,%p)\n",
port ? port : "NULL", ciptrs_ret);
*count_ret = 0;
+#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD
+ fprintf(stderr, "Launchd socket fd: %d\n", xquartz_launchd_fd);
+ if(xquartz_launchd_fd != -1) {
+ if((ciptr = TRANS(ReopenCOTSServer(TRANS_SOCKET_LOCAL_INDEX,
+ xquartz_launchd_fd, getenv("DISPLAY"))))==NULL)
+ fprintf(stderr,"Got NULL while trying to Reopen launchd port\n");
+ else
+ temp_ciptrs[(*count_ret)++] = ciptr;
+ }
+#endif
+
+ if (receive_listening_fds(port, temp_ciptrs, count_ret) < 0)
+ return -1;
+
for (i = 0; i < NUMTRANS; i++)
{
Xtransport *trans = Xtransports[i].transport;
unsigned int flags = 0;
- if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN)
+ if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN ||
+ trans->flags&TRANS_RECEIVED)
continue;
- sprintf(buffer,"%s/:%s", trans->TransName, port ? port : "");
+ snprintf(buffer, sizeof(buffer), "%s/:%s",
+ trans->TransName, port ? port : "");
prmsg (5,"MakeAllCOTSServerListeners: opening %s\n",
buffer);
@@ -1055,7 +1244,7 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
if (*count_ret > 0)
{
- if ((*ciptrs_ret = (XtransConnInfo *) malloc (
+ if ((*ciptrs_ret = malloc (
*count_ret * sizeof (XtransConnInfo))) == NULL)
{
return -1;
@@ -1081,7 +1270,8 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
* may be used by it.
*/
-#if (defined(SYSV) && defined(__i386__) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__)
+
+#ifdef WIN32
/*
* emulate readv
@@ -1111,9 +1301,6 @@ static int TRANS(ReadV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt)
return total;
}
-#endif /* SYSV && __i386__ || WIN32 || __sxg__ */
-
-#if (defined(SYSV) && defined(__i386__) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__)
/*
* emulate writev
@@ -1143,10 +1330,10 @@ static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt)
return total;
}
-#endif /* SYSV && __i386__ || WIN32 || __sxg__ */
+#endif /* WIN32 */
-#if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SCO__)
+#if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__)
#ifndef NEED_UTSNAME
#define NEED_UTSNAME
#endif
diff --git a/nx-X11/lib/xtrans/Xtrans.h b/nx-X11/lib/xtrans/Xtrans.h
index 2ab5ac3fe..54b2a1425 100644
--- a/nx-X11/lib/xtrans/Xtrans.h
+++ b/nx-X11/lib/xtrans/Xtrans.h
@@ -52,117 +52,75 @@ from The Open Group.
#include <nx-X11/Xfuncproto.h>
#include <nx-X11/Xos.h>
+#include <nx-X11/Xmd.h>
#ifndef WIN32
#include <sys/socket.h>
#endif
+#ifdef __clang__
+/* Not all clients make use of all provided statics */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
/*
* Set the functions names according to where this code is being compiled.
*/
#ifdef X11_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _X11Trans##func
-#else
-#define TRANS(func) _X11Trans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_X11Trans";
+static const char *__xtransname = "_X11Trans";
#endif
#endif /* X11_t */
#ifdef XSERV_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _XSERVTrans##func
-#else
-#define TRANS(func) _XSERVTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_XSERVTrans";
+static const char *__xtransname = "_XSERVTrans";
#endif
#define X11_t
#endif /* XSERV_t */
#ifdef XIM_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _XimXTrans##func
-#else
-#define TRANS(func) _XimXTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_XimTrans";
+static const char *__xtransname = "_XimTrans";
#endif
#endif /* XIM_t */
#ifdef FS_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _FSTrans##func
-#else
-#define TRANS(func) _FSTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_FSTrans";
+static const char *__xtransname = "_FSTrans";
#endif
#endif /* FS_t */
#ifdef FONT_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _FontTrans##func
-#else
-#define TRANS(func) _FontTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_FontTrans";
+static const char *__xtransname = "_FontTrans";
#endif
#endif /* FONT_t */
#ifdef ICE_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _IceTrans##func
-#else
-#define TRANS(func) _IceTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_IceTrans";
+static const char *__xtransname = "_IceTrans";
#endif
#endif /* ICE_t */
-#ifdef TEST_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
-#define TRANS(func) _TESTTrans##func
-#else
-#define TRANS(func) _TESTTrans/**/func
-#endif
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_TESTTrans";
-#endif
-#endif /* TEST_t */
-
-#ifdef LBXPROXY_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
-#define TRANS(func) _LBXPROXYTrans##func
-#else
-#define TRANS(func) _LBXPROXYTrans/**/func
-#endif
-#define X11_t /* The server defines this - so should the LBX proxy */
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_LBXPROXYTrans";
-#endif
-#endif /* LBXPROXY_t */
-
#if !defined(TRANS)
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _XTrans##func
-#else
-#define TRANS(func) _XTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_XTrans";
+static const char *__xtransname = "_XTrans";
#endif
#endif /* !TRANS */
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
/*
* Create a single address structure that can be used wherever
@@ -190,7 +148,7 @@ typedef long BytesReadable_t;
#endif
-#if defined(WIN32) || (defined(USG) && !defined(umips) && !defined(MOTOROLA) && !defined(uniosu) && !defined(__sxg__))
+#if defined(WIN32) || defined(USG)
/*
* TRANS(Readv) and TRANS(Writev) use struct iovec, normally found
@@ -264,7 +222,7 @@ void TRANS(FreeConnInfo) (
#ifdef TRANS_CLIENT
XtransConnInfo TRANS(OpenCOTSClient)(
- char * /* address */
+ const char * /* address */
);
#endif /* TRANS_CLIENT */
@@ -272,7 +230,7 @@ XtransConnInfo TRANS(OpenCOTSClient)(
#ifdef TRANS_SERVER
XtransConnInfo TRANS(OpenCOTSServer)(
- char * /* address */
+ const char * /* address */
);
#endif /* TRANS_SERVER */
@@ -282,7 +240,7 @@ XtransConnInfo TRANS(OpenCOTSServer)(
XtransConnInfo TRANS(ReopenCOTSServer)(
int, /* trans_id */
int, /* fd */
- char * /* port */
+ const char * /* port */
);
int TRANS(GetReopenInfo)(
@@ -305,12 +263,24 @@ int TRANS(SetOption)(
int TRANS(CreateListener)(
XtransConnInfo, /* ciptr */
- char *, /* port */
+ const char *, /* port */
unsigned int /* flags */
);
+int TRANS(Received) (
+ const char* /* protocol*/
+);
+
int TRANS(NoListen) (
- char* /* protocol*/
+ const char* /* protocol*/
+);
+
+int TRANS(Listen) (
+ const char* /* protocol*/
+);
+
+int TRANS(IsListening) (
+ const char* /* protocol*/
);
int TRANS(ResetListener)(
@@ -328,7 +298,7 @@ XtransConnInfo TRANS(Accept)(
int TRANS(Connect)(
XtransConnInfo, /* ciptr */
- char * /* address */
+ const char * /* address */
);
#endif /* TRANS_CLIENT */
@@ -362,6 +332,10 @@ int TRANS(Writev)(
int /* size */
);
+int TRANS(SendFd) (XtransConnInfo ciptr, int fd, int do_close);
+
+int TRANS(RecvFd) (XtransConnInfo ciptr);
+
int TRANS(Disconnect)(
XtransConnInfo /* ciptr */
);
@@ -378,12 +352,15 @@ int TRANS(IsLocal)(
XtransConnInfo /* ciptr */
);
+#ifdef NX_TRANS_SOCKET
+/* needed for pre-xcb libX11 as we have in NX */
int TRANS(GetMyAddr)(
- XtransConnInfo, /* ciptr */
- int *, /* familyp */
- int *, /* addrlenp */
- Xtransaddr ** /* addrp */
+ XtransConnInfo, /* ciptr */
+ int *, /* familyp */
+ int *, /* addrlenp */
+ Xtransaddr ** /* addrp */
);
+#endif
int TRANS(GetPeerAddr)(
XtransConnInfo, /* ciptr */
@@ -399,7 +376,7 @@ int TRANS(GetConnectionNumber)(
#ifdef TRANS_SERVER
int TRANS(MakeAllCOTSServerListeners)(
- char *, /* port */
+ const char *, /* port */
int *, /* partial */
int *, /* count_ret */
XtransConnInfo ** /* ciptrs_ret */
diff --git a/nx-X11/lib/xtrans/Xtransint.h b/nx-X11/lib/xtrans/Xtransint.h
index 2a138484b..2156bd52f 100644
--- a/nx-X11/lib/xtrans/Xtransint.h
+++ b/nx-X11/lib/xtrans/Xtransint.h
@@ -68,7 +68,7 @@ from The Open Group.
* message.
*/
-#ifndef XTRANSDEBUG
+#if !defined(XTRANSDEBUG) && defined(XTRANS_TRANSPORT_C)
# define XTRANSDEBUG 1
#endif
@@ -78,6 +78,10 @@ from The Open Group.
#include "Xtrans.h"
+#ifndef _X_UNUSED /* Defined in Xfuncproto.h in xproto >= 7.0.22 */
+# define _X_UNUSED /* */
+#endif
+
#ifdef XTRANSDEBUG
# include <stdio.h>
#endif /* XTRANSDEBUG */
@@ -94,7 +98,7 @@ from The Open Group.
* to avoid a race condition. JKJ (6/5/97)
*/
-# if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SCO__)
+# if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__)
# ifndef NEED_UTSNAME
# define NEED_UTSNAME
# endif
@@ -119,6 +123,16 @@ from The Open Group.
#define X_TCP_PORT 6000
#endif
+#if XTRANS_SEND_FDS
+
+struct _XtransConnFd {
+ struct _XtransConnFd *next;
+ int fd;
+ int do_close;
+};
+
+#endif
+
struct _XtransConnInfo {
struct _Xtransport *transptr;
int index;
@@ -131,33 +145,35 @@ struct _XtransConnInfo {
int addrlen;
char *peeraddr;
int peeraddrlen;
+ struct _XtransConnFd *recv_fds;
+ struct _XtransConnFd *send_fds;
};
#define XTRANS_OPEN_COTS_CLIENT 1
#define XTRANS_OPEN_COTS_SERVER 2
typedef struct _Xtransport {
- char *TransName;
+ const char *TransName;
int flags;
#ifdef TRANS_CLIENT
XtransConnInfo (*OpenCOTSClient)(
struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
+ const char *, /* protocol */
+ const char *, /* host */
+ const char * /* port */
);
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
- char ** nolisten;
+ const char ** nolisten;
XtransConnInfo (*OpenCOTSServer)(
struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
+ const char *, /* protocol */
+ const char *, /* host */
+ const char * /* port */
);
#endif /* TRANS_SERVER */
@@ -167,7 +183,7 @@ typedef struct _Xtransport {
XtransConnInfo (*ReopenCOTSServer)(
struct _Xtransport *, /* transport */
int, /* fd */
- char * /* port */
+ const char * /* port */
);
#endif /* TRANS_REOPEN */
@@ -185,7 +201,7 @@ typedef struct _Xtransport {
int (*CreateListener)(
XtransConnInfo, /* connection */
- char *, /* port */
+ const char *, /* port */
unsigned int /* flags */
);
@@ -204,8 +220,8 @@ typedef struct _Xtransport {
int (*Connect)(
XtransConnInfo, /* connection */
- char *, /* host */
- char * /* port */
+ const char *, /* host */
+ const char * /* port */
);
#endif /* TRANS_CLIENT */
@@ -239,6 +255,18 @@ typedef struct _Xtransport {
int /* size */
);
+#if XTRANS_SEND_FDS
+ int (*SendFd)(
+ XtransConnInfo, /* connection */
+ int, /* fd */
+ int /* do_close */
+ );
+
+ int (*RecvFd)(
+ XtransConnInfo /* connection */
+ );
+#endif
+
int (*Disconnect)(
XtransConnInfo /* connection */
);
@@ -268,8 +296,10 @@ typedef struct _Xtransport_table {
#define TRANS_LOCAL (1<<1) /* local transport */
#define TRANS_DISABLED (1<<2) /* Don't open this one */
#define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */
-#define TRANS_NOUNLINK (1<<4) /* Dont unlink transport endpoints */
+#define TRANS_NOUNLINK (1<<4) /* Don't unlink transport endpoints */
#define TRANS_ABSTRACT (1<<5) /* Use abstract sockets if available */
+#define TRANS_NOXAUTH (1<<6) /* Don't verify authentication (because it's secure some other way at the OS layer) */
+#define TRANS_RECEIVED (1<<7) /* The fd for this has already been opened by someone else. */
/* Flags to preserve when setting others */
#define TRANS_KEEPFLAGS (TRANS_NOUNLINK|TRANS_ABSTRACT)
@@ -277,12 +307,18 @@ typedef struct _Xtransport_table {
#ifdef XTRANS_TRANSPORT_C /* only provide static function prototypes when
building the transport.c file that has them in */
+#ifdef __clang__
+/* Not all clients make use of all provided statics */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
/*
* readv() and writev() don't exist or don't work correctly on some
* systems, so they may be emulated.
*/
-#if (defined(SYSV) && defined(__i386__) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__)
+#ifdef WIN32
#define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt)
@@ -296,10 +332,10 @@ static int TRANS(ReadV)(
#define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt)
-#endif /* (SYSV && __i386__) || WIN32 || __sxg__ || */
+#endif /* WIN32 */
-#if (defined(SYSV) && defined(__i386__) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__)
+#ifdef WIN32
#define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt)
@@ -313,20 +349,24 @@ static int TRANS(WriteV)(
#define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt)
-#endif /* WIN32 || __sxg__ */
+#endif /* WIN32 */
static int is_numeric (
- char * /* str */
+ const char * /* str */
);
#ifdef TRANS_SERVER
static int trans_mkdir (
- char *, /* path */
+ const char *, /* path */
int /* mode */
);
#endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
/*
* Some XTRANSDEBUG stuff
*/
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 */
diff --git a/nx-X11/lib/xtrans/Xtranssock.c b/nx-X11/lib/xtrans/Xtranssock.c
index ccfa0e13b..95db315f3 100644
--- a/nx-X11/lib/xtrans/Xtranssock.c
+++ b/nx-X11/lib/xtrans/Xtranssock.c
@@ -132,12 +132,9 @@ from the copyright holders.
#include <sys/stat.h>
#endif
-#if defined(MOTOROLA) && defined(SYSV)
-#define NO_TCP_H
-#endif
#ifndef NO_TCP_H
-#if defined(__osf__) || defined(linux) || defined(__GLIBC__) || defined(AIXV5)
+#if defined(linux) || defined(__GLIBC__)
#include <sys/param.h>
#endif /* osf */
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
@@ -148,18 +145,10 @@ from the copyright holders.
#endif /* !NO_TCP_H */
#include <sys/ioctl.h>
-#if defined(SVR4) && !defined(DGUX) && !defined(_SEQUENT_)
+#if defined(SVR4) || defined(__SVR4)
#include <sys/filio.h>
#endif
-#if (defined(__i386__) && defined(SYSV)) && !defined(SCO325) && !defined(sun)
-#include <net/errno.h>
-#endif
-
-#if (defined(__i386__) && defined(SYSV)) && (!defined(ISC) || !defined(I_NREAD) || defined(SCO325)) || defined(_SEQUENT_)
-#include <sys/stropts.h>
-#endif
-
#include <unistd.h>
#else /* !WIN32 */
@@ -189,7 +178,7 @@ from the copyright holders.
/* others don't need this */
#define SocketInitOnce() /**/
-#if defined(linux)
+#ifdef linux
#define HAVE_ABSTRACT_SOCKETS
#endif
@@ -212,7 +201,7 @@ from the copyright holders.
*/
typedef struct _Sockettrans2dev {
- char *transname;
+ const char *transname;
int family;
int devcotsname;
int devcltsname;
@@ -263,14 +252,6 @@ static int TRANS(SocketINETClose) (XtransConnInfo ciptr);
#define UNIX_PATH "/tmp/.ICE-unix/"
#define UNIX_DIR "/tmp/.ICE-unix"
#endif /* ICE_t */
-#if defined(TEST_t)
-#define UNIX_PATH "/tmp/.Test-unix/test"
-#define UNIX_DIR "/tmp/.Test-unix"
-#endif
-#if defined(LBXPROXY_t)
-#define UNIX_PATH "/tmp/.X11-unix/X"
-#define UNIX_DIR "/tmp/.X11-unix"
-#endif
#endif /* UNIXCONN */
@@ -281,17 +262,12 @@ static int TRANS(SocketINETClose) (XtransConnInfo ciptr);
#define MAXHOSTNAMELEN 255
#endif
-/*
- * This provides compatibility for apps linked against system libraries
- * that don't have IPv6 support.
- */
-#if defined(IPv6) && defined(AF_INET6)
-static const struct in6_addr local_in6addr_any = IN6ADDR_ANY_INIT;
-#pragma weak in6addr_any = local_in6addr_any
-#ifndef __USLC__
-#pragma weak getaddrinfo
-#endif
-static int haveIPv6 = 1;
+#if defined HAVE_SOCKLEN_T || (defined(IPv6) && defined(AF_INET6))
+# define SOCKLEN_T socklen_t
+#elif defined(SVR4) || defined(__SVR4) || defined(__SCO__)
+# define SOCKLEN_T size_t
+#else
+# define SOCKLEN_T int
#endif
#ifndef X11_t
@@ -307,6 +283,10 @@ static int haveIPv6 = 1;
#ifdef NX_TRANS_SOCKET
+#ifdef XTRANS_SEND_FDS
+ #error XTRANS_SEND_FDS is unsupported for NX!
+#endif
+
#ifdef TRANS_CLIENT
#include <nx/NX.h>
@@ -686,7 +666,7 @@ int TRANS(SocketCongestionChange) (XtransConnInfo ciptr, int *state)
*/
static int
-TRANS(SocketSelectFamily) (int first, char *family)
+TRANS(SocketSelectFamily) (int first, const char *family)
{
int i;
@@ -714,34 +694,26 @@ TRANS(SocketINETGetAddr) (XtransConnInfo ciptr)
{
#if defined(IPv6) && defined(AF_INET6)
struct sockaddr_storage socknamev6;
-#endif
- struct sockaddr_in socknamev4;
- void *socknamePtr;
-#if defined(SVR4) || defined(__SCO__)
-# define SOCKLEN_T_PTR void*
- size_t namelen;
#else
-# define SOCKLEN_T_PTR socklen_t*
- socklen_t namelen;
+ struct sockaddr_in socknamev4;
#endif
+ void *socknamePtr;
+ SOCKLEN_T namelen;
prmsg (3,"SocketINETGetAddr(%p)\n", ciptr);
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6)
- {
namelen = sizeof(socknamev6);
socknamePtr = &socknamev6;
- }
- else
-#endif
- {
+#else
namelen = sizeof(socknamev4);
socknamePtr = &socknamev4;
- }
+#endif
+
+ bzero(socknamePtr, namelen);
if (getsockname (ciptr->fd,(struct sockaddr *) socknamePtr,
- (SOCKLEN_T_PTR)&namelen) < 0)
+ (void *)&namelen) < 0)
{
#ifdef WIN32
errno = WSAGetLastError();
@@ -755,7 +727,7 @@ TRANS(SocketINETGetAddr) (XtransConnInfo ciptr)
* Everything looks good: fill in the XtransConnInfo structure.
*/
- if ((ciptr->addr = (char *) malloc (namelen)) == NULL)
+ if ((ciptr->addr = malloc (namelen)) == NULL)
{
prmsg (1,
"SocketINETGetAddr: Can't allocate space for the addr\n");
@@ -763,15 +735,10 @@ TRANS(SocketINETGetAddr) (XtransConnInfo ciptr)
}
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6)
- {
ciptr->family = ((struct sockaddr *)socknamePtr)->sa_family;
- }
- else
-#endif
- {
+#else
ciptr->family = socknamev4.sin_family;
- }
+#endif
ciptr->addrlen = namelen;
memcpy (ciptr->addr, socknamePtr, ciptr->addrlen);
@@ -793,14 +760,10 @@ TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr)
#endif
struct sockaddr_in socknamev4;
void *socknamePtr;
-#if defined(SVR4) || defined(__SCO__)
- size_t namelen;
-#else
- int namelen;
-#endif
+ SOCKLEN_T namelen;
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6 && ciptr->family == AF_INET6)
+ if (ciptr->family == AF_INET6)
{
namelen = sizeof(socknamev6);
socknamePtr = &socknamev6;
@@ -812,6 +775,8 @@ TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr)
socknamePtr = &socknamev4;
}
+ bzero(socknamePtr, namelen);
+
prmsg (3,"SocketINETGetPeerAddr(%p)\n", ciptr);
if (getpeername (ciptr->fd, (struct sockaddr *) socknamePtr,
@@ -829,7 +794,7 @@ TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr)
* Everything looks good: fill in the XtransConnInfo structure.
*/
- if ((ciptr->peeraddr = (char *) malloc (namelen)) == NULL)
+ if ((ciptr->peeraddr = malloc (namelen)) == NULL)
{
prmsg (1,
"SocketINETGetPeerAddr: Can't allocate space for the addr\n");
@@ -851,16 +816,7 @@ TRANS(SocketOpen) (int i, int type)
prmsg (3,"SocketOpen(%d,%d)\n", i, type);
-#if defined(IPv6) && defined(AF_INET6)
- if (getaddrinfo == NULL)
- haveIPv6 = 0;
-
- if (!haveIPv6 && Sockettrans2devtab[i].family == AF_INET6)
- return NULL;
-#endif
-
- if ((ciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((ciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
prmsg (1, "SocketOpen: malloc failed\n");
return NULL;
@@ -880,7 +836,7 @@ TRANS(SocketOpen) (int i, int type)
prmsg (2, "SocketOpen: socket() failed for %s\n",
Sockettrans2devtab[i].transname);
- free ((char *) ciptr);
+ free (ciptr);
return NULL;
}
@@ -901,6 +857,27 @@ TRANS(SocketOpen) (int i, int type)
}
#endif
+ /*
+ * Some systems provide a really small default buffer size for
+ * UNIX sockets. Bump it up a bit such that large transfers don't
+ * proceed at glacial speed.
+ */
+#ifdef SO_SNDBUF
+ if (Sockettrans2devtab[i].family == AF_UNIX)
+ {
+ SOCKLEN_T len = sizeof (int);
+ int val;
+
+ if (getsockopt (ciptr->fd, SOL_SOCKET, SO_SNDBUF,
+ (char *) &val, &len) == 0 && val < 64 * 1024)
+ {
+ val = 64 * 1024;
+ setsockopt (ciptr->fd, SOL_SOCKET, SO_SNDBUF,
+ (char *) &val, sizeof (int));
+ }
+ }
+#endif
+
return ciptr;
}
@@ -908,22 +885,82 @@ TRANS(SocketOpen) (int i, int type)
#ifdef TRANS_REOPEN
static XtransConnInfo
-TRANS(SocketReopen) (int i, int type, int fd, char *port)
+TRANS(SocketReopen) (int i _X_UNUSED, int type, int fd, const char *port)
{
XtransConnInfo ciptr;
+ int portlen;
+ struct sockaddr *addr;
+ size_t addrlen;
prmsg (3,"SocketReopen(%d,%d,%s)\n", type, fd, port);
- if ((ciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if (port == NULL) {
+ prmsg (1, "SocketReopen: port was null!\n");
+ return NULL;
+ }
+
+ portlen = strlen(port) + 1; // include space for trailing null
+#ifdef SOCK_MAXADDRLEN
+ if (portlen < 0 || portlen > (SOCK_MAXADDRLEN + 2)) {
+ prmsg (1, "SocketReopen: invalid portlen %d\n", portlen);
+ return NULL;
+ }
+ if (portlen < 14) portlen = 14;
+#else
+ if (portlen < 0 || portlen > 14) {
+ prmsg (1, "SocketReopen: invalid portlen %d\n", portlen);
+ return NULL;
+ }
+#endif /*SOCK_MAXADDRLEN*/
+
+ if ((ciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
- prmsg (1, "SocketReopen: malloc failed\n");
+ prmsg (1, "SocketReopen: malloc(ciptr) failed\n");
return NULL;
}
ciptr->fd = fd;
+ addrlen = portlen + offsetof(struct sockaddr, sa_data);
+ if ((addr = calloc (1, addrlen)) == NULL) {
+ prmsg (1, "SocketReopen: malloc(addr) failed\n");
+ free (ciptr);
+ return NULL;
+ }
+ ciptr->addr = (char *) addr;
+ ciptr->addrlen = addrlen;
+
+ if ((ciptr->peeraddr = calloc (1, addrlen)) == NULL) {
+ prmsg (1, "SocketReopen: malloc(portaddr) failed\n");
+ free (addr);
+ free (ciptr);
+ return NULL;
+ }
+ ciptr->peeraddrlen = addrlen;
+
+ /* Initialize ciptr structure as if it were a normally-opened unix socket */
+ ciptr->flags = TRANS_LOCAL | TRANS_NOUNLINK;
+#ifdef BSD44SOCKETS
+ addr->sa_len = addrlen;
+#endif
+ addr->sa_family = AF_UNIX;
+#if defined(HAVE_STRLCPY) || defined(HAS_STRLCPY)
+ strlcpy(addr->sa_data, port, portlen);
+#else
+ strncpy(addr->sa_data, port, portlen);
+#endif
+ ciptr->family = AF_UNIX;
+ memcpy(ciptr->peeraddr, ciptr->addr, addrlen);
+ ciptr->port = rindex(addr->sa_data, ':');
+ if (ciptr->port == NULL) {
+ if (is_numeric(addr->sa_data)) {
+ ciptr->port = addr->sa_data;
+ }
+ } else if (ciptr->port[0] == ':') {
+ ciptr->port++;
+ }
+ /* port should now point to portnum or NULL */
return ciptr;
}
@@ -937,8 +974,8 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
#ifdef TRANS_CLIENT
static XtransConnInfo
-TRANS(SocketOpenCOTSClientBase) (char *transname, char *protocol,
- char *host, char *port, int previndex)
+TRANS(SocketOpenCOTSClientBase) (const char *transname, const char *protocol,
+ const char *host, const char *port, int previndex)
{
XtransConnInfo ciptr;
int i = previndex;
@@ -973,7 +1010,10 @@ TRANS(SocketOpenCOTSClientBase) (char *transname, char *protocol,
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
if ((ciptr = TRANS(SocketOpen) (
- i, Sockettrans2devtab[i].devcotsname)) != NULL)
+ i, Sockettrans2devtab[i].devcotsname)) != NULL) {
+ /* Save the index for later use */
+
+ ciptr->index = i;
break;
}
}
@@ -993,16 +1033,12 @@ TRANS(SocketOpenCOTSClientBase) (char *transname, char *protocol,
#endif
- /* Save the index for later use */
-
- ciptr->index = i;
-
return ciptr;
}
static XtransConnInfo
-TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
+TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, const char *protocol,
+ const char *host, const char *port)
{
return TRANS(SocketOpenCOTSClientBase)(
thistrans->TransName, protocol, host, port, -1);
@@ -1015,8 +1051,8 @@ TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, char *protocol,
#ifdef TRANS_SERVER
static XtransConnInfo
-TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
+TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, const char *protocol,
+ const char *host, const char *port)
{
XtransConnInfo ciptr;
@@ -1082,7 +1118,7 @@ TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol,
#ifdef TRANS_REOPEN
static XtransConnInfo
-TRANS(SocketReopenCOTSServer) (Xtransport *thistrans, int fd, char *port)
+TRANS(SocketReopenCOTSServer) (Xtransport *thistrans, int fd, const char *port)
{
XtransConnInfo ciptr;
@@ -1168,7 +1204,7 @@ TRANS(SocketCreateListener) (XtransConnInfo ciptr,
int socknamelen, unsigned int flags)
{
- int namelen = socknamelen;
+ SOCKLEN_T namelen = socknamelen;
int fd = ciptr->fd;
int retry;
@@ -1248,7 +1284,8 @@ TRANS(SocketCreateListener) (XtransConnInfo ciptr,
#ifdef TCPCONN
static int
-TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int flags)
+TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, const char *port,
+ unsigned int flags)
{
#if defined(IPv6) && defined(AF_INET6)
@@ -1257,7 +1294,7 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
struct sockaddr_in sockname;
#endif
unsigned short sport;
- int namelen = sizeof(sockname);
+ SOCKLEN_T namelen = sizeof(sockname);
int status;
long tmpport;
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
@@ -1285,7 +1322,7 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
{
/* fixup the server port address */
tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
- sprintf (portbuf,"%lu", tmpport);
+ snprintf (portbuf, sizeof(portbuf), "%lu", tmpport);
port = portbuf;
}
#endif
@@ -1370,13 +1407,13 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
return 0;
}
-#endif /* SOCKCONN */
+#endif /* TCPCONN */
#ifdef UNIXCONN
static int
-TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
+TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, const char *port,
unsigned int flags)
{
@@ -1426,28 +1463,23 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
snprintf (tmpport, sizeof(tmpport), "%s%ld", UNIX_PATH, (long)getpid());
port = tmpport;
}
- if (port && *port) {
#ifdef NX_TRANS_SOCKET
- if (set_sun_path(port, _NXGetUnixPath(UNIX_PATH), sockname.sun_path, abstract) != 0) {
+ if (set_sun_path(port, _NXGetUnixPath(UNIX_PATH), sockname.sun_path, abstract) != 0) {
#else
if (set_sun_path(port, UNIX_PATH, sockname.sun_path, abstract) != 0) {
#endif
prmsg (1, "SocketUNIXCreateListener: path too long\n");
return TRANS_CREATE_LISTENER_FAILED;
}
- } else {
-#ifdef NX_TRANS_SOCKET
- sprintf (sockname.sun_path, "%s%ld", _NXGetUnixPath(UNIX_PATH), (long)getpid());
-#else
- sprintf (sockname.sun_path, "%s%ld", UNIX_PATH, (long)getpid());
-#endif
- }
#if (defined(BSD44SOCKETS) || defined(__UNIXWARE__))
sockname.sun_len = strlen(sockname.sun_path);
+#endif
+
+#if defined(BSD44SOCKETS) || defined(SUN_LEN)
namelen = SUN_LEN(&sockname);
#else
- namelen = strlen(sockname.sun_path) + sizeof(sockname.sun_family);
+ namelen = strlen(sockname.sun_path) + offsetof(struct sockaddr_un, sun_path);
#endif
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
@@ -1479,7 +1511,7 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
namelen = sizeof (sockname); /* this will always make it the same size */
- if ((ciptr->addr = (char *) malloc (namelen)) == NULL)
+ if ((ciptr->addr = malloc (namelen)) == NULL)
{
prmsg (1,
"SocketUNIXCreateListener: Can't allocate space for the addr\n");
@@ -1522,11 +1554,12 @@ TRANS(SocketUNIXResetListener) (XtransConnInfo ciptr)
if (!abstract && (
stat (unsock->sun_path, &statb) == -1 ||
((statb.st_mode & S_IFMT) !=
-#if (defined (sun) && defined(SVR4)) || defined(NCR) || defined(SCO325) || !defined(S_IFSOCK)
- S_IFIFO))
+#if defined(NCR) || defined(SCO325) || !defined(S_IFSOCK)
+ S_IFIFO
#else
- S_IFSOCK)))
+ S_IFSOCK
#endif
+ )))
{
int oldUmask = umask (0);
@@ -1594,12 +1627,11 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
{
XtransConnInfo newciptr;
struct sockaddr_in sockname;
- int namelen = sizeof(sockname);
+ SOCKLEN_T namelen = sizeof(sockname);
prmsg (2, "SocketINETAccept(%p,%d)\n", ciptr, ciptr->fd);
- if ((newciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
prmsg (1, "SocketINETAccept: malloc failed\n");
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -1671,16 +1703,11 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
{
XtransConnInfo newciptr;
struct sockaddr_un sockname;
-#if defined(SVR4) || defined(__SCO__)
- size_t namelen = sizeof sockname;
-#else
- int namelen = sizeof sockname;
-#endif
+ SOCKLEN_T namelen = sizeof sockname;
prmsg (2, "SocketUNIXAccept(%p,%d)\n", ciptr, ciptr->fd);
- if ((newciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
prmsg (1, "SocketUNIXAccept: malloc() failed\n");
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -1696,12 +1723,13 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
return NULL;
}
+ ciptr->addrlen = namelen;
/*
* Get the socket name and the peer name from the listener socket,
* since this is unix domain.
*/
- if ((newciptr->addr = (char *) malloc (ciptr->addrlen)) == NULL)
+ if ((newciptr->addr = malloc (ciptr->addrlen)) == NULL)
{
prmsg (1,
"SocketUNIXAccept: Can't allocate space for the addr\n");
@@ -1719,7 +1747,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
newciptr->addrlen = ciptr->addrlen;
memcpy (newciptr->addr, ciptr->addr, newciptr->addrlen);
- if ((newciptr->peeraddr = (char *) malloc (ciptr->addrlen)) == NULL)
+ if ((newciptr->peeraddr = malloc (ciptr->addrlen)) == NULL)
{
prmsg (1,
"SocketUNIXAccept: Can't allocate space for the addr\n");
@@ -1761,7 +1789,8 @@ static struct addrlist *addrlist = NULL;
static int
-TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
+TRANS(SocketINETConnect) (XtransConnInfo ciptr,
+ const char *host, const char *port)
{
struct sockaddr * socketaddr = NULL;
@@ -1771,20 +1800,20 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
struct addrinfo hints;
char ntopbuf[INET6_ADDRSTRLEN];
int resetonce = 0;
-#endif
+#else
struct sockaddr_in sockname;
+ struct hostent *hostp;
+ struct servent *servp;
+ unsigned long tmpaddr;
+#endif
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
_Xgethostbynameparams hparams;
_Xgetservbynameparams sparams;
#endif
- struct hostent *hostp;
- struct servent *servp;
- unsigned long tmpaddr;
#ifdef X11_t
char portbuf[PORTBUFSIZE];
#endif
- long tmpport;
char hostnamebuf[256]; /* tmp space */
prmsg (2,"SocketINETConnect(%d,%s,%s)\n", ciptr->fd, host, port);
@@ -1808,14 +1837,14 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
if (is_numeric (port))
{
- tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
- sprintf (portbuf, "%lu", tmpport);
+ long tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
+ snprintf (portbuf, sizeof(portbuf), "%lu", tmpport);
port = portbuf;
}
#endif
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6) {
+ {
if (addrlist != NULL) {
if (strcmp(host,addrlist->host) || strcmp(port,addrlist->port)) {
if (addrlist->firstaddr)
@@ -1954,8 +1983,8 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
addrlist->addr = addrlist->addr->ai_next;
}
}
- } else
-#endif
+ }
+#else
{
/*
* Build the socket name.
@@ -2018,7 +2047,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
}
sockname.sin_port = htons (servp->s_port);
} else {
- tmpport = strtol (port, (char**)NULL, 10);
+ long tmpport = strtol (port, (char**)NULL, 10);
if (tmpport < 1024 || tmpport > USHRT_MAX)
return TRANS_CONNECT_FAILED;
sockname.sin_port = htons (((unsigned short) tmpport));
@@ -2029,6 +2058,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
socketaddr = (struct sockaddr *) &sockname;
socketaddrlen = sizeof(sockname);
}
+#endif
/*
* Turn on socket keepalive so the client process will eventually
@@ -2079,7 +2109,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
if (olderrno == ECONNREFUSED || olderrno == EINTR
#if defined(IPv6) && defined(AF_INET6)
- || (haveIPv6 && ((addrlist->addr->ai_next != NULL) ||
+ || (((addrlist->addr->ai_next != NULL) ||
(addrlist->addr != addrlist->firstaddr)) &&
(olderrno == ENETUNREACH || olderrno == EAFNOSUPPORT ||
olderrno == EADDRNOTAVAIL || olderrno == ETIMEDOUT
@@ -2123,7 +2153,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
}
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6 && res != 0) {
+ if (res != 0) {
addrlist->addr = addrlist->addr->ai_next;
}
#endif
@@ -2142,25 +2172,18 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
*/
static int
-UnixHostReallyLocal (char *host)
+UnixHostReallyLocal (const char *host)
{
char hostnamebuf[256];
-#if defined(IPv6) && defined(AF_INET6)
- if (getaddrinfo == NULL)
- haveIPv6 = 0;
-#endif
-
TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf));
if (strcmp (hostnamebuf, host) == 0)
{
return (1);
- }
+ } else {
#if defined(IPv6) && defined(AF_INET6)
- else if (haveIPv6)
- {
struct addrinfo *localhostaddr;
struct addrinfo *otherhostaddr;
struct addrinfo *i, *j;
@@ -2206,10 +2229,7 @@ UnixHostReallyLocal (char *host)
freeaddrinfo(localhostaddr);
freeaddrinfo(otherhostaddr);
return equiv;
- }
-#endif
- else
- {
+#else
/*
* A host may have more than one network address. If any of the
* network addresses of 'host' (specified to the connect call)
@@ -2278,15 +2298,17 @@ UnixHostReallyLocal (char *host)
i++;
}
return (equiv);
+#endif
}
}
static int
-TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
+TRANS(SocketUNIXConnect) (XtransConnInfo ciptr,
+ const char *host, const char *port)
{
struct sockaddr_un sockname;
- int namelen;
+ SOCKLEN_T namelen;
int abstract = 0;
@@ -2305,10 +2327,10 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
*/
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
- if (strcmp(host, "unix") != 0 && strcasecmp(host, "nx") != 0 &&
+ if (host && *host && host[0]!='/' && strcmp(host, "unix") != 0 && strcasecmp(host, "nx") != 0 &&
strncasecmp(host, "nx,", 3) != 0 && !UnixHostReallyLocal (host))
#else
- if (strcmp (host, "unix") != 0 && !UnixHostReallyLocal (host))
+ if (host && *host && host[0]!='/' && strcmp (host, "unix") != 0 && !UnixHostReallyLocal (host))
#endif
{
prmsg (1,
@@ -2345,9 +2367,12 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
#if (defined(BSD44SOCKETS) || defined(__UNIXWARE__))
sockname.sun_len = strlen (sockname.sun_path);
+#endif
+
+#if defined(BSD44SOCKETS) || defined(SUN_LEN)
namelen = SUN_LEN (&sockname);
#else
- namelen = strlen (sockname.sun_path) + sizeof (sockname.sun_family);
+ namelen = strlen (sockname.sun_path) + offsetof(struct sockaddr_un, sun_path);
#endif
@@ -2371,8 +2396,9 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
* Done here because otherwise all the strlen() calls above would fail.
*/
- if (abstract)
+ if (abstract) {
sockname.sun_path[0] = '\0';
+ }
/*
* Do the connect()
@@ -2388,8 +2414,13 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
errno = olderrno;
/*
- * If the error was ENOENT, the server may be starting up
- * and we should try again.
+ * If the error was ENOENT, the server may be starting up; we used
+ * to suggest to try again in this case with
+ * TRANS_TRY_CONNECT_AGAIN, but this introduced problems for
+ * processes still referencing stale sockets in their environment.
+ * Hence, we now return a hard error, TRANS_CONNECT_FAILED, and it
+ * is suggested that higher level stacks handle retries on their
+ * level when they face a slow starting server.
*
* If the error was EWOULDBLOCK or EINPROGRESS then the socket
* was non-blocking and we should poll using select
@@ -2402,13 +2433,14 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
return TRANS_IN_PROGRESS;
else if (olderrno == EINTR)
return TRANS_TRY_CONNECT_AGAIN;
- else if (olderrno == ENOENT || olderrno == ECONNREFUSED)
- /* If opening as abstract failed, try again normally */
+ else if (olderrno == ENOENT || olderrno == ECONNREFUSED) {
+ /* If opening as abstract socket failed, try again normally */
if (abstract) {
ciptr->transptr->flags &= ~(TRANS_ABSTRACT);
return TRANS_TRY_CONNECT_AGAIN;
} else {
return TRANS_CONNECT_FAILED;
+ }
} else {
prmsg (2,"SocketUNIXConnect: Can't connect: errno = %d\n",
EGET());
@@ -2429,8 +2461,8 @@ SocketUNIXConnectPost:
* since this is unix domain.
*/
- if ((ciptr->addr = (char *) malloc(namelen)) == NULL ||
- (ciptr->peeraddr = (char *) malloc(namelen)) == NULL)
+ if ((ciptr->addr = malloc(namelen)) == NULL ||
+ (ciptr->peeraddr = malloc(namelen)) == NULL)
{
prmsg (1,
"SocketUNIXCreateListener: Can't allocate space for the addr\n");
@@ -2512,24 +2544,123 @@ TRANS(SocketBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend)
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
-#if defined(QNX4)
- *pend = 0L; /* FIONREAD only returns a short. Zero out upper bits */
-#endif
#ifdef WIN32
{
int ret = ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend);
- errno = WSAGetLastError();
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
return ret;
}
#else
-#if (defined(__i386__) && defined(SYSV) && !defined(SCO325)) || (defined(_SEQUENT_) && _SOCKET_VERSION == 1)
- return ioctl (ciptr->fd, I_NREAD, (char *) pend);
-#else
return ioctl (ciptr->fd, FIONREAD, (char *) pend);
-#endif /* __i386__ && SYSV || _SEQUENT_ && _SOCKET_VERSION == 1 */
#endif /* WIN32 */
}
+#if XTRANS_SEND_FDS
+
+static void
+appendFd(struct _XtransConnFd **prev, int fd, int do_close)
+{
+ struct _XtransConnFd *cf, *new;
+
+ new = malloc (sizeof (struct _XtransConnFd));
+ if (!new) {
+ /* XXX mark connection as broken */
+ close(fd);
+ return;
+ }
+ new->next = 0;
+ new->fd = fd;
+ new->do_close = do_close;
+ /* search to end of list */
+ for (; (cf = *prev); prev = &(cf->next));
+ *prev = new;
+}
+
+static int
+removeFd(struct _XtransConnFd **prev)
+{
+ struct _XtransConnFd *cf;
+ int fd;
+
+ if ((cf = *prev)) {
+ *prev = cf->next;
+ fd = cf->fd;
+ free(cf);
+ } else
+ fd = -1;
+ return fd;
+}
+
+static void
+discardFd(struct _XtransConnFd **prev, struct _XtransConnFd *upto, int do_close)
+{
+ struct _XtransConnFd *cf, *next;
+
+ for (cf = *prev; cf != upto; cf = next) {
+ next = cf->next;
+ if (do_close || cf->do_close)
+ close(cf->fd);
+ free(cf);
+ }
+ *prev = upto;
+}
+
+static void
+cleanupFds(XtransConnInfo ciptr)
+{
+ /* Clean up the send list but don't close the fds */
+ discardFd(&ciptr->send_fds, NULL, 0);
+ /* Clean up the recv list and *do* close the fds */
+ discardFd(&ciptr->recv_fds, NULL, 1);
+}
+
+static int
+nFd(struct _XtransConnFd **prev)
+{
+ struct _XtransConnFd *cf;
+ int n = 0;
+
+ for (cf = *prev; cf; cf = cf->next)
+ n++;
+ return n;
+}
+
+static int
+TRANS(SocketRecvFd) (XtransConnInfo ciptr)
+{
+ prmsg (2, "SocketRecvFd(%d)\n", ciptr->fd);
+ return removeFd(&ciptr->recv_fds);
+}
+
+static int
+TRANS(SocketSendFd) (XtransConnInfo ciptr, int fd, int do_close)
+{
+ appendFd(&ciptr->send_fds, fd, do_close);
+ return 0;
+}
+
+static int
+TRANS(SocketRecvFdInvalid)(XtransConnInfo ciptr)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+static int
+TRANS(SocketSendFdInvalid)(XtransConnInfo ciptr, int fd, int do_close)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+#define MAX_FDS 128
+
+union fd_pass {
+ struct cmsghdr cmsghdr;
+ char buf[CMSG_SPACE(MAX_FDS * sizeof(int))];
+};
+
+#endif /* XTRANS_SEND_FDS */
static int
TRANS(SocketRead) (XtransConnInfo ciptr, char *buf, int size)
@@ -2567,7 +2698,41 @@ TRANS(SocketRead) (XtransConnInfo ciptr, char *buf, int size)
}
else
{
+ /* FIXME: same code as below, should be possible without duplication */
+#if XTRANS_SEND_FDS
+ struct iovec iov = {
+ .iov_base = buf,
+ .iov_len = size
+ };
+ union fd_pass cmsgbuf;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(MAX_FDS * sizeof(int))
+ };
+
+ size = recvmsg(ciptr->fd, &msg, 0);
+ if (size >= 0) {
+ struct cmsghdr *hdr;
+
+ for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+ if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+ int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+ int i;
+ int *fd = (int *) CMSG_DATA(hdr);
+
+ for (i = 0; i < nfd; i++)
+ appendFd(&ciptr->recv_fds, fd[i], 0);
+ }
+ }
+ }
+ return size;
+#else
return read (ciptr->fd, buf, size);
+#endif /* XTRANS_SEND_FDS */
}
#else /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
@@ -2576,137 +2741,323 @@ TRANS(SocketRead) (XtransConnInfo ciptr, char *buf, int size)
{
int ret = recv ((SOCKET)ciptr->fd, buf, size, 0);
#ifdef WIN32
- errno = WSAGetLastError();
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
#endif
return ret;
}
#else
+#if XTRANS_SEND_FDS
+ {
+ struct iovec iov = {
+ .iov_base = buf,
+ .iov_len = size
+ };
+ union fd_pass cmsgbuf;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(MAX_FDS * sizeof(int))
+ };
+
+ size = recvmsg(ciptr->fd, &msg, 0);
+ if (size >= 0) {
+ struct cmsghdr *hdr;
+
+ for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+ if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+ int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+ int i;
+ int *fd = (int *) CMSG_DATA(hdr);
+
+ for (i = 0; i < nfd; i++)
+ appendFd(&ciptr->recv_fds, fd[i], 0);
+ }
+ }
+ }
+ return size;
+ }
+#else
return read (ciptr->fd, buf, size);
+#endif /* XTRANS_SEND_FDS */
#endif /* WIN32 */
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
}
-
static int
-TRANS(SocketWrite) (XtransConnInfo ciptr, char *buf, int size)
+TRANS(SocketReadv) (XtransConnInfo ciptr, struct iovec *buf, int size)
{
- prmsg (2,"SocketWrite(%d,%p,%d)\n", ciptr->fd, buf, size);
+ prmsg (2,"SocketReadv(%d,%p,%d)\n", ciptr->fd, buf, size);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
/*
* If we have a valid priv pointer then this
* is an internal connection to the proxy.
- * In this case we should emulate the write.
+ * In this case we should emulate the readv.
*/
if (ciptr->priv)
{
- int result;
-
- result = NXTransWrite(ciptr->fd, buf, size);
-
-#ifdef NX_TRANS_DEBUG
- if (result < 0 && EGET() == EAGAIN)
- {
- fprintf(stderr, "SocketWrite: Write on descriptor [%d] would block.\n",
- ciptr->fd);
- }
- else
- {
- fprintf(stderr, "SocketWrite: Written [%d] bytes on descriptor [%d].\n",
- result, ciptr->fd);
- }
-#endif
- return result;
+ return NXTransReadVector(ciptr->fd, buf, size);
}
else
{
- return write (ciptr->fd, buf, size);
+ /* FIXME: same code as below, should be possible without duplication */
+#if XTRANS_SEND_FDS
+ union fd_pass cmsgbuf;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = buf,
+ .msg_iovlen = size,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(MAX_FDS * sizeof(int))
+ };
+
+ size = recvmsg(ciptr->fd, &msg, 0);
+ if (size >= 0) {
+ struct cmsghdr *hdr;
+
+ for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+ if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+ int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+ int i;
+ int *fd = (int *) CMSG_DATA(hdr);
+
+ for (i = 0; i < nfd; i++)
+ appendFd(&ciptr->recv_fds, fd[i], 0);
+ }
+ }
+ }
+ return size;
+#else
+ return READV (ciptr, buf, size);
+#endif
}
#else /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
-#if defined(WIN32)
- {
- int ret = send ((SOCKET)ciptr->fd, buf, size, 0);
-#ifdef WIN32
- errno = WSAGetLastError();
-#endif
- return ret;
+#if XTRANS_SEND_FDS
+ {
+ union fd_pass cmsgbuf;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = buf,
+ .msg_iovlen = size,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(MAX_FDS * sizeof(int))
+ };
+
+ size = recvmsg(ciptr->fd, &msg, 0);
+ if (size >= 0) {
+ struct cmsghdr *hdr;
+
+ for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+ if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+ int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+ int i;
+ int *fd = (int *) CMSG_DATA(hdr);
+
+ for (i = 0; i < nfd; i++)
+ appendFd(&ciptr->recv_fds, fd[i], 0);
+ }
+ }
+ }
+ return size;
}
#else
- return write (ciptr->fd, buf, size);
-#endif /* WIN32 */
+ return READV (ciptr, buf, size);
+#endif
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
}
static int
-TRANS(SocketReadv) (XtransConnInfo ciptr, struct iovec *buf, int size)
+TRANS(SocketWritev) (XtransConnInfo ciptr, struct iovec *buf, int size)
{
- prmsg (2,"SocketReadv(%d,%p,%d)\n", ciptr->fd, buf, size);
+ prmsg (2,"SocketWritev(%d,%p,%d)\n", ciptr->fd, buf, size);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
/*
* If we have a valid priv pointer then this
* is an internal connection to the proxy.
- * In this case we should emulate the readv.
+ * In this case we should emulate the writev.
*/
if (ciptr->priv)
{
- return NXTransReadVector(ciptr->fd, buf, size);
+ return NXTransWriteVector(ciptr->fd, buf, size);
}
else
{
- return READV (ciptr, buf, size);
+ /* FIXME: same code as below, should be possible without duplication */
+#if XTRANS_SEND_FDS
+ if (ciptr->send_fds)
+ {
+ union fd_pass cmsgbuf;
+ int nfd = nFd(&ciptr->send_fds);
+ struct _XtransConnFd *cf = ciptr->send_fds;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = buf,
+ .msg_iovlen = size,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(nfd * sizeof(int))
+ };
+ struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg);
+ int i;
+ int *fds;
+
+ hdr->cmsg_len = msg.msg_controllen;
+ hdr->cmsg_level = SOL_SOCKET;
+ hdr->cmsg_type = SCM_RIGHTS;
+
+ fds = (int *) CMSG_DATA(hdr);
+ /* Set up fds */
+ for (i = 0; i < nfd; i++) {
+ fds[i] = cf->fd;
+ cf = cf->next;
+ }
+
+ i = sendmsg(ciptr->fd, &msg, 0);
+ if (i > 0)
+ discardFd(&ciptr->send_fds, cf, 0);
+ return i;
+ }
+#endif
+ return WRITEV (ciptr, buf, size);
}
#else /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
- return READV (ciptr, buf, size);
+#if XTRANS_SEND_FDS
+ if (ciptr->send_fds)
+ {
+ union fd_pass cmsgbuf;
+ int nfd = nFd(&ciptr->send_fds);
+ struct _XtransConnFd *cf = ciptr->send_fds;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = buf,
+ .msg_iovlen = size,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(nfd * sizeof(int))
+ };
+ struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg);
+ int i;
+ int *fds;
+
+ hdr->cmsg_len = msg.msg_controllen;
+ hdr->cmsg_level = SOL_SOCKET;
+ hdr->cmsg_type = SCM_RIGHTS;
+
+ fds = (int *) CMSG_DATA(hdr);
+ /* Set up fds */
+ for (i = 0; i < nfd; i++) {
+ fds[i] = cf->fd;
+ cf = cf->next;
+ }
+
+ i = sendmsg(ciptr->fd, &msg, 0);
+ if (i > 0)
+ discardFd(&ciptr->send_fds, cf, 0);
+ return i;
+ }
+#endif
+ return WRITEV (ciptr, buf, size);
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
}
static int
-TRANS(SocketWritev) (XtransConnInfo ciptr, struct iovec *buf, int size)
+TRANS(SocketWrite) (XtransConnInfo ciptr, char *buf, int size)
{
- prmsg (2,"SocketWritev(%d,%p,%d)\n", ciptr->fd, buf, size);
+ prmsg (2,"SocketWrite(%d,%p,%d)\n", ciptr->fd, buf, size);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
/*
* If we have a valid priv pointer then this
* is an internal connection to the proxy.
- * In this case we should emulate the writev.
+ * In this case we should emulate the write.
*/
if (ciptr->priv)
{
- return NXTransWriteVector(ciptr->fd, buf, size);
+ int result;
+
+ result = NXTransWrite(ciptr->fd, buf, size);
+
+#ifdef NX_TRANS_DEBUG
+ if (result < 0 && EGET() == EAGAIN)
+ {
+ fprintf(stderr, "SocketWrite: Write on descriptor [%d] would block.\n",
+ ciptr->fd);
+ }
+ else
+ {
+ fprintf(stderr, "SocketWrite: Written [%d] bytes on descriptor [%d].\n",
+ result, ciptr->fd);
+ }
+#endif
+ return result;
}
else
{
- return WRITEV (ciptr, buf, size);
+ /* FIXME: same code as below, should be possible without duplication */
+#if XTRANS_SEND_FDS
+ if (ciptr->send_fds)
+ {
+ struct iovec iov;
+
+ iov.iov_base = buf;
+ iov.iov_len = size;
+ return TRANS(SocketWritev)(ciptr, &iov, 1);
+ }
+#endif /* XTRANS_SEND_FDS */
+ return write (ciptr->fd, buf, size);
}
#else /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
- return WRITEV (ciptr, buf, size);
+#if defined(WIN32)
+ {
+ int ret = send ((SOCKET)ciptr->fd, buf, size, 0);
+#ifdef WIN32
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
+#endif
+ return ret;
+ }
+#else
+#if XTRANS_SEND_FDS
+ if (ciptr->send_fds)
+ {
+ struct iovec iov;
+
+ iov.iov_base = buf;
+ iov.iov_len = size;
+ return TRANS(SocketWritev)(ciptr, &iov, 1);
+ }
+#endif /* XTRANS_SEND_FDS */
+ return write (ciptr->fd, buf, size);
+#endif /* WIN32 */
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
}
-
static int
TRANS(SocketDisconnect) (XtransConnInfo ciptr)
@@ -2716,7 +3067,7 @@ TRANS(SocketDisconnect) (XtransConnInfo ciptr)
#ifdef WIN32
{
int ret = shutdown (ciptr->fd, 2);
- errno = WSAGetLastError();
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
return ret;
}
#else
@@ -2735,7 +3086,7 @@ TRANS(SocketINETClose) (XtransConnInfo ciptr)
#ifdef WIN32
{
int ret = close (ciptr->fd);
- errno = WSAGetLastError();
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
return ret;
}
#else
@@ -2769,6 +3120,9 @@ TRANS(SocketUNIXClose) (XtransConnInfo ciptr)
#endif
+#if XTRANS_SEND_FDS
+ cleanupFds(ciptr);
+#endif
ret = close(ciptr->fd);
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
@@ -2783,14 +3137,16 @@ TRANS(SocketUNIXClose) (XtransConnInfo ciptr)
&& sockname->sun_path[0])
{
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
- if (!(ciptr->flags & TRANS_NOUNLINK))
+ if (!(ciptr->flags & TRANS_NOUNLINK
+ || ciptr->transptr->flags & TRANS_ABSTRACT))
{
fprintf(stderr, "SocketUNIXClose: Unlinking path [%s] for ciptr at [%p].\n",
sockname->sun_path, (void *) ciptr);
unlink (sockname->sun_path);
}
#else
- if (!(ciptr->flags & TRANS_NOUNLINK))
+ if (!(ciptr->flags & TRANS_NOUNLINK
+ || ciptr->transptr->flags & TRANS_ABSTRACT))
unlink (sockname->sun_path);
#endif
}
@@ -2820,6 +3176,9 @@ TRANS(SocketUNIXCloseForCloning) (XtransConnInfo ciptr)
#endif
+#if XTRANS_SEND_FDS
+ cleanupFds(ciptr);
+#endif
ret = close(ciptr->fd);
return ret;
@@ -2830,7 +3189,7 @@ TRANS(SocketUNIXCloseForCloning) (XtransConnInfo ciptr)
#ifdef TCPCONN
# ifdef TRANS_SERVER
-static char* tcp_nolisten[] = {
+static const char* tcp_nolisten[] = {
"inet",
#if defined(IPv6) && defined(AF_INET6)
"inet6",
@@ -2867,6 +3226,10 @@ Xtransport TRANS(SocketTCPFuncs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFdInvalid),
+ TRANS(SocketRecvFdInvalid),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketINETClose),
TRANS(SocketINETClose),
@@ -2900,6 +3263,10 @@ Xtransport TRANS(SocketINETFuncs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFdInvalid),
+ TRANS(SocketRecvFdInvalid),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketINETClose),
TRANS(SocketINETClose),
@@ -2934,6 +3301,10 @@ Xtransport TRANS(SocketINET6Funcs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFdInvalid),
+ TRANS(SocketRecvFdInvalid),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketINETClose),
TRANS(SocketINETClose),
@@ -2975,6 +3346,10 @@ Xtransport TRANS(SocketLocalFuncs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFd),
+ TRANS(SocketRecvFd),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketUNIXClose),
TRANS(SocketUNIXCloseForCloning),
@@ -2982,7 +3357,7 @@ Xtransport TRANS(SocketLocalFuncs) = {
#endif /* !LOCALCONN */
# ifdef TRANS_SERVER
# if !defined(LOCALCONN)
-static char* unix_nolisten[] = { "local" , NULL };
+static const char* unix_nolisten[] = { "local" , NULL };
# endif
# endif
@@ -3022,6 +3397,10 @@ Xtransport TRANS(SocketUNIXFuncs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFd),
+ TRANS(SocketRecvFd),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketUNIXClose),
TRANS(SocketUNIXCloseForCloning),
@@ -3029,7 +3408,6 @@ Xtransport TRANS(SocketUNIXFuncs) = {
#endif /* UNIXCONN */
-
#ifdef NX_TRANS_SOCKET
/*
* Override the UNIX_DIR and UNIX_PATH settings and
diff --git a/nx-X11/lib/xtrans/Xtransutil.c b/nx-X11/lib/xtrans/Xtransutil.c
index 53fd7d75b..34abe836f 100644
--- a/nx-X11/lib/xtrans/Xtransutil.c
+++ b/nx-X11/lib/xtrans/Xtransutil.c
@@ -55,7 +55,11 @@ from The Open Group.
*/
#ifdef XTHREADS
-#include <nx-X11/Xthreads.h>
+#include <X11/Xthreads.h>
+#endif
+#ifdef WIN32
+#include <X11/Xlibint.h>
+#include <X11/Xwinsock.h>
#endif
#ifdef X11_t
@@ -193,11 +197,11 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
if (len > 0) {
if (*addrp && *addrlenp < (len + 1))
{
- free ((char *) *addrp);
+ free (*addrp);
*addrp = NULL;
}
if (!*addrp)
- *addrp = (Xtransaddr *) malloc (len + 1);
+ *addrp = malloc (len + 1);
if (*addrp) {
strcpy ((char *) *addrp, hostnamebuf);
*addrlenp = len;
@@ -208,7 +212,7 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
else
{
if (*addrp)
- free ((char *) *addrp);
+ free (*addrp);
*addrp = NULL;
*addrlenp = 0;
}
@@ -221,6 +225,13 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
#ifdef ICE_t
+/* Needed for _XGethostbyaddr usage in TRANS(GetPeerNetworkId) */
+# if defined(TCPCONN) || defined(UNIXCONN)
+# define X_INCLUDE_NETDB_H
+# define XOS_USE_NO_LOCKING
+# include <X11/Xos_r.h>
+# endif
+
#include <signal.h>
char *
@@ -231,7 +242,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
char *addr = ciptr->addr;
char hostnamebuf[256];
char *networkId = NULL;
- char *transName = ciptr->transptr->TransName;
+ const char *transName = ciptr->transptr->TransName;
if (gethostname (hostnamebuf, sizeof (hostnamebuf)) < 0)
{
@@ -244,7 +255,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
case AF_UNIX:
{
struct sockaddr_un *saddr = (struct sockaddr_un *) addr;
- networkId = (char *) malloc (3 + strlen (transName) +
+ networkId = malloc (3 + strlen (transName) +
strlen (hostnamebuf) + strlen (saddr->sun_path));
sprintf (networkId, "%s/%s:%s", transName,
hostnamebuf, saddr->sun_path);
@@ -273,8 +284,8 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
#endif
portnum = ntohs (saddr->sin_port);
- sprintf (portnumbuf, "%d", portnum);
- networkId = (char *) malloc (3 + strlen (transName) +
+ snprintf (portnumbuf, sizeof(portnumbuf), "%d", portnum);
+ networkId = malloc (3 + strlen (transName) +
strlen (hostnamebuf) + strlen (portnumbuf));
sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf);
break;
@@ -295,24 +306,12 @@ static jmp_buf env;
#ifdef SIGALRM
static volatile int nameserver_timedout = 0;
-static
-#ifdef RETSIGTYPE /* set by autoconf AC_TYPE_SIGNAL */
-RETSIGTYPE
-#else /* Imake */
-#ifdef SIGNALRETURNSINT
-int
-#else
-void
-#endif
-#endif
-nameserver_lost(int sig)
+static void
+nameserver_lost(int sig _X_UNUSED)
{
nameserver_timedout = 1;
longjmp (env, -1);
/* NOTREACHED */
-#ifdef SIGNALRETURNSINT
- return -1; /* for picky compilers */
-#endif
}
#endif /* SIGALARM */
@@ -407,8 +406,7 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr)
}
- hostname = (char *) malloc (
- strlen (ciptr->transptr->TransName) + strlen (addr) + 2);
+ hostname = malloc (strlen (ciptr->transptr->TransName) + strlen (addr) + 2);
strcpy (hostname, ciptr->transptr->TransName);
strcat (hostname, "/");
if (addr)
@@ -428,16 +426,16 @@ TRANS(WSAStartup) (void)
prmsg (2,"WSAStartup()\n");
- if (!wsadata.wVersion && WSAStartup(0x0101, &wsadata))
+ if (!wsadata.wVersion && WSAStartup(MAKEWORD(2,2), &wsadata))
return 1;
return 0;
}
#endif
+#include <ctype.h>
static int
-is_numeric (char *str)
-
+is_numeric (const char *str)
{
int i;
@@ -468,7 +466,7 @@ is_numeric (char *str)
* bit cannot be set and fail.
*/
static int
-trans_mkdir(char *path, int mode)
+trans_mkdir(const char *path, int mode)
{
struct stat buf;
@@ -480,7 +478,7 @@ trans_mkdir(char *path, int mode)
}
/* Dir doesn't exist. Try to create it */
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__CYGWIN__)
/*
* 'sticky' bit requested: assume application makes
* certain security implications. If effective user ID
@@ -575,6 +573,7 @@ trans_mkdir(char *path, int mode)
if (fstat(fd, &fbuf) == -1) {
prmsg(1, "mkdir: ERROR: fstat failed for %s (%d)\n",
path, errno);
+ close(fd);
return -1;
}
/*
@@ -586,6 +585,7 @@ trans_mkdir(char *path, int mode)
buf.st_ino != fbuf.st_ino) {
prmsg(1, "mkdir: ERROR: inode for %s changed\n",
path);
+ close(fd);
return -1;
}
if (updateOwner && fchown(fd, 0, 0) == 0)
@@ -605,8 +605,10 @@ trans_mkdir(char *path, int mode)
return -1;
}
#endif
+#if !defined(__APPLE_CC__) && !defined(__CYGWIN__)
prmsg(1, "mkdir: Owner of %s should be set to root\n",
path);
+#endif
}
if (updateMode && !updatedMode) {
diff --git a/nx-X11/lib/xtrans/transport.c b/nx-X11/lib/xtrans/transport.c
index 6632a88fb..b62fc7b64 100644
--- a/nx-X11/lib/xtrans/transport.c
+++ b/nx-X11/lib/xtrans/transport.c
@@ -47,18 +47,19 @@ from The Open Group.
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-
-#ifdef XSERV_t
-#include "os.h"
-#else
#include <stdlib.h>
-#endif
#define XTRANS_TRANSPORT_C /* used to flag Xtransint.h that it's being used
here, not just #included in another file */
#include "Xtransint.h"
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
#ifdef LOCALCONN
#include "Xtranslcl.c"
#endif
@@ -67,3 +68,7 @@ from The Open Group.
#endif
#include "Xtrans.c"
#include "Xtransutil.c"
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif