aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog20
-rw-r--r--lib-src/emacsclient.c151
2 files changed, 127 insertions, 44 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index d25c4710ccc..c240cfb956b 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,23 @@
12006-11-06 Juanma Barranquero <lekktu@gmail.com>
2
3 * emacsclient.c (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show
4 option --socket-name.
5 (decode_options): Don't get EMACS_SERVER_FILE here, it could override
6 command line options.
7 (decode_options) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't parse "-s" option.
8 (fail): Don't check for missing arguments, it is now done in set_socket.
9 (file_name_absolute_p): New function (loosely based on the one in
10 fileio.c).
11 (initialize_sockets): Don't check for duplicate loading of Winsock.
12 (get_server_config): Only try relative paths in the default
13 directory locations.
14 (set_tcp_socket): Don't call INITIALIZE(). Warn when connecting to
15 a remote server.
16 (set_socket): Call INITIALIZE(). Search explicit command-line
17 arguments, then environment variable EMACS_SERVER_FILE, then implicit
18 socket paths, before trying the alternate editor.
19 (main): Use file_name_absolute_p.
20
12006-11-04 Eli Zaretskii <eliz@gnu.org> 212006-11-04 Eli Zaretskii <eliz@gnu.org>
2 22
3 * makefile.w32-in (../src/$(BLD)/temacs.exe): Create as temporary 23 * makefile.w32-in (../src/$(BLD)/temacs.exe): Create as temporary
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index af7c10cac7d..aeb221dfed1 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -115,7 +115,7 @@ char *display = NULL;
115 115
116/* If non-NULL, the name of an editor to fallback to if the server 116/* If non-NULL, the name of an editor to fallback to if the server
117 is not running. --alternate-editor. */ 117 is not running. --alternate-editor. */
118const char * alternate_editor = NULL; 118const char *alternate_editor = NULL;
119 119
120/* If non-NULL, the filename of the UNIX socket. */ 120/* If non-NULL, the filename of the UNIX socket. */
121char *socket_name = NULL; 121char *socket_name = NULL;
@@ -132,7 +132,9 @@ struct option longopts[] =
132 { "help", no_argument, NULL, 'H' }, 132 { "help", no_argument, NULL, 'H' },
133 { "version", no_argument, NULL, 'V' }, 133 { "version", no_argument, NULL, 'V' },
134 { "alternate-editor", required_argument, NULL, 'a' }, 134 { "alternate-editor", required_argument, NULL, 'a' },
135#ifndef NO_SOCKETS_IN_FILE_SYSTEM
135 { "socket-name", required_argument, NULL, 's' }, 136 { "socket-name", required_argument, NULL, 's' },
137#endif
136 { "server-file", required_argument, NULL, 'f' }, 138 { "server-file", required_argument, NULL, 'f' },
137 { "display", required_argument, NULL, 'd' }, 139 { "display", required_argument, NULL, 'd' },
138 { 0, 0, 0, 0 } 140 { 0, 0, 0, 0 }
@@ -147,12 +149,16 @@ decode_options (argc, argv)
147 char **argv; 149 char **argv;
148{ 150{
149 alternate_editor = getenv ("ALTERNATE_EDITOR"); 151 alternate_editor = getenv ("ALTERNATE_EDITOR");
150 server_file = getenv ("EMACS_SERVER_FILE");
151 152
152 while (1) 153 while (1)
153 { 154 {
154 int opt = getopt_long (argc, argv, 155 int opt = getopt_long (argc, argv,
155 "VHnea:s:f:d:", longopts, 0); 156#ifndef NO_SOCKETS_IN_FILE_SYSTEM
157 "VHnea:s:f:d:",
158#else
159 "VHnea:f:d:",
160#endif
161 longopts, 0);
156 162
157 if (opt == EOF) 163 if (opt == EOF)
158 break; 164 break;
@@ -168,9 +174,11 @@ decode_options (argc, argv)
168 alternate_editor = optarg; 174 alternate_editor = optarg;
169 break; 175 break;
170 176
177#ifndef NO_SOCKETS_IN_FILE_SYSTEM
171 case 's': 178 case 's':
172 socket_name = optarg; 179 socket_name = optarg;
173 break; 180 break;
181#endif
174 182
175 case 'f': 183 case 'f':
176 server_file = optarg; 184 server_file = optarg;
@@ -252,16 +260,6 @@ fail (argc, argv)
252 fprintf (stderr, "%s: error executing alternate editor \"%s\"\n", 260 fprintf (stderr, "%s: error executing alternate editor \"%s\"\n",
253 progname, alternate_editor); 261 progname, alternate_editor);
254 } 262 }
255 else
256 {
257 fprintf (stderr, "%s: No socket or alternate editor. Please use:\n\n"
258#if !defined (NO_SOCKETS_IN_FILE_SYSTEM)
259"\t--socket-name\n"
260#endif
261"\t--server-file (or environment variable EMACS_SERVER_FILE)\n\
262\t--alternate-editor (or environment variable ALTERNATE_EDITOR)\n",
263 progname);
264 }
265 exit (EXIT_FAILURE); 263 exit (EXIT_FAILURE);
266} 264}
267 265
@@ -306,7 +304,8 @@ int sblen = 0; /* Fill pointer for the send buffer. */
306 - the data ends in "\n", or 304 - the data ends in "\n", or
307 - the buffer is full (but this shouldn't happen) 305 - the buffer is full (but this shouldn't happen)
308 Otherwise, we just accumulate it. */ 306 Otherwise, we just accumulate it. */
309void send_to_emacs (s, data) 307void
308send_to_emacs (s, data)
310 HSOCKET s; 309 HSOCKET s;
311 char *data; 310 char *data;
312{ 311{
@@ -381,21 +380,46 @@ quote_file_name (s, name)
381 free (copy); 380 free (copy);
382} 381}
383 382
383int
384file_name_absolute_p (filename)
385 const unsigned char *filename;
386{
387 /* Sanity check, it shouldn't happen. */
388 if (! filename) return FALSE;
389
390 /* /xxx is always an absolute path. */
391 if (filename[0] == '/') return TRUE;
392
393 /* Empty filenames (which shouldn't happen) are relative. */
394 if (filename[0] == '\0') return FALSE;
395
396#ifdef WINDOWSNT
397 /* X:\xxx is always absolute; X:xxx is an error and will fail. */
398 if (islower (tolower (filename[0]))
399 && filename[1] == ':' && filename[2] == '\\')
400 return TRUE;
401
402 /* Both \xxx and \\xxx\yyy are absolute. */
403 if (filename[0] == '\\') return TRUE;
404#endif
405
406 return FALSE;
407}
408
384#ifdef WINDOWSNT 409#ifdef WINDOWSNT
385/* Wrapper to make WSACleanup a cdecl, as required by atexit(). */ 410/* Wrapper to make WSACleanup a cdecl, as required by atexit(). */
386void __cdecl close_winsock () 411void
412__cdecl close_winsock ()
387{ 413{
388 WSACleanup (); 414 WSACleanup ();
389} 415}
390 416
391void initialize_sockets () 417/* Initialize the WinSock2 library. */
418void
419initialize_sockets ()
392{ 420{
393 static done = FALSE;
394 WSADATA wsaData; 421 WSADATA wsaData;
395 422
396 if (done) return;
397
398 /* Initialize the WinSock2 library. */
399 if (WSAStartup (MAKEWORD (2, 0), &wsaData)) 423 if (WSAStartup (MAKEWORD (2, 0), &wsaData))
400 { 424 {
401 fprintf (stderr, "%s: error initializing WinSock2", progname); 425 fprintf (stderr, "%s: error initializing WinSock2", progname);
@@ -403,7 +427,6 @@ void initialize_sockets ()
403 } 427 }
404 428
405 atexit (close_winsock); 429 atexit (close_winsock);
406 done = TRUE;
407} 430}
408#endif /* WINDOWSNT */ 431#endif /* WINDOWSNT */
409 432
@@ -411,15 +434,18 @@ void initialize_sockets ()
411 * Read the information needed to set up a TCP comm channel with 434 * Read the information needed to set up a TCP comm channel with
412 * the Emacs server: host, port and authentication string. 435 * the Emacs server: host, port and authentication string.
413*/ 436*/
414int get_server_config (server, authentication) 437int
438get_server_config (server, authentication)
415 struct sockaddr_in *server; 439 struct sockaddr_in *server;
416 char *authentication; 440 char *authentication;
417{ 441{
418 FILE *config;
419 char dotted[32]; 442 char dotted[32];
420 char *port; 443 char *port;
444 FILE *config = NULL;
421 445
422 if (! (config = fopen (server_file, "rb"))) 446 if (file_name_absolute_p (server_file))
447 config = fopen (server_file, "rb");
448 else
423 { 449 {
424 char *home = getenv ("HOME"); 450 char *home = getenv ("HOME");
425#ifdef WINDOWSNT 451#ifdef WINDOWSNT
@@ -471,11 +497,13 @@ set_tcp_socket ()
471 struct linger l_arg = {1, 1}; 497 struct linger l_arg = {1, 1};
472 char auth_string[AUTH_KEY_LENGTH + 1]; 498 char auth_string[AUTH_KEY_LENGTH + 1];
473 499
474 INITIALIZE ();
475
476 if (! get_server_config (&server, auth_string)) 500 if (! get_server_config (&server, auth_string))
477 return INVALID_SOCKET; 501 return INVALID_SOCKET;
478 502
503 if (server.sin_addr.s_addr != inet_addr ("127.0.0.1"))
504 fprintf (stderr, "%s: connected to remote socket at %s\n",
505 progname, inet_ntoa (server.sin_addr));
506
479 /* 507 /*
480 * Open up an AF_INET socket 508 * Open up an AF_INET socket
481 */ 509 */
@@ -645,7 +673,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
645 else 673 else
646 fprintf (stderr, "%s: can't stat %s: %s\n", 674 fprintf (stderr, "%s: can't stat %s: %s\n",
647 progname, server.sun_path, strerror (saved_errno)); 675 progname, server.sun_path, strerror (saved_errno));
648 return INVALID_SOCKET; 676 return INVALID_SOCKET;
649 } 677 }
650 } 678 }
651 679
@@ -664,17 +692,61 @@ To start the server in Emacs, type \"M-x server-start\".\n",
664HSOCKET 692HSOCKET
665set_socket () 693set_socket ()
666{ 694{
667 if (server_file) 695 HSOCKET s;
668 return set_tcp_socket (); 696
669 else 697 INITIALIZE ();
698
670#ifndef NO_SOCKETS_IN_FILE_SYSTEM 699#ifndef NO_SOCKETS_IN_FILE_SYSTEM
671 return set_local_socket (); 700 /* Explicit --socket-name argument. */
672#else 701 if (socket_name)
702 {
703 s = set_local_socket ();
704 if ((s != INVALID_SOCKET) || alternate_editor)
705 return s;
706
707 fprintf (stderr, "%s: error accessing socket \"%s\"",
708 progname, socket_name);
709 exit (EXIT_FAILURE);
710 }
711#endif
712
713 /* Explicit --server-file arg or EMACS_SERVER_FILE variable. */
714 if (!server_file)
715 server_file = getenv ("EMACS_SERVER_FILE");
716
717 if (server_file)
673 { 718 {
674 server_file = "server"; 719 s = set_tcp_socket ();
675 return set_tcp_socket (); 720 if ((s != INVALID_SOCKET) || alternate_editor)
721 return s;
722
723 fprintf (stderr, "%s: error accessing server file \"%s\"",
724 progname, server_file);
725 exit (EXIT_FAILURE);
676 } 726 }
727
728#ifndef NO_SOCKETS_IN_FILE_SYSTEM
729 /* Implicit local socket. */
730 s = set_local_socket ();
731 if (s != INVALID_SOCKET)
732 return s;
733#endif
734
735 /* Implicit server file. */
736 server_file = "server";
737 s = set_tcp_socket ();
738 if ((s != INVALID_SOCKET) || alternate_editor)
739 return s;
740
741 /* No implicit or explicit socket, and no alternate editor. */
742 fprintf (stderr, "%s: No socket or alternate editor. Please use:\n\n"
743#ifndef NO_SOCKETS_IN_FILE_SYSTEM
744"\t--socket-name\n"
677#endif 745#endif
746"\t--server-file (or environment variable EMACS_SERVER_FILE)\n\
747\t--alternate-editor (or environment variable ALTERNATE_EDITOR)\n",
748 progname);
749 exit (EXIT_FAILURE);
678} 750}
679 751
680int 752int
@@ -748,16 +820,7 @@ main (argc, argv)
748 SEND_STRING ("/"); 820 SEND_STRING ("/");
749 } 821 }
750 } 822 }
751#ifndef WINDOWSNT 823 else if (! file_name_absolute_p (argv[i]))
752 else if (*argv[i] != '/')
753#else
754 else if ((*argv[i] != '/')
755 /* Absolute paths can also start with backslash
756 or drive letters. */
757 && (*argv[i] != '\\')
758 && (!islower (tolower (*argv[i]))
759 || (argv[i][1] != ':')))
760#endif
761 { 824 {
762 SEND_QUOTED (cwd); 825 SEND_QUOTED (cwd);
763 SEND_STRING ("/"); 826 SEND_STRING ("/");