Mercurial > hg > xemacs-beta
changeset 5518:3cc7470ea71c
gnuclient: if TMPDIR was set and connect failed, try again with /tmp
2011-06-03 Aidan Kehoe <kehoea@parhasard.net>
* gnuslib.c (connect_to_unix_server):
Retry with /tmp as a directory in which to search for Unix sockets
if an attempt to connect with some other directory failed (which
may be because gnuclient and gnuserv don't share an environment
value for TMPDIR, or because gnuserv was compiled with USE_TMPDIR
turned off).
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 03 Jun 2011 18:40:57 +0100 |
parents | 5e128eda1d1f |
children | bcd74c477a38 |
files | lib-src/ChangeLog lib-src/gnuslib.c |
diffstat | 2 files changed, 49 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/lib-src/ChangeLog Wed Jun 01 14:53:44 2011 +0200 +++ b/lib-src/ChangeLog Fri Jun 03 18:40:57 2011 +0100 @@ -1,3 +1,12 @@ +2011-06-03 Aidan Kehoe <kehoea@parhasard.net> + + * gnuslib.c (connect_to_unix_server): + Retry with /tmp as a directory in which to search for Unix sockets + if an attempt to connect with some other directory failed (which + may be because gnuclient and gnuserv don't share an environment + value for TMPDIR, or because gnuserv was compiled with USE_TMPDIR + turned off). + 2011-05-20 Jerry James <james@xemacs.org> * Makefile.in.in: Default DESTDIR to the empty string, and use it in
--- a/lib-src/gnuslib.c Wed Jun 01 14:53:44 2011 +0200 +++ b/lib-src/gnuslib.c Fri Jun 03 18:40:57 2011 +0100 @@ -266,26 +266,52 @@ { int s; /* connected socket descriptor */ struct sockaddr_un server; /* for unix connections */ + char *ctus_tmpdir = tmpdir; - if ((s = socket(AF_UNIX,SOCK_STREAM,0)) < 0) { - perror(progname); - fprintf(stderr,"%s: unable to create socket\n",progname); - exit(1); - }; /* if */ + do + { + if ((s = socket(AF_UNIX,SOCK_STREAM,0)) < 0) { + perror(progname); + fprintf(stderr,"%s: unable to create socket\n",progname); + exit(1); + }; /* if */ - server.sun_family = AF_UNIX; + server.sun_family = AF_UNIX; + #ifdef HIDE_UNIX_SOCKET - sprintf(server.sun_path,"%s/gsrvdir%d/gsrv",tmpdir,(int)geteuid()); + sprintf(server.sun_path,"%s/gsrvdir%d/gsrv", ctus_tmpdir, + (int)geteuid()); #else /* HIDE_UNIX_SOCKET */ - sprintf(server.sun_path,"%s/gsrv%d",tmpdir,(int)geteuid()); + sprintf(server.sun_path,"%s/gsrv%d", ctus_tmpdir, + (int)geteuid()); #endif /* HIDE_UNIX_SOCKET */ - if (connect(s,(struct sockaddr *)&server,strlen(server.sun_path)+2) < 0) { - perror(progname); - fprintf(stderr,"%s: unable to connect to local\n",progname); - exit(1); - }; /* if */ + if (connect(s,(struct sockaddr *)&server,strlen(server.sun_path)+2) < 0) { +#ifndef WIN32_NATIVE +#ifdef USE_TMPDIR + if (0 != strcmp (ctus_tmpdir, "/tmp")) + { + /* Try again; the server may have no environment value for + TMPDIR, or it may have been compiled without USE_TMPDIR, and + in both those cases it's useful to retry with /tmp. - return(s); + In the case where the server was compiled with USE_TMPDIR and + it has a value for TMPDIR distinct from ours, we have no way of + working out what that value is, so it's appropriate to give + up. */ + close (s); + ctus_tmpdir = "/tmp"; + continue; + } +#endif /* USE_TMPDIR */ +#endif /* !WIN32_NATIVE */ + perror(progname); + fprintf(stderr,"%s: %s: unable to connect to local\n", progname, + server.sun_path); + exit(1); + }; /* if */ + + return(s); + } while (1); } /* connect_to_unix_server */ #endif /* UNIX_DOMAIN_SOCKETS */