Skip to content

Commit

Permalink
Update XPA library to latest version
Browse files Browse the repository at this point in the history
Update XPA communication library in libxpa/ to the latest version (2.1.19)
dated 21 March 2019.

The XPA library is now on GitHub at https://github.com/ericmandel/xpa

As a reminder, this directory contains only the parts of the XPA library needed
for the ScopeDesign project, and not the entire library.

	modified:   LICENSE
	modified:   README
	modified:   client.c
	modified:   find.c
	modified:   find.h
	modified:   prsetup.h
	modified:   tclloop.c
	modified:   tcp.c
	modified:   word.c
	modified:   word.h
	modified:   xalloc.c
	modified:   xalloc.h
	modified:   xlaunch.c
	modified:   xlaunch.h
	modified:   xpa.c
	modified:   xpa.h
	modified:   xpap.h
	modified:   xport.h
  • Loading branch information
tbowers7 committed Dec 5, 2019
1 parent bfc9b16 commit 9d59812
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 34 deletions.
2 changes: 1 addition & 1 deletion libxpa/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
XPA is distributed under the terms of The MIT License (MIT), reproduced below.

Copyright (c) 2014 Smithsonian Institution
Copyright (c) 2014-2016 Smithsonian Institution

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion libxpa/README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This directory contains the pieces of XPA Version 2.1.17 (Dec 15, 2016)
This directory contains the pieces of XPA Version 2.1.19 (Mar 21, 2019)
needed for use with ScopeDesign. The Makefiles are modified (narrowed)
for the purpose of being an included "convenience library" for this
project.
Expand Down
28 changes: 19 additions & 9 deletions libxpa/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,13 +1061,19 @@ static int XPAClientGet(xpa, client)
if( xpa->nclient > 1 ){
snprintf(tbuf, SZ_LINE, "XPA$BEGIN %s:%s %s\n",
client->xclass, client->name, client->method);
write(client->fd, tbuf, strlen(tbuf));
if( write(client->fd, tbuf, strlen(tbuf)) < 0 ){
fprintf(stderr, "warning: XPA client can't write header\n");
}
}
if( write(client->fd, *(client->bufptr), *(client->lenptr)) < 0 ){
fprintf(stderr, "warning: XPA client can't write data\n");
}
write(client->fd, *(client->bufptr), *(client->lenptr));
if( xpa->nclient > 1 ){
snprintf(tbuf, SZ_LINE, "XPA$END %s:%s %s\n",
client->xclass, client->name, client->method);
write(client->fd, tbuf, strlen(tbuf));
if( write(client->fd, tbuf, strlen(tbuf)) < 0 ){
fprintf(stderr, "warning: XPA client can't write header\n");
}
}
/* we can free buf, since its not being passed back */
if( *(client->bufptr) ){
Expand Down Expand Up @@ -1096,7 +1102,9 @@ static int XPAClientGet(xpa, client)
/* for single client fd mode, we write immediately -- this deals with
the important case of one client with a large amount of data */
if( (client->mode & XPA_CLIENT_FD) && (xpa->nclient == 1) ){
write(client->fd, *(client->bufptr), *(client->lenptr));
if( write(client->fd, *(client->bufptr), *(client->lenptr)) < 0 ){
fprintf(stderr, "warning: XPA client can't write data\n");
}
/* reset buf for next read */
if( *(client->bufptr) ) xfree(*(client->bufptr));
*(client->bufptr) = NULL;
Expand Down Expand Up @@ -1532,8 +1540,9 @@ static int XPAClientLoopFork(xpa, mode)
else if( pid == 0 ){ /* child */
/* child write to parent that he is active */
close(fd[0]);
write(fd[1], &active, 1);
close(fd[1]);
if( write(fd[1], &active, 1) >= 0 ){
close(fd[1]);
}
#ifdef USE_DOUBLE_FORK
/* second fork prevents zombies:
when child/parent exits, second child is inherited
Expand All @@ -1552,8 +1561,9 @@ static int XPAClientLoopFork(xpa, mode)
} else { /* parent */
/* parent waits for child to wake up */
close(fd[1]);
read(fd[0], &active, 1);
close(fd[0]);
if( read(fd[0], &active, 1) >= 0 ){
close(fd[0]);
}
#ifdef USE_DOUBLE_FORK
/* for double fork, also wait for intermediate process to exit */
waitpid(pid, NULL, 0);
Expand Down Expand Up @@ -2673,7 +2683,7 @@ int XPASetFd(xpa, xtemplate, paramlist, mode, fd, names, messages, n)
int got2=0;
int type='s';
int idef=1;
int flags;
int flags=0;
char *s;
char tbuf[SZ_LINE];
XPAClient client, tclient;
Expand Down
4 changes: 3 additions & 1 deletion libxpa/find.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ char *ResolvePath(ibuf, obuf, maxlen)

/* if we have a relative path to deal with, get current directory */
if( (*ibuf == '.') || ( (strchr(ibuf, '/') != NULL) && (*ibuf != '/') ) ){
getcwd(path, MAXBUFSIZE);
if( !getcwd(path, MAXBUFSIZE) ){
*path = '\0';
}
}
else{
*path = '\0';
Expand Down
2 changes: 1 addition & 1 deletion libxpa/find.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define __find_h

#if HAVE_CONFIG_H
#include <config.h>
#include <conf.h>
#endif

#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion libxpa/prsetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#endif

#ifndef ABS
#define ABS(x) ((x)<0?(-x):(x))
#define ABS(x) ((x)<0?(-(x)):(x))
#endif

#endif
Expand Down
2 changes: 1 addition & 1 deletion libxpa/tclloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
presence of Windows by the presence of Cygwin. This is important for Tcl
because Windows does not support Tcl_CreateFileHandler */
#ifndef HAVE_TCLFILEHANDLER
#if HAVE_CYGWIN
#if HAVE_CYGWIN|HAVE_MINGW32
#define HAVE_TCLFILEHANDLER 0
#else
#define HAVE_TCLFILEHANDLER 1
Expand Down
48 changes: 45 additions & 3 deletions libxpa/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
*
*/
#if HAVE_CONFIG_H
#include <config.h>
#include <conf.h>
#endif

#if HAVE_UNISTD_H
#include <unistd.h>
#endif
Expand Down Expand Up @@ -84,7 +85,11 @@ int gethost(xhost, len)
#endif
{
char *s=NULL;
#if HAVE_GETADDRINFO
struct addrinfo *hints=NULL, *addrinfo=NULL;
#else
struct hostent *hent;
#endif
static int init=0;

if( use_localhost == 0 ){
Expand All @@ -97,10 +102,25 @@ int gethost(xhost, len)
init++;
}
strncpy(xhost, myhost, len-1);

#if HAVE_GETADDRINFO
hints = (struct addrinfo *)calloc(1, sizeof(struct addrinfo));
hints->ai_flags |= AI_CANONNAME;
hints->ai_family = AF_INET;
if( getaddrinfo(xhost, NULL, hints, &addrinfo) != 0 ){
freeaddrinfo(addrinfo);
if( hints ) free(hints);
return -1;
}
strncpy(xhost, addrinfo->ai_canonname, len-1);
freeaddrinfo(addrinfo);
if( hints ) free(hints);
#else
if( (hent = gethostbyname(xhost)) == NULL ){
return(-1);
}
strncpy(xhost, hent->h_name, len-1);
#endif
}
else{
strncpy(xhost, "localhost", len-1);
Expand Down Expand Up @@ -130,13 +150,18 @@ unsigned int gethostip(xhost)
char *xhost; /* (in) Hostname (human readable) */
#endif
{
#if HAVE_GETADDRINFO
struct addrinfo *hints=NULL, *addrinfo=NULL;
struct sockaddr_in * p;
int got;
#else
struct hostent *hostent;
#endif
unsigned int ip;
char temp[SZ_LINE];
int saveip=0;
static unsigned int myip=0;


/* null input means current host */
if( (xhost == NULL) || (*xhost == '\0') || !strcmp(xhost, "$host") ){
if( myip != 0 )
Expand Down Expand Up @@ -165,6 +190,19 @@ unsigned int gethostip(xhost)
goto done;
}

#if HAVE_GETADDRINFO
/*
* Try looking it up by name.
*/
hints = (struct addrinfo *)calloc(1, sizeof(struct addrinfo));
hints->ai_family = AF_INET;
got = getaddrinfo(temp, NULL, hints, &addrinfo);
if( got == 0 ){
p = (struct sockaddr_in *)(addrinfo->ai_addr);
memcpy(&ip, &(p->sin_addr.s_addr), sizeof(p->sin_addr.s_addr));
goto done;
}
#else
/*
* Try looking it up by name. If successful, the IP address is in
* hostent->h_addr_list[0]
Expand All @@ -173,12 +211,16 @@ unsigned int gethostip(xhost)
memcpy(&ip, hostent->h_addr_list[0], (size_t)hostent->h_length);
goto done;
}

#endif
/* could not convert */
ip = 0;
saveip = 0;

done:
#if HAVE_GETADDRINFO
freeaddrinfo(addrinfo);
if( hints ) free(hints);
#endif
ip = ntohl(ip);
if( saveip ) myip = ip;
return(ip);
Expand Down
3 changes: 3 additions & 0 deletions libxpa/word.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ int keyword(ibuf, key, obuf, maxlen)
case '[':
quote = ']';
break;
default:
quote = '\0';
break;
}
/* bump past opening quote char */
t++; u++; v++;
Expand Down
2 changes: 1 addition & 1 deletion libxpa/word.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define __word_h

#if HAVE_CONFIG_H
#include <config.h>
#include <conf.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
Expand Down
4 changes: 3 additions & 1 deletion libxpa/xalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ static void _xalloc_error(void)
static void _xalloc_error()
#endif
{
write(1, XALLOC_ERROR, strlen(XALLOC_ERROR));
if( write(1, XALLOC_ERROR, strlen(XALLOC_ERROR)) < 0 ){
exit(1);
}
#if XALLOC_SETJMP
if( xalloc_envptr )
longjmp(*xalloc_envptr, XALLOC_SETJMP);
Expand Down
2 changes: 1 addition & 1 deletion libxpa/xalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define __xalloc_h

#if HAVE_CONFIG_H
#include <config.h>
#include <conf.h>
#endif

#include <sys/types.h>
Expand Down
9 changes: 6 additions & 3 deletions libxpa/xlaunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ static int launch_fork_exec(char *cmdstring, int attach,
case 2:
/* if stderr is the same as stdout, just dup */
if( stdfiles[1] && !strcmp(stdfiles[1], stdfiles[i]) ){
dup(1);
if( dup(1) < 0 ){
_exit(-1);
}
}
else{
if( open(stdfiles[i], O_CREAT|O_WRONLY|O_TRUNC, 0600) < 0){
Expand Down Expand Up @@ -279,8 +281,9 @@ static int launch_fork_exec(char *cmdstring, int attach,
status = 127;
#if LAUNCH_USE_PIPE
if( !attach ){
write(fd[1], &status, 4);
close(fd[1]);
if( write(fd[1], &status, 4) >= 0 ){
close(fd[1]);
}
}
#endif
_exit(status); /* exec error */
Expand Down
5 changes: 4 additions & 1 deletion libxpa/xlaunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define __xlaunch_h

#if HAVE_CONFIG_H
#include <config.h>
#include <conf.h>
#endif

#include <stdio.h>
Expand All @@ -24,6 +24,9 @@
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_STRINGS_H
#include <strings.h>
#endif
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
Expand Down
16 changes: 12 additions & 4 deletions libxpa/xpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ static int stimeout=XPA_SHORT_TIMEOUT; /* select, gets timeout in secs */
static int ltimeout=XPA_LONG_TIMEOUT; /* fillbuf timeout in secs */
static int ctimeout=XPA_CONNECT_TIMEOUT;/* local xpans connect */
static int verbosity=XPA_VERBOSITY; /* 0=quiet, 1=normal, 2=full */
static int nsdelay=XPA_NSDELAY; /* delay increment waiting for ns to start */
static int retries=XPA_RETRIES; /* retries when retrying */
static int guseacl=1; /* 0=don't use acls, 1=enable acls */
static int etimestamp=0; /* 0=don't timestamp errors, 1=do timestamp */
static int nsregister=1; /* 0=don't register with xpans, 1=register */
Expand Down Expand Up @@ -166,7 +168,7 @@ static int XPAProxyConnect(xpa, method, rip, rport, rname)
xclose(ofd);
/* Unix sockets get ECONNREFUSED when the listen queue is full,
so we try a few times to give the server a chance to recover */
if( (xerrno == ECONNREFUSED) && (tries < XPA_RETRIES) ){
if( (xerrno == ECONNREFUSED) && (tries < retries) ){
tries++;
XPASleep(10);
goto again2;
Expand Down Expand Up @@ -614,7 +616,7 @@ static NS XPANSOpen(xpa, host, force)
xclose(xnsfd);
/* Unix sockets get ECONNREFUSED when the listen queue is full,
so we try a few times to give the server a chance to recover */
if( (xerrno == ECONNREFUSED) && (tries < XPA_RETRIES) ){
if( (xerrno == ECONNREFUSED) && (tries < retries) ){
tries++;
XPASleep(10);
goto again2;
Expand Down Expand Up @@ -691,7 +693,7 @@ static NS XPANSOpen(xpa, host, force)
goto nons;
#endif
/* enter loop looking to connect */
for(tries=0; tries<XPA_RETRIES; tries++){
for(tries=0; tries<retries; tries++){
switch(mtype){
case XPA_INET:
/* use $localhost alternately with $host */
Expand Down Expand Up @@ -724,7 +726,7 @@ static NS XPANSOpen(xpa, host, force)
#endif
}
xclose(xnsfd);
XPASleep(XPA_NSDELAY);
XPASleep(nsdelay);
}
/* if we got here, we did not connect */
goto nons;
Expand Down Expand Up @@ -2731,6 +2733,12 @@ void XPAInitEnv()
/* set xpans connect timeout, if necessary */
if( (s=(char *)getenv("XPA_CONNECT_TIMEOUT")) != NULL )
ctimeout = atoi(s);
/* set nsdelay timeout, if necessary */
if( (s=(char *)getenv("XPA_NSDELAY")) != NULL )
nsdelay = atoi(s);
/* set retries, if necessary */
if( (s=(char *)getenv("XPA_RETRIES")) != NULL )
retries = atoi(s);
/* set verbosity level, if necessary */
if( (s=(char *)getenv("XPA_VERBOSITY")) != NULL ){
if( istrue(s) )
Expand Down
4 changes: 2 additions & 2 deletions libxpa/xpa.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

#define XPA_MAJOR_VERSION 2
#define XPA_MINOR_VERSION 1
#define XPA_PATCH_LEVEL 17
#define XPA_VERSION "2.1.17"
#define XPA_PATCH_LEVEL 18
#define XPA_VERSION "2.1.18"

/* #define XPA_DEBUG 1 */
#ifdef XPA_DEBUG
Expand Down
Loading

0 comments on commit 9d59812

Please sign in to comment.