annotate lib-src/emacsclient.c @ 74413:3f31a8cff008

*** empty log message ***
author Kim F. Storm <storm@cua.dk>
date Mon, 04 Dec 2006 12:39:58 +0000
parents c6cb776ffbb7
children fe8bd1af34c4 c71725faff1a f1d13e615070
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
1 /* Client process that communicates with GNU Emacs acting as server.
64769
6358e3c6075c Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64083
diff changeset
2 Copyright (C) 1986, 1987, 1994, 1999, 2000, 2001, 2002, 2003, 2004,
68647
3661e9b3c48f Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64769
diff changeset
3 2005, 2006 Free Software Foundation, Inc.
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 This file is part of GNU Emacs.
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
5522
64a936b21f74 Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 any later version.
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 GNU General Public License for more details.
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
64083
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60718
diff changeset
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60718
diff changeset
20 Boston, MA 02110-1301, USA. */
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 #define NO_SHORTNAMES
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
24
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
25 #ifdef HAVE_CONFIG_H
42412
83c1951257f1 Include <config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 42176
diff changeset
26 #include <config.h>
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
27 #endif
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
28
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
29 #ifdef WINDOWSNT
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
30
73973
a36e68eb4ae8 [WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents: 73896
diff changeset
31 /* config.h defines these, which disables sockets altogether! */
a36e68eb4ae8 [WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents: 73896
diff changeset
32 # undef _WINSOCKAPI_
a36e68eb4ae8 [WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents: 73896
diff changeset
33 # undef _WINSOCK_H
a36e68eb4ae8 [WINDOWSNT]: Undef _WINSOCKAPI_ and _WINSOCK_H.
Juanma Barranquero <lekktu@gmail.com>
parents: 73896
diff changeset
34
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
35 # include <malloc.h>
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
36 # include <stdlib.h>
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
37 # include <windows.h>
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
38
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
39 # define NO_SOCKETS_IN_FILE_SYSTEM
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
40
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
41 # define HSOCKET SOCKET
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
42 # define CLOSE_SOCKET closesocket
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
43 # define INITIALIZE() (initialize_sockets ())
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
44
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
45 #else /* !WINDOWSNT */
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
46
73896
09dabd95380c [!WINDOWSNT]: Include <sys/types.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73816
diff changeset
47 # include <sys/types.h>
09dabd95380c [!WINDOWSNT]: Include <sys/types.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73816
diff changeset
48
73617
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
49 # ifdef HAVE_INET_SOCKETS
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
50 # include <netinet/in.h>
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
51 # endif
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
52
73578
e193b6a3f379 Fixes to emacsclient.c for GNU/Linux.
Juanma Barranquero <lekktu@gmail.com>
parents: 73562
diff changeset
53 # define INVALID_SOCKET -1
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
54 # define HSOCKET int
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
55 # define CLOSE_SOCKET close
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
56 # define INITIALIZE()
73585
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
57
7d264c036b25 [WINDOWSNT]: Include <malloc.h> and <stdlib.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73583
diff changeset
58 #endif /* !WINDOWSNT */
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
59
3595
e10f7473d2e3 * emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents: 1031
diff changeset
60 #undef signal
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
62 #include <stdarg.h>
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
63 #include <ctype.h>
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
64 #include <stdio.h>
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
65 #include "getopt.h"
21431
a080769e8f7d Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents: 21387
diff changeset
66 #ifdef HAVE_UNISTD_H
a080769e8f7d Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents: 21387
diff changeset
67 #include <unistd.h>
a080769e8f7d Move inclusion of unistd.h to top, else fails on
Dave Love <fx@gnu.org>
parents: 21387
diff changeset
68 #endif
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
70 #ifdef VMS
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
71 # include "vms-pwd.h"
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
72 #else /* not VMS */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
73 #ifdef WINDOWSNT
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
74 # include <io.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
75 #else /* not WINDOWSNT */
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
76 # include <pwd.h>
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
77 #endif /* not WINDOWSNT */
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
78 #endif /* not VMS */
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
79
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
80 char *getenv (), *getwd ();
60718
96023ae0af92 * emacsclient.c: Avoid expansion of getcwd when defined as a macro.
Jan Djärv <jan.h.d@swipnet.se>
parents: 56446
diff changeset
81 char *(getcwd) ();
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
82
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
83 #ifndef VERSION
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
84 #define VERSION "unspecified"
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
85 #endif
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
86
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
87 #define SEND_STRING(data) (send_to_emacs (s, (data)))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
88 #define SEND_QUOTED(data) (quote_file_name (s, (data)))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
89
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
90 #ifndef EXIT_SUCCESS
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
91 #define EXIT_SUCCESS 0
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
92 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
93
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
94 #ifndef EXIT_FAILURE
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
95 #define EXIT_FAILURE 1
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
96 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
97
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
98 #ifndef FALSE
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
99 #define FALSE 0
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
100 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
101
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
102 #ifndef TRUE
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
103 #define TRUE 1
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
104 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
105
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
106 #ifndef NO_RETURN
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
107 #define NO_RETURN
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
108 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
109
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
110 /* Name used to invoke this program. */
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
111 char *progname;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
112
16146
a649abfefbb1 (longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents: 16074
diff changeset
113 /* Nonzero means don't wait for a response from Emacs. --no-wait. */
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
114 int nowait = 0;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
115
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
116 /* Nonzero means args are expressions to be evaluated. --eval. */
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
117 int eval = 0;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
118
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
119 /* The display on which Emacs should work. --display. */
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
120 char *display = NULL;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
121
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
122 /* If non-NULL, the name of an editor to fallback to if the server
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
123 is not running. --alternate-editor. */
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
124 const char *alternate_editor = NULL;
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
125
52532
cd53bfef4ab1 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 52479
diff changeset
126 /* If non-NULL, the filename of the UNIX socket. */
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
127 char *socket_name = NULL;
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
128
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
129 /* If non-NULL, the filename of the authentication file. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
130 char *server_file = NULL;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
131
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
132 /* PID of the Emacs server process. */
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
133 int emacs_pid = 0;
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
134
72005
da0099bc0ba4 * ebrowse.c (usage, version): Mark as NO_RETURN.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 68647
diff changeset
135 void print_help_and_exit () NO_RETURN;
21387
4812cf228971 Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 19582
diff changeset
136
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
137 struct option longopts[] =
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
138 {
16146
a649abfefbb1 (longopts): Change nowait to no-wait.
Richard M. Stallman <rms@gnu.org>
parents: 16074
diff changeset
139 { "no-wait", no_argument, NULL, 'n' },
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
140 { "eval", no_argument, NULL, 'e' },
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
141 { "help", no_argument, NULL, 'H' },
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
142 { "version", no_argument, NULL, 'V' },
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
143 { "alternate-editor", required_argument, NULL, 'a' },
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
144 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
145 { "socket-name", required_argument, NULL, 's' },
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
146 #endif
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
147 { "server-file", required_argument, NULL, 'f' },
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
148 { "display", required_argument, NULL, 'd' },
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
149 { 0, 0, 0, 0 }
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
150 };
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
151
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
152 /* Message functions. */
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
153
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
154 #ifdef WINDOWSNT
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
155 /* I first tried to check for STDOUT. The check did not work,
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
156 I get a valid handle also in nonconsole apps.
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
157 Instead I test for console title, which seems to work. */
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
158 int
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
159 w32_window_app()
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
160 {
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
161 static int window_app = -1;
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
162 char szTitle[MAX_PATH];
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
163
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
164 if (window_app < 0)
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
165 window_app = (GetConsoleTitleA (szTitle, MAX_PATH) == 0);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
166
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
167 return window_app;
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
168 }
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
169 #endif
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
170
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
171 void
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
172 message (int is_error, char *message, ...)
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
173 {
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
174 char msg [2048];
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
175 va_list args;
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
176
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
177 va_start (args, message);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
178 vsprintf (msg, message, args);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
179 va_end (args);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
180
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
181 #ifdef WINDOWSNT
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
182 if (w32_window_app ())
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
183 {
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
184 if (is_error)
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
185 MessageBox (NULL, msg, "Emacsclient ERROR", MB_ICONERROR);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
186 else
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
187 MessageBox (NULL, msg, "Emacsclient", MB_ICONINFORMATION);
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
188 }
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
189 else
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
190 #endif
74341
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
191 {
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
192 FILE *f = is_error ? stderr : stdout;
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
193
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
194 fputs (msg, f);
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
195 fflush (f);
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
196 }
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
197 }
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
198
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
199 /* Decode the options from argv and argc.
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
200 The global variable `optind' will say how many arguments we used up. */
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
201
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
202 void
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
203 decode_options (argc, argv)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
204 int argc;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
205 char **argv;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
206 {
53813
ddc4b99f4f8c (decode_options): Fix handling of alternate editor.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53734
diff changeset
207 alternate_editor = getenv ("ALTERNATE_EDITOR");
ddc4b99f4f8c (decode_options): Fix handling of alternate editor.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53734
diff changeset
208
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
209 while (1)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
210 {
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
211 int opt = getopt_long (argc, argv,
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
212 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
213 "VHnea:s:f:d:",
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
214 #else
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
215 "VHnea:f:d:",
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
216 #endif
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
217 longopts, 0);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
218
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
219 if (opt == EOF)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
220 break;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
221
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
222 switch (opt)
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
223 {
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
224 case 0:
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
225 /* If getopt returns 0, then it has already processed a
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
226 long-named option. We should do nothing. */
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
227 break;
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
228
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
229 case 'a':
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
230 alternate_editor = optarg;
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
231 break;
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
232
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
233 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
234 case 's':
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
235 socket_name = optarg;
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
236 break;
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
237 #endif
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
238
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
239 case 'f':
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
240 server_file = optarg;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
241 break;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
242
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
243 case 'd':
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
244 display = optarg;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
245 break;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
246
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
247 case 'n':
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
248 nowait = 1;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
249 break;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
250
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
251 case 'e':
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
252 eval = 1;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
253 break;
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
254
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
255 case 'V':
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
256 message (FALSE, "emacsclient %s\n", VERSION);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
257 exit (EXIT_SUCCESS);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
258 break;
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
259
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
260 case 'H':
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
261 print_help_and_exit ();
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
262 break;
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
263
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
264 default:
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
265 message (TRUE, "Try `%s --help' for more information\n", progname);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
266 exit (EXIT_FAILURE);
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
267 break;
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
268 }
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
269 }
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
270 }
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
271
21387
4812cf228971 Include <stdlib.h> and <unistd.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 19582
diff changeset
272 void
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
273 print_help_and_exit ()
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
274 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
275 message (FALSE,
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
276 "Usage: %s [OPTIONS] FILE...\n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
277 Tell the Emacs server to visit the specified files.\n\
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
278 Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.\n\
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
279 \n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
280 The following OPTIONS are accepted:\n\
74127
46dc2e041725 (print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents: 74118
diff changeset
281 \n\
46dc2e041725 (print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents: 74118
diff changeset
282 -V, --version Just print version info and return\n\
46dc2e041725 (print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents: 74118
diff changeset
283 -H, --help Print this usage information message\n\
46dc2e041725 (print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents: 74118
diff changeset
284 -e, --eval Evaluate FILE arguments as Lisp expressions\n\
46dc2e041725 (print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents: 74118
diff changeset
285 -n, --no-wait Don't wait for the server to return\n\
46dc2e041725 (print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents: 74118
diff changeset
286 -d, --display=DISPLAY Visit the file in the given display\n"
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
287 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
288 "-s, --socket-name=FILENAME\n\
74127
46dc2e041725 (print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents: 74118
diff changeset
289 Set filename of the UNIX socket for communication\n"
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
290 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
291 "-f, --server-file=FILENAME\n\
74127
46dc2e041725 (print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents: 74118
diff changeset
292 Set filename of the TCP authentication file\n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
293 -a, --alternate-editor=EDITOR\n\
74127
46dc2e041725 (print_help_and_exit): Tweak message contents and tabs/spaces
Juanma Barranquero <lekktu@gmail.com>
parents: 74118
diff changeset
294 Editor to fallback to if server is not running\n\
50101
e5f56d47b52c (print_help_and_exit): Print to stdout. Exit successfully. Added some blank
Juanma Barranquero <lekktu@gmail.com>
parents: 48627
diff changeset
295 \n\
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
296 Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
297 exit (EXIT_SUCCESS);
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
298 }
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
299
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
300
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
301 /*
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
302 Try to run a different command, or --if no alternate editor is
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
303 defined-- exit with an errorcode.
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
304 */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
305 void
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
306 fail (argc, argv)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
307 int argc;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
308 char **argv;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
309 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
310 if (alternate_editor)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
311 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
312 int i = optind - 1;
73601
e243e9889b8b [WINDOWSNT]: Force the first argv passed to execvp to point to alternate_editor
Juanma Barranquero <lekktu@gmail.com>
parents: 73585
diff changeset
313 #ifdef WINDOWSNT
e243e9889b8b [WINDOWSNT]: Force the first argv passed to execvp to point to alternate_editor
Juanma Barranquero <lekktu@gmail.com>
parents: 73585
diff changeset
314 argv[i] = (char *)alternate_editor;
e243e9889b8b [WINDOWSNT]: Force the first argv passed to execvp to point to alternate_editor
Juanma Barranquero <lekktu@gmail.com>
parents: 73585
diff changeset
315 #endif
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
316 execvp (alternate_editor, argv + i);
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
317 message (TRUE, "%s: error executing alternate editor \"%s\"\n",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
318 progname, alternate_editor);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
319 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
320 exit (EXIT_FAILURE);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
321 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
322
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
323
73617
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
324 #if !defined (HAVE_SOCKETS) || !defined (HAVE_INET_SOCKETS)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
325
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
326 int
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
327 main (argc, argv)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
328 int argc;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
329 char **argv;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
330 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
331 message (TRUE, "%s: Sorry, the Emacs server is supported only\non systems with Berkely sockets.\n",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
332 argv[0]);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
333
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
334 fail (argc, argv);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
335 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
336
73617
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
337 #else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
338
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
339 #ifdef WINDOWSNT
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
340 # include <winsock2.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
341 #else
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
342 # include <sys/types.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
343 # include <sys/socket.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
344 # include <sys/un.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
345 # include <sys/stat.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
346 # include <errno.h>
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
347 #endif
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
348
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
349 #define AUTH_KEY_LENGTH 64
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
350 #define SEND_BUFFER_SIZE 4096
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
351
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
352 extern char *strerror ();
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
353 extern int errno;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
354
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
355 /* Buffer to accumulate data to send in TCP connections. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
356 char send_buffer[SEND_BUFFER_SIZE + 1];
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
357 int sblen = 0; /* Fill pointer for the send buffer. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
358
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
359 /* Let's send the data to Emacs when either
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
360 - the data ends in "\n", or
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
361 - the buffer is full (but this shouldn't happen)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
362 Otherwise, we just accumulate it. */
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
363 void
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
364 send_to_emacs (s, data)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
365 HSOCKET s;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
366 char *data;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
367 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
368 while (data)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
369 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
370 int dlen = strlen (data);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
371 if (dlen + sblen >= SEND_BUFFER_SIZE)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
372 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
373 int part = SEND_BUFFER_SIZE - sblen;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
374 strncpy (&send_buffer[sblen], data, part);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
375 data += part;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
376 sblen = SEND_BUFFER_SIZE;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
377 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
378 else if (dlen)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
379 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
380 strcpy (&send_buffer[sblen], data);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
381 data = NULL;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
382 sblen += dlen;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
383 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
384 else
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
385 break;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
386
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
387 if (sblen == SEND_BUFFER_SIZE
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
388 || (sblen > 0 && send_buffer[sblen-1] == '\n'))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
389 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
390 int sent = send (s, send_buffer, sblen, 0);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
391 if (sent != sblen)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
392 strcpy (send_buffer, &send_buffer[sent]);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
393 sblen -= sent;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
394 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
395 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
396 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
397
52848
5c74e66d6c36 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 52635
diff changeset
398 /* In NAME, insert a & before each &, each space, each newline, and
5c74e66d6c36 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 52635
diff changeset
399 any initial -. Change spaces to underscores, too, so that the
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
400 return value never contains a space. */
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
401 void
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
402 quote_file_name (s, name)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
403 HSOCKET s;
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
404 char *name;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
405 {
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
406 char *copy = (char *) malloc (strlen (name) * 2 + 1);
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
407 char *p, *q;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
408
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
409 p = name;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
410 q = copy;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
411 while (*p)
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
412 {
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
413 if (*p == ' ')
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
414 {
16074
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
415 *q++ = '&';
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
416 *q++ = '_';
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
417 p++;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
418 }
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
419 else if (*p == '\n')
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
420 {
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
421 *q++ = '&';
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
422 *q++ = 'n';
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
423 p++;
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
424 }
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
425 else
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
426 {
16074
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
427 if (*p == '&' || (*p == '-' && p == name))
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
428 *q++ = '&';
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
429 *q++ = *p++;
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
430 }
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
431 }
16074
25cfff7ffced (quote_file_name): Quote with &, not \.
Richard M. Stallman <rms@gnu.org>
parents: 16061
diff changeset
432 *q++ = 0;
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
433
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
434 SEND_STRING (copy);
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
435
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
436 free (copy);
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
437 }
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
438
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
439 int
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
440 file_name_absolute_p (filename)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
441 const unsigned char *filename;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
442 {
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
443 /* Sanity check, it shouldn't happen. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
444 if (! filename) return FALSE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
445
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
446 /* /xxx is always an absolute path. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
447 if (filename[0] == '/') return TRUE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
448
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
449 /* Empty filenames (which shouldn't happen) are relative. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
450 if (filename[0] == '\0') return FALSE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
451
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
452 #ifdef WINDOWSNT
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
453 /* X:\xxx is always absolute; X:xxx is an error and will fail. */
74176
6eee550d3bda (file_name_absolute_p) [WINDOWSNT]: Use isalpha().
Jason Rumney <jasonr@gnu.org>
parents: 74172
diff changeset
454 if (isalpha (filename[0])
74172
cbda0982f77c (file_name_absolute_p) [WINDOWSNT]: Support absolute file names with forward
Eli Zaretskii <eliz@gnu.org>
parents: 74145
diff changeset
455 && filename[1] == ':' && (filename[2] == '\\' || filename[2] == '/'))
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
456 return TRUE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
457
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
458 /* Both \xxx and \\xxx\yyy are absolute. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
459 if (filename[0] == '\\') return TRUE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
460 #endif
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
461
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
462 return FALSE;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
463 }
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
464
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
465 #ifdef WINDOWSNT
74145
8eceefbbcde7 Space/tab mixup.
Juanma Barranquero <lekktu@gmail.com>
parents: 74127
diff changeset
466 /* Wrapper to make WSACleanup a cdecl, as required by atexit(). */
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
467 void
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
468 __cdecl close_winsock ()
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
469 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
470 WSACleanup ();
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
471 }
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
472
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
473 /* Initialize the WinSock2 library. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
474 void
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
475 initialize_sockets ()
18701
9c7e0c926ed5 [C_ALLOCA] (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16218
diff changeset
476 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
477 WSADATA wsaData;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
478
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
479 if (WSAStartup (MAKEWORD (2, 0), &wsaData))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
480 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
481 message (TRUE, "%s: error initializing WinSock2", progname);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
482 exit (EXIT_FAILURE);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
483 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
484
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
485 atexit (close_winsock);
73578
e193b6a3f379 Fixes to emacsclient.c for GNU/Linux.
Juanma Barranquero <lekktu@gmail.com>
parents: 73562
diff changeset
486 }
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
487 #endif /* WINDOWSNT */
16030
fb38057473c8 (decode_options): New function.
Richard M. Stallman <rms@gnu.org>
parents: 15995
diff changeset
488
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
489 /*
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
490 * Read the information needed to set up a TCP comm channel with
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
491 * the Emacs server: host, port, pid and authentication string.
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
492 */
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
493 int
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
494 get_server_config (server, authentication)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
495 struct sockaddr_in *server;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
496 char *authentication;
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
497 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
498 char dotted[32];
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
499 char *port;
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
500 char *pid;
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
501 FILE *config = NULL;
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
502
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
503 if (file_name_absolute_p (server_file))
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
504 config = fopen (server_file, "rb");
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
505 else
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
506 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
507 char *home = getenv ("HOME");
73809
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
508
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
509 if (home)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
510 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
511 char *path = alloca (32 + strlen (home) + strlen (server_file));
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
512 sprintf (path, "%s/.emacs.d/server/%s", home, server_file);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
513 config = fopen (path, "rb");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
514 }
73809
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
515 #ifdef WINDOWSNT
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
516 if (!config && (home = getenv ("APPDATA")))
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
517 {
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
518 char *path = alloca (32 + strlen (home) + strlen (server_file));
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
519 sprintf (path, "%s/.emacs.d/server/%s", home, server_file);
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
520 config = fopen (path, "rb");
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
521 }
cbc1f46b6590 (get_server_config) [WINDOWSNT]: Search the server file on APPDATA
Juanma Barranquero <lekktu@gmail.com>
parents: 73806
diff changeset
522 #endif
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
523 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
524
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
525 if (! config)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
526 return FALSE;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
527
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
528 if (fgets (dotted, sizeof dotted, config)
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
529 && (port = strchr (dotted, ':'))
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
530 && (pid = strchr (port, ' ')))
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
531 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
532 *port++ = '\0';
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
533 *pid++ = '\0';
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
534 }
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
535 else
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
536 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
537 message (TRUE, "%s: invalid configuration info", progname);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
538 exit (EXIT_FAILURE);
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
539 }
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
540
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
541 server->sin_family = AF_INET;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
542 server->sin_addr.s_addr = inet_addr (dotted);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
543 server->sin_port = htons (atoi (port));
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
544
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
545 if (! fread (authentication, AUTH_KEY_LENGTH, 1, config))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
546 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
547 message (TRUE, "%s: cannot read authentication info", progname);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
548 exit (EXIT_FAILURE);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
549 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
550
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
551 fclose (config);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
552
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
553 emacs_pid = atoi (pid);
73806
fbfa7d8c0a64 (get_server_config): Extract also the Emacs pid from the server file.
Juanma Barranquero <lekktu@gmail.com>
parents: 73765
diff changeset
554
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
555 return TRUE;
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
556 }
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
557
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
558 HSOCKET
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
559 set_tcp_socket ()
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
560 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
561 HSOCKET s;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
562 struct sockaddr_in server;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
563 struct linger l_arg = {1, 1};
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
564 char auth_string[AUTH_KEY_LENGTH + 1];
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
565
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
566 if (! get_server_config (&server, auth_string))
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
567 return INVALID_SOCKET;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
568
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
569 if (server.sin_addr.s_addr != inet_addr ("127.0.0.1"))
74341
32079f79e240 (message): Make sure the message is properly written even if it contains printf
Juanma Barranquero <lekktu@gmail.com>
parents: 74176
diff changeset
570 message (FALSE, "%s: connected to remote socket at %s\n",
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
571 progname, inet_ntoa (server.sin_addr));
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
572
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
573 /*
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
574 * Open up an AF_INET socket
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
575 */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
576 if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
577 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
578 message (TRUE, "%s: socket: %s\n", progname, strerror (errno));
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
579 return INVALID_SOCKET;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
580 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
582 /*
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
583 * Set up the socket
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
584 */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
585 if (connect (s, (struct sockaddr *) &server, sizeof server) < 0)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
586 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
587 message (TRUE, "%s: connect: %s\n", progname, strerror (errno));
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
588 return INVALID_SOCKET;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
589 }
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
590
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
591 setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
592
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
593 /*
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
594 * Send the authentication
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
595 */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
596 auth_string[AUTH_KEY_LENGTH] = '\0';
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
597
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
598 SEND_STRING ("-auth ");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
599 SEND_STRING (auth_string);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
600 SEND_STRING ("\n");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
601
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
602 return s;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
605 #if !defined (NO_SOCKETS_IN_FILE_SYSTEM)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
607 /* Three possibilities:
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
608 2 - can't be `stat'ed (sets errno)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
609 1 - isn't owned by us
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
610 0 - success: none of the above */
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
611
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
612 static int
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
613 socket_status (socket_name)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
614 char *socket_name;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
615 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
616 struct stat statbfr;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
617
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
618 if (stat (socket_name, &statbfr) == -1)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
619 return 2;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
620
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
621 if (statbfr.st_uid != geteuid ())
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
622 return 1;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
623
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
624 return 0;
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
625 }
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
626
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
627 HSOCKET
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
628 set_local_socket ()
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
630 HSOCKET s;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 struct sockaddr_un server;
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
633 /*
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 * Open up an AF_UNIX socket in this person's home directory
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 */
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
639 message (TRUE, "%s: socket: %s\n", progname, strerror (errno));
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
640 return INVALID_SOCKET;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 }
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
642
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 server.sun_family = AF_UNIX;
25261
89be69860eeb (main): Move the dynamic allocation of
Karl Heuer <kwzh@gnu.org>
parents: 24652
diff changeset
644
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
645 {
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
646 int sock_status = 0;
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
647 int default_sock = !socket_name;
53543
fec82b542db2 (main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents: 53497
diff changeset
648 int saved_errno;
53734
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
649 char *server_name = "server";
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
650
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
651 if (socket_name && !index (socket_name, '/') && !index (socket_name, '\\'))
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
652 { /* socket_name is a file name component. */
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
653 server_name = socket_name;
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
654 socket_name = NULL;
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
655 default_sock = 1; /* Try both UIDs. */
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
656 }
24084
c0b0893dd5a6 (main): Eliminate arbitrary limit on length of system_name.
Richard M. Stallman <rms@gnu.org>
parents: 23412
diff changeset
657
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
658 if (default_sock)
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
659 {
53734
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
660 socket_name = alloca (100 + strlen (server_name));
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
661 sprintf (socket_name, "/tmp/emacs%d/%s",
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
662 (int) geteuid (), server_name);
52479
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
663 }
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
664
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
665 if (strlen (socket_name) < sizeof (server.sun_path))
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
666 strcpy (server.sun_path, socket_name);
bc2610a13fbf (socket_name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
667 else
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
668 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
669 message (TRUE, "%s: socket-name %s too long",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
670 progname, socket_name);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
671 exit (EXIT_FAILURE);
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
672 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
674 /* See if the socket exists, and if it's owned by us. */
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
675 sock_status = socket_status (server.sun_path);
53543
fec82b542db2 (main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents: 53497
diff changeset
676 saved_errno = errno;
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
677 if (sock_status && default_sock)
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
678 {
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
679 /* Failing that, see if LOGNAME or USER exist and differ from
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
680 our euid. If so, look for a socket based on the UID
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
681 associated with the name. This is reminiscent of the logic
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
682 that init_editfns uses to set the global Vuser_full_name. */
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
683
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
684 char *user_name = (char *) getenv ("LOGNAME");
53693
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
685
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
686 if (!user_name)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
687 user_name = (char *) getenv ("USER");
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
688
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
689 if (user_name)
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
690 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
691 struct passwd *pw = getpwnam (user_name);
53693
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
692
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
693 if (pw && (pw->pw_uid != geteuid ()))
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
694 {
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
695 /* We're running under su, apparently. */
53734
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
696 socket_name = alloca (100 + strlen (server_name));
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
697 sprintf (socket_name, "/tmp/emacs%d/%s",
132739917566 (main): Don't use the hostname in the socket name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53693
diff changeset
698 (int) pw->pw_uid, server_name);
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
699
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
700 if (strlen (socket_name) < sizeof (server.sun_path))
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
701 strcpy (server.sun_path, socket_name);
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
702 else
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
703 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
704 message (TRUE, "%s: socket-name %s too long",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
705 progname, socket_name);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
706 exit (EXIT_FAILURE);
53646
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
707 }
8c55b1b400d5 (main): Stop if socket name too long.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53543
diff changeset
708
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
709 sock_status = socket_status (server.sun_path);
53543
fec82b542db2 (main): Save errno from socket_status.
Andreas Schwab <schwab@suse.de>
parents: 53497
diff changeset
710 saved_errno = errno;
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
711 }
53693
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
712 else
04e9ebd16fcd (main): Restore errno from saved_errno,
Richard M. Stallman <rms@gnu.org>
parents: 53646
diff changeset
713 errno = saved_errno;
27474
ed3668c0295a (socket_status): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27305
diff changeset
714 }
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
715 }
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
716
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
717 switch (sock_status)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
718 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
719 case 1:
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
720 /* There's a socket, but it isn't owned by us. This is OK if
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
721 we are root. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
722 if (0 != geteuid ())
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
723 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
724 message (TRUE, "%s: Invalid socket owner\n", progname);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
725 return INVALID_SOCKET;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
726 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
727 break;
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
728
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
729 case 2:
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
730 /* `stat' failed */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
731 if (saved_errno == ENOENT)
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
732 message (TRUE,
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
733 "%s: can't find socket; have you started the server?\n\
48627
c91408365d35 (main): Tell user how to start server within Emacs if socket could not
Stephen Eglen <stephen@gnu.org>
parents: 48617
diff changeset
734 To start the server in Emacs, type \"M-x server-start\".\n",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
735 progname);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
736 else
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
737 message (TRUE, "%s: can't stat %s: %s\n",
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
738 progname, server.sun_path, strerror (saved_errno));
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
739 return INVALID_SOCKET;
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
740 }
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 478
diff changeset
741 }
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742
3595
e10f7473d2e3 * emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents: 1031
diff changeset
743 if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2)
e10f7473d2e3 * emacsserver.c (main): When we're passing a `struct sockaddr_un'
Jim Blandy <jimb@redhat.com>
parents: 1031
diff changeset
744 < 0)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
746 message (TRUE, "%s: connect: %s\n", progname, strerror (errno));
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
747 return INVALID_SOCKET;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 }
15758
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
749
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
750 return s;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
751 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
752 #endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
753
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
754 HSOCKET
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
755 set_socket ()
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
756 {
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
757 HSOCKET s;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
758
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
759 INITIALIZE ();
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
760
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
761 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
762 /* Explicit --socket-name argument. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
763 if (socket_name)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 {
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
765 s = set_local_socket ();
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
766 if ((s != INVALID_SOCKET) || alternate_editor)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
767 return s;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
768
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
769 message (TRUE, "%s: error accessing socket \"%s\"",
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
770 progname, socket_name);
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
771 exit (EXIT_FAILURE);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
772 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
773 #endif
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
774
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
775 /* Explicit --server-file arg or EMACS_SERVER_FILE variable. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
776 if (!server_file)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
777 server_file = getenv ("EMACS_SERVER_FILE");
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
778
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
779 if (server_file)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
780 {
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
781 s = set_tcp_socket ();
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
782 if ((s != INVALID_SOCKET) || alternate_editor)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
783 return s;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
784
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
785 message (TRUE, "%s: error accessing server file \"%s\"",
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
786 progname, server_file);
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
787 exit (EXIT_FAILURE);
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
788 }
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
789
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
790 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
791 /* Implicit local socket. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
792 s = set_local_socket ();
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
793 if (s != INVALID_SOCKET)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
794 return s;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
795 #endif
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
796
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
797 /* Implicit server file. */
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
798 server_file = "server";
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
799 s = set_tcp_socket ();
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
800 if ((s != INVALID_SOCKET) || alternate_editor)
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
801 return s;
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
802
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
803 /* No implicit or explicit socket, and no alternate editor. */
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
804 message (TRUE, "%s: No socket or alternate editor. Please use:\n\n"
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
805 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
806 "\t--socket-name\n"
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
807 #endif
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
808 "\t--server-file (or environment variable EMACS_SERVER_FILE)\n\
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
809 \t--alternate-editor (or environment variable ALTERNATE_EDITOR)\n",
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
810 progname);
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
811 exit (EXIT_FAILURE);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
812 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
813
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
814 int
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
815 main (argc, argv)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
816 int argc;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
817 char **argv;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
818 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
819 HSOCKET s;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
820 int i, rl, needlf = 0;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
821 char *cwd;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
822 char string[BUFSIZ+1];
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
823
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
824 progname = argv[0];
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
825
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
826 /* Process options. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
827 decode_options (argc, argv);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
828
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
829 if ((argc - optind < 1) && !eval)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
830 {
74118
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
831 message (TRUE, "%s: file name or argument required\nTry `%s --help' for more information\n",
bee73d83d967 Include <stdarg.h>.
Juanma Barranquero <lekktu@gmail.com>
parents: 73978
diff changeset
832 progname, progname);
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
833 exit (EXIT_FAILURE);
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
836 if ((s = set_socket ()) == INVALID_SOCKET)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
837 fail (argc, argv);
15758
7e712d42d371 (main) [HAVE_SOCKETS]: Use two separate stdio
Richard M. Stallman <rms@gnu.org>
parents: 14610
diff changeset
838
48617
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
839 #ifdef HAVE_GETCWD
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
840 cwd = getcwd (string, sizeof string);
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
841 #else
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
842 cwd = getwd (string);
11030
3345f6426f49 Use BSD sockets whenever available, even if HAVE_SYSVIPC.
Richard M. Stallman <rms@gnu.org>
parents: 10124
diff changeset
843 #endif
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
844 if (cwd == 0)
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
845 {
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
846 /* getwd puts message in STRING if it fails. */
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
847 message (TRUE, "%s: %s (%s)\n", progname,
48617
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
848 #ifdef HAVE_GETCWD
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
849 "Cannot get current working directory",
48617
802b2a15e451 (main): Test HAVE_GETCWD rather than BSD_SYSTEM.
Richard M. Stallman <rms@gnu.org>
parents: 47717
diff changeset
850 #else
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
851 string,
19582
1289a4779e68 [HAVE_SYSVIPC]: Include errno.h, as in the other case.
Richard M. Stallman <rms@gnu.org>
parents: 18701
diff changeset
852 #endif
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
853 strerror (errno));
27305
4161adef5fd3 Add option -a EDITOR and environment variable
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
854 fail (argc, argv);
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
855 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
856
74342
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
857 #ifdef WINDOWSNT
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
858 /*
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
859 Modern Windows restrict which processes can set the foreground window.
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
860 emacsclient can allow Emacs to grab the focus by calling the function
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
861 AllowSetForegroundWindow(). Unfortunately, older Windows (W95, W98
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
862 and NT) lack this function, so we have to check its availability.
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
863 */
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
864 if (emacs_pid)
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
865 {
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
866 HMODULE hUser32;
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
867
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
868 if (hUser32 = LoadLibrary ("user32.dll"))
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
869 {
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
870 FARPROC set_fg;
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
871 if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow"))
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
872 set_fg (emacs_pid);
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
873 FreeLibrary (hUser32);
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
874 }
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
875 }
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
876 #endif
c6cb776ffbb7 (emacs_pid): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents: 74341
diff changeset
877
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
878 if (nowait)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
879 SEND_STRING ("-nowait ");
16061
a1290c4159b5 (quote_file_name): New function.
Richard M. Stallman <rms@gnu.org>
parents: 16030
diff changeset
880
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
881 if (eval)
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
882 SEND_STRING ("-eval ");
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
883
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
884 if (display)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
885 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
886 SEND_STRING ("-display ");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
887 SEND_QUOTED (display);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
888 SEND_STRING (" ");
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
889 }
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
890
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
891 if ((argc - optind > 0))
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
892 {
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
893 for (i = optind; i < argc; i++)
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894 {
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
895 if (eval)
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
896 ; /* Don't prepend any cwd or anything like that. */
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
897 else if (*argv[i] == '+')
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
898 {
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
899 char *p = argv[i] + 1;
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
900 while (isdigit ((unsigned char) *p) || *p == ':') p++;
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
901 if (*p != 0)
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
902 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
903 SEND_QUOTED (cwd);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
904 SEND_STRING ("/");
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
905 }
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
906 }
73765
bcb5c0f9a466 (longopts) [! NO_SOCKETS_IN_FILE_SYSTEM]: Don't show option --socket-name.
Juanma Barranquero <lekktu@gmail.com>
parents: 73657
diff changeset
907 else if (! file_name_absolute_p (argv[i]))
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
908 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
909 SEND_QUOTED (cwd);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
910 SEND_STRING ("/");
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
911 }
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
912
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
913 SEND_QUOTED (argv[i]);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
914 SEND_STRING (" ");
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 }
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
917 else
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
918 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
919 while (fgets (string, BUFSIZ, stdin))
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
920 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
921 SEND_QUOTED (string);
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
922 }
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
923 SEND_STRING (" ");
52635
9963e9da5850 (quote_file_name): Print the result instead of
Eli Zaretskii <eliz@gnu.org>
parents: 52532
diff changeset
924 }
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
925
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
926 SEND_STRING ("\n");
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927
15995
7284f973fc42 (both versions): Handle -nowait and --nowait by sending data to the server.
Richard M. Stallman <rms@gnu.org>
parents: 15758
diff changeset
928 /* Maybe wait for an answer. */
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
929 if (!nowait)
47647
5498210ad40d Remove SYSV support.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47515
diff changeset
930 {
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
931 if (!eval)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
932 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
933 printf ("Waiting for Emacs...");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
934 needlf = 2;
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
935 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
936 fflush (stdout);
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
938 /* Now, wait for an answer and print any messages. */
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
939 while ((rl = recv (s, string, BUFSIZ, 0)) > 0)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
940 {
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
941 string[rl] = '\0';
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
942 if (needlf == 2)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
943 printf ("\n");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
944 printf ("%s", string);
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
945 needlf = string[0] == '\0' ? needlf : string[strlen (string) - 1] != '\n';
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
946 }
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
947
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
948 if (needlf)
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
949 printf ("\n");
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
950 fflush (stdout);
47515
6ee937dcfe16 (quote_file_name): Quote \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42412
diff changeset
951 }
42176
1f5dbeefa536 Include "config.h", not <../src/config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 39723
diff changeset
952
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
953 CLOSE_SOCKET (s);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
954 return EXIT_SUCCESS;
412
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955 }
3cc2c5136064 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
956
73617
7af864af10b6 [WINDOWSNT]: Define HAVE_INET_SOCKETS.
Juanma Barranquero <lekktu@gmail.com>
parents: 73601
diff changeset
957 #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */
73562
368665ce6f35 Add support for TCP sockets.
Juanma Barranquero <lekktu@gmail.com>
parents: 72005
diff changeset
958
5527
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
959 #ifndef HAVE_STRERROR
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
960 char *
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
961 strerror (errnum)
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
962 int errnum;
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
963 {
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
964 extern char *sys_errlist[];
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
965 extern int sys_nerr;
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
966
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
967 if (errnum >= 0 && errnum < sys_nerr)
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
968 return sys_errlist[errnum];
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
969 return (char *) "Unknown error";
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
970 }
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
971
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5522
diff changeset
972 #endif /* ! HAVE_STRERROR */
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
973
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
974 /* arch-tag: f39bb9c4-73eb-477e-896d-50832e2ca9a7
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52069
diff changeset
975 (do not change this comment) */
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
976
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53813
diff changeset
977 /* emacsclient.c ends here */