aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/emacsclient.c
diff options
context:
space:
mode:
authorJoakim Verona2011-06-16 00:22:07 +0200
committerJoakim Verona2011-06-16 00:22:07 +0200
commita7513ade3bc0fe79430d5541d88c9dcda0932bec (patch)
tree4383951ba698a11e9f8933a9d8c72e00aa872a10 /lib-src/emacsclient.c
parent4bd51ad5c3445b644dfb017d5b57b10a90aa325f (diff)
parent4bba86e6210a74326e843a8fdc8409127105e1fe (diff)
downloademacs-a7513ade3bc0fe79430d5541d88c9dcda0932bec.tar.gz
emacs-a7513ade3bc0fe79430d5541d88c9dcda0932bec.zip
merge from upstream
Diffstat (limited to 'lib-src/emacsclient.c')
-rw-r--r--lib-src/emacsclient.c198
1 files changed, 115 insertions, 83 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index e5484b987e2..c334fb6a196 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -112,6 +112,13 @@ char *(getcwd) (char *, size_t);
112/* Additional space when allocating buffers for filenames, etc. */ 112/* Additional space when allocating buffers for filenames, etc. */
113#define EXTRA_SPACE 100 113#define EXTRA_SPACE 100
114 114
115/* Use this to suppress gcc's `...may be used before initialized' warnings. */
116#ifdef lint
117# define IF_LINT(Code) Code
118#else
119# define IF_LINT(Code) /* empty */
120#endif
121
115 122
116/* Name used to invoke this program. */ 123/* Name used to invoke this program. */
117const char *progname; 124const char *progname;
@@ -122,6 +129,9 @@ char **main_argv;
122/* Nonzero means don't wait for a response from Emacs. --no-wait. */ 129/* Nonzero means don't wait for a response from Emacs. --no-wait. */
123int nowait = 0; 130int nowait = 0;
124 131
132/* Nonzero means don't print messages for successful operations. --quiet. */
133int quiet = 0;
134
125/* Nonzero means args are expressions to be evaluated. --eval. */ 135/* Nonzero means args are expressions to be evaluated. --eval. */
126int eval = 0; 136int eval = 0;
127 137
@@ -150,13 +160,14 @@ const char *server_file = NULL;
150/* PID of the Emacs server process. */ 160/* PID of the Emacs server process. */
151int emacs_pid = 0; 161int emacs_pid = 0;
152 162
153void print_help_and_exit (void) NO_RETURN; 163static void print_help_and_exit (void) NO_RETURN;
154void fail (void) NO_RETURN; 164static void fail (void) NO_RETURN;
155 165
156 166
157struct option longopts[] = 167struct option longopts[] =
158{ 168{
159 { "no-wait", no_argument, NULL, 'n' }, 169 { "no-wait", no_argument, NULL, 'n' },
170 { "quiet", no_argument, NULL, 'q' },
160 { "eval", no_argument, NULL, 'e' }, 171 { "eval", no_argument, NULL, 'e' },
161 { "help", no_argument, NULL, 'H' }, 172 { "help", no_argument, NULL, 'H' },
162 { "version", no_argument, NULL, 'V' }, 173 { "version", no_argument, NULL, 'V' },
@@ -178,7 +189,7 @@ struct option longopts[] =
178 189
179/* Like malloc but get fatal error if memory is exhausted. */ 190/* Like malloc but get fatal error if memory is exhausted. */
180 191
181long * 192static long *
182xmalloc (unsigned int size) 193xmalloc (unsigned int size)
183{ 194{
184 long *result = (long *) malloc (size); 195 long *result = (long *) malloc (size);
@@ -190,20 +201,6 @@ xmalloc (unsigned int size)
190 return result; 201 return result;
191} 202}
192 203
193/* Like strdup but get a fatal error if memory is exhausted. */
194
195char *
196xstrdup (const char *s)
197{
198 char *result = strdup (s);
199 if (result == NULL)
200 {
201 perror ("strdup");
202 exit (EXIT_FAILURE);
203 }
204 return result;
205}
206
207/* From sysdep.c */ 204/* From sysdep.c */
208#if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME) 205#if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
209 206
@@ -221,10 +218,8 @@ xstrdup (const char *s)
221#define IS_DEVICE_SEP(_c_) ((_c_) == DEVICE_SEP) 218#define IS_DEVICE_SEP(_c_) ((_c_) == DEVICE_SEP)
222#endif 219#endif
223#endif 220#endif
224#ifndef IS_ANY_SEP
225#define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_))
226#endif
227 221
222char *get_current_dir_name (void);
228 223
229/* Return the current working directory. Returns NULL on errors. 224/* Return the current working directory. Returns NULL on errors.
230 Any other returned value must be freed with free. This is used 225 Any other returned value must be freed with free. This is used
@@ -233,7 +228,7 @@ char*
233get_current_dir_name (void) 228get_current_dir_name (void)
234{ 229{
235 char *buf; 230 char *buf;
236 char *pwd; 231 const char *pwd;
237 struct stat dotstat, pwdstat; 232 struct stat dotstat, pwdstat;
238 /* If PWD is accurate, use it instead of calling getwd. PWD is 233 /* If PWD is accurate, use it instead of calling getwd. PWD is
239 sometimes a nicer name, and using it may avoid a fatal error if a 234 sometimes a nicer name, and using it may avoid a fatal error if a
@@ -300,6 +295,20 @@ get_current_dir_name (void)
300 295
301#ifdef WINDOWSNT 296#ifdef WINDOWSNT
302 297
298/* Like strdup but get a fatal error if memory is exhausted. */
299
300char *
301xstrdup (const char *s)
302{
303 char *result = strdup (s);
304 if (result == NULL)
305 {
306 perror ("strdup");
307 exit (EXIT_FAILURE);
308 }
309 return result;
310}
311
303#define REG_ROOT "SOFTWARE\\GNU\\Emacs" 312#define REG_ROOT "SOFTWARE\\GNU\\Emacs"
304 313
305/* Retrieve an environment variable from the Emacs subkeys of the registry. 314/* Retrieve an environment variable from the Emacs subkeys of the registry.
@@ -335,9 +344,11 @@ w32_get_resource (HKEY predefined, char *key, LPDWORD type)
335/* 344/*
336 getenv wrapper for Windows 345 getenv wrapper for Windows
337 346
338 This is needed to duplicate Emacs's behavior, which is to look for environment 347 Value is allocated on the heap, and can be free'd.
339 variables in the registry if they don't appear in the environment. 348
340*/ 349 This is needed to duplicate Emacs's behavior, which is to look for
350 environment variables in the registry if they don't appear in the
351 environment. */
341char * 352char *
342w32_getenv (char *envvar) 353w32_getenv (char *envvar)
343{ 354{
@@ -345,8 +356,9 @@ w32_getenv (char *envvar)
345 DWORD dwType; 356 DWORD dwType;
346 357
347 if (value = getenv (envvar)) 358 if (value = getenv (envvar))
348 /* Found in the environment. */ 359 /* Found in the environment. strdup it, because values returned
349 return value; 360 by getenv cannot be free'd. */
361 return xstrdup (value);
350 362
351 if (! (value = w32_get_resource (HKEY_CURRENT_USER, envvar, &dwType)) && 363 if (! (value = w32_get_resource (HKEY_CURRENT_USER, envvar, &dwType)) &&
352 ! (value = w32_get_resource (HKEY_LOCAL_MACHINE, envvar, &dwType))) 364 ! (value = w32_get_resource (HKEY_LOCAL_MACHINE, envvar, &dwType)))
@@ -473,14 +485,15 @@ ttyname (int fd)
473 485
474/* Display a normal or error message. 486/* Display a normal or error message.
475 On Windows, use a message box if compiled as a Windows app. */ 487 On Windows, use a message box if compiled as a Windows app. */
476void 488static void message (int, const char *, ...) ATTRIBUTE_FORMAT_PRINTF (2, 3);
477message (int is_error, const char *message, ...) 489static void
490message (int is_error, const char *format, ...)
478{ 491{
479 char msg[2048]; 492 char msg[2048];
480 va_list args; 493 va_list args;
481 494
482 va_start (args, message); 495 va_start (args, format);
483 vsprintf (msg, message, args); 496 vsprintf (msg, format, args);
484 va_end (args); 497 va_end (args);
485 498
486#ifdef WINDOWSNT 499#ifdef WINDOWSNT
@@ -504,7 +517,7 @@ message (int is_error, const char *message, ...)
504/* Decode the options from argv and argc. 517/* Decode the options from argv and argc.
505 The global variable `optind' will say how many arguments we used up. */ 518 The global variable `optind' will say how many arguments we used up. */
506 519
507void 520static void
508decode_options (int argc, char **argv) 521decode_options (int argc, char **argv)
509{ 522{
510 alternate_editor = egetenv ("ALTERNATE_EDITOR"); 523 alternate_editor = egetenv ("ALTERNATE_EDITOR");
@@ -513,9 +526,9 @@ decode_options (int argc, char **argv)
513 { 526 {
514 int opt = getopt_long_only (argc, argv, 527 int opt = getopt_long_only (argc, argv,
515#ifndef NO_SOCKETS_IN_FILE_SYSTEM 528#ifndef NO_SOCKETS_IN_FILE_SYSTEM
516 "VHnea:s:f:d:tc", 529 "VHneqa:s:f:d:tc",
517#else 530#else
518 "VHnea:f:d:tc", 531 "VHneqa:f:d:tc",
519#endif 532#endif
520 longopts, 0); 533 longopts, 0);
521 534
@@ -559,6 +572,10 @@ decode_options (int argc, char **argv)
559 eval = 1; 572 eval = 1;
560 break; 573 break;
561 574
575 case 'q':
576 quiet = 1;
577 break;
578
562 case 'V': 579 case 'V':
563 message (FALSE, "emacsclient %s\n", VERSION); 580 message (FALSE, "emacsclient %s\n", VERSION);
564 exit (EXIT_SUCCESS); 581 exit (EXIT_SUCCESS);
@@ -630,7 +647,7 @@ an empty string");
630} 647}
631 648
632 649
633void 650static void
634print_help_and_exit (void) 651print_help_and_exit (void)
635{ 652{
636 /* Spaces and tabs are significant in this message; they're chosen so the 653 /* Spaces and tabs are significant in this message; they're chosen so the
@@ -650,6 +667,7 @@ The following OPTIONS are accepted:\n\
650 use the current Emacs frame\n\ 667 use the current Emacs frame\n\
651-e, --eval Evaluate the FILE arguments as ELisp expressions\n\ 668-e, --eval Evaluate the FILE arguments as ELisp expressions\n\
652-n, --no-wait Don't wait for the server to return\n\ 669-n, --no-wait Don't wait for the server to return\n\
670-q, --quiet Don't display messages on success\n\
653-d DISPLAY, --display=DISPLAY\n\ 671-d DISPLAY, --display=DISPLAY\n\
654 Visit the file in the given display\n\ 672 Visit the file in the given display\n\
655--parent-id=ID Open in parent window ID, via XEmbed\n" 673--parent-id=ID Open in parent window ID, via XEmbed\n"
@@ -675,7 +693,7 @@ Report bugs with M-x report-emacs-bug.\n", progname);
675 defined-- exit with an errorcode. 693 defined-- exit with an errorcode.
676 Uses argv, but gets it from the global variable main_argv. 694 Uses argv, but gets it from the global variable main_argv.
677*/ 695*/
678void 696static void
679fail (void) 697fail (void)
680{ 698{
681 if (alternate_editor) 699 if (alternate_editor)
@@ -718,7 +736,7 @@ HSOCKET emacs_socket = 0;
718 736
719/* On Windows, the socket library was historically separate from the standard 737/* On Windows, the socket library was historically separate from the standard
720 C library, so errors are handled differently. */ 738 C library, so errors are handled differently. */
721void 739static void
722sock_err_message (const char *function_name) 740sock_err_message (const char *function_name)
723{ 741{
724#ifdef WINDOWSNT 742#ifdef WINDOWSNT
@@ -742,7 +760,7 @@ sock_err_message (const char *function_name)
742 - the data ends in "\n", or 760 - the data ends in "\n", or
743 - the buffer is full (but this shouldn't happen) 761 - the buffer is full (but this shouldn't happen)
744 Otherwise, we just accumulate it. */ 762 Otherwise, we just accumulate it. */
745void 763static void
746send_to_emacs (HSOCKET s, const char *data) 764send_to_emacs (HSOCKET s, const char *data)
747{ 765{
748 while (data) 766 while (data)
@@ -781,7 +799,7 @@ send_to_emacs (HSOCKET s, const char *data)
781 return value never contains a space. 799 return value never contains a space.
782 800
783 Does not change the string. Outputs the result to S. */ 801 Does not change the string. Outputs the result to S. */
784void 802static void
785quote_argument (HSOCKET s, const char *str) 803quote_argument (HSOCKET s, const char *str)
786{ 804{
787 char *copy = (char *) xmalloc (strlen (str) * 2 + 1); 805 char *copy = (char *) xmalloc (strlen (str) * 2 + 1);
@@ -822,7 +840,7 @@ quote_argument (HSOCKET s, const char *str)
822/* The inverse of quote_argument. Removes quoting in string STR by 840/* The inverse of quote_argument. Removes quoting in string STR by
823 modifying the string in place. Returns STR. */ 841 modifying the string in place. Returns STR. */
824 842
825char * 843static char *
826unquote_argument (char *str) 844unquote_argument (char *str)
827{ 845{
828 char *p, *q; 846 char *p, *q;
@@ -853,7 +871,7 @@ unquote_argument (char *str)
853} 871}
854 872
855 873
856int 874static int
857file_name_absolute_p (const char *filename) 875file_name_absolute_p (const char *filename)
858{ 876{
859 /* Sanity check, it shouldn't happen. */ 877 /* Sanity check, it shouldn't happen. */
@@ -907,7 +925,7 @@ initialize_sockets (void)
907 * Read the information needed to set up a TCP comm channel with 925 * Read the information needed to set up a TCP comm channel with
908 * the Emacs server: host, port, and authentication string. 926 * the Emacs server: host, port, and authentication string.
909 */ 927 */
910int 928static int
911get_server_config (struct sockaddr_in *server, char *authentication) 929get_server_config (struct sockaddr_in *server, char *authentication)
912{ 930{
913 char dotted[32]; 931 char dotted[32];
@@ -918,7 +936,7 @@ get_server_config (struct sockaddr_in *server, char *authentication)
918 config = fopen (server_file, "rb"); 936 config = fopen (server_file, "rb");
919 else 937 else
920 { 938 {
921 char *home = egetenv ("HOME"); 939 const char *home = egetenv ("HOME");
922 940
923 if (home) 941 if (home)
924 { 942 {
@@ -965,7 +983,7 @@ get_server_config (struct sockaddr_in *server, char *authentication)
965 return TRUE; 983 return TRUE;
966} 984}
967 985
968HSOCKET 986static HSOCKET
969set_tcp_socket (void) 987set_tcp_socket (void)
970{ 988{
971 HSOCKET s; 989 HSOCKET s;
@@ -976,7 +994,7 @@ set_tcp_socket (void)
976 if (! get_server_config (&server, auth_string)) 994 if (! get_server_config (&server, auth_string))
977 return INVALID_SOCKET; 995 return INVALID_SOCKET;
978 996
979 if (server.sin_addr.s_addr != inet_addr ("127.0.0.1")) 997 if (server.sin_addr.s_addr != inet_addr ("127.0.0.1") && !quiet)
980 message (FALSE, "%s: connected to remote socket at %s\n", 998 message (FALSE, "%s: connected to remote socket at %s\n",
981 progname, inet_ntoa (server.sin_addr)); 999 progname, inet_ntoa (server.sin_addr));
982 1000
@@ -1024,11 +1042,11 @@ strprefix (const char *prefix, const char *string)
1024 and the name in TTY_NAME, and return 1. Otherwise, fail if NOABORT 1042 and the name in TTY_NAME, and return 1. Otherwise, fail if NOABORT
1025 is zero, or return 0 if NOABORT is non-zero. */ 1043 is zero, or return 0 if NOABORT is non-zero. */
1026 1044
1027int 1045static int
1028find_tty (char **tty_type, char **tty_name, int noabort) 1046find_tty (const char **tty_type, const char **tty_name, int noabort)
1029{ 1047{
1030 char *type = egetenv ("TERM"); 1048 const char *type = egetenv ("TERM");
1031 char *name = ttyname (fileno (stdout)); 1049 const char *name = ttyname (fileno (stdout));
1032 1050
1033 if (!name) 1051 if (!name)
1034 { 1052 {
@@ -1080,11 +1098,11 @@ find_tty (char **tty_type, char **tty_name, int noabort)
1080 0 - success: none of the above */ 1098 0 - success: none of the above */
1081 1099
1082static int 1100static int
1083socket_status (char *socket_name) 1101socket_status (const char *name)
1084{ 1102{
1085 struct stat statbfr; 1103 struct stat statbfr;
1086 1104
1087 if (stat (socket_name, &statbfr) == -1) 1105 if (stat (name, &statbfr) == -1)
1088 return 2; 1106 return 2;
1089 1107
1090 if (statbfr.st_uid != geteuid ()) 1108 if (statbfr.st_uid != geteuid ())
@@ -1097,7 +1115,7 @@ socket_status (char *socket_name)
1097/* A signal handler that passes the signal to the Emacs process. 1115/* A signal handler that passes the signal to the Emacs process.
1098 Useful for SIGWINCH. */ 1116 Useful for SIGWINCH. */
1099 1117
1100SIGTYPE 1118static void
1101pass_signal_to_emacs (int signalnum) 1119pass_signal_to_emacs (int signalnum)
1102{ 1120{
1103 int old_errno = errno; 1121 int old_errno = errno;
@@ -1112,7 +1130,7 @@ pass_signal_to_emacs (int signalnum)
1112/* Signal handler for SIGCONT; notify the Emacs process that it can 1130/* Signal handler for SIGCONT; notify the Emacs process that it can
1113 now resume our tty frame. */ 1131 now resume our tty frame. */
1114 1132
1115SIGTYPE 1133static void
1116handle_sigcont (int signalnum) 1134handle_sigcont (int signalnum)
1117{ 1135{
1118 int old_errno = errno; 1136 int old_errno = errno;
@@ -1138,7 +1156,7 @@ handle_sigcont (int signalnum)
1138 reality, we may get a SIGTSTP on C-z. Handling this signal and 1156 reality, we may get a SIGTSTP on C-z. Handling this signal and
1139 notifying Emacs about it should get things under control again. */ 1157 notifying Emacs about it should get things under control again. */
1140 1158
1141SIGTYPE 1159static void
1142handle_sigtstp (int signalnum) 1160handle_sigtstp (int signalnum)
1143{ 1161{
1144 int old_errno = errno; 1162 int old_errno = errno;
@@ -1162,7 +1180,7 @@ handle_sigtstp (int signalnum)
1162 1180
1163/* Set up signal handlers before opening a frame on the current tty. */ 1181/* Set up signal handlers before opening a frame on the current tty. */
1164 1182
1165void 1183static void
1166init_signals (void) 1184init_signals (void)
1167{ 1185{
1168 /* Set up signal handlers. */ 1186 /* Set up signal handlers. */
@@ -1182,7 +1200,7 @@ init_signals (void)
1182} 1200}
1183 1201
1184 1202
1185HSOCKET 1203static HSOCKET
1186set_local_socket (void) 1204set_local_socket (void)
1187{ 1205{
1188 HSOCKET s; 1206 HSOCKET s;
@@ -1205,7 +1223,7 @@ set_local_socket (void)
1205 int default_sock = !socket_name; 1223 int default_sock = !socket_name;
1206 int saved_errno = 0; 1224 int saved_errno = 0;
1207 const char *server_name = "server"; 1225 const char *server_name = "server";
1208 const char *tmpdir; 1226 const char *tmpdir IF_LINT ( = NULL);
1209 1227
1210 if (socket_name && !strchr (socket_name, '/') 1228 if (socket_name && !strchr (socket_name, '/')
1211 && !strchr (socket_name, '\\')) 1229 && !strchr (socket_name, '\\'))
@@ -1260,10 +1278,10 @@ set_local_socket (void)
1260 associated with the name. This is reminiscent of the logic 1278 associated with the name. This is reminiscent of the logic
1261 that init_editfns uses to set the global Vuser_full_name. */ 1279 that init_editfns uses to set the global Vuser_full_name. */
1262 1280
1263 char *user_name = (char *) egetenv ("LOGNAME"); 1281 const char *user_name = egetenv ("LOGNAME");
1264 1282
1265 if (!user_name) 1283 if (!user_name)
1266 user_name = (char *) egetenv ("USER"); 1284 user_name = egetenv ("USER");
1267 1285
1268 if (user_name) 1286 if (user_name)
1269 { 1287 {
@@ -1331,7 +1349,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
1331} 1349}
1332#endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */ 1350#endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */
1333 1351
1334HSOCKET 1352static HSOCKET
1335set_socket (int no_exit_if_error) 1353set_socket (int no_exit_if_error)
1336{ 1354{
1337 HSOCKET s; 1355 HSOCKET s;
@@ -1447,7 +1465,7 @@ w32_give_focus (void)
1447 1465
1448/* Start the emacs daemon and try to connect to it. */ 1466/* Start the emacs daemon and try to connect to it. */
1449 1467
1450void 1468static void
1451start_daemon_and_retry_set_socket (void) 1469start_daemon_and_retry_set_socket (void)
1452{ 1470{
1453#ifndef WINDOWSNT 1471#ifndef WINDOWSNT
@@ -1483,8 +1501,8 @@ start_daemon_and_retry_set_socket (void)
1483 else 1501 else
1484 { 1502 {
1485 char emacs[] = "emacs"; 1503 char emacs[] = "emacs";
1486 char daemon[] = "--daemon"; 1504 char daemon_option[] = "--daemon";
1487 char *d_argv[] = {emacs, daemon, 0 }; 1505 char *d_argv[] = {emacs, daemon_option, 0 };
1488 if (socket_name != NULL) 1506 if (socket_name != NULL)
1489 { 1507 {
1490 /* Pass --daemon=socket_name as argument. */ 1508 /* Pass --daemon=socket_name as argument. */
@@ -1504,10 +1522,12 @@ start_daemon_and_retry_set_socket (void)
1504int 1522int
1505main (int argc, char **argv) 1523main (int argc, char **argv)
1506{ 1524{
1507 int i, rl, needlf = 0; 1525 int rl = 0, needlf = 0;
1508 char *cwd, *str; 1526 char *cwd, *str;
1509 char string[BUFSIZ+1]; 1527 char string[BUFSIZ+1];
1510 int null_socket_name, null_server_file, start_daemon_if_needed; 1528 int null_socket_name IF_LINT ( = 0);
1529 int null_server_file IF_LINT ( = 0);
1530 int start_daemon_if_needed;
1511 int exit_status = EXIT_SUCCESS; 1531 int exit_status = EXIT_SUCCESS;
1512 1532
1513 main_argv = argv; 1533 main_argv = argv;
@@ -1543,21 +1563,21 @@ main (int argc, char **argv)
1543 null_server_file = (server_file == NULL); 1563 null_server_file = (server_file == NULL);
1544 } 1564 }
1545 1565
1546 if ((emacs_socket = set_socket (alternate_editor 1566 emacs_socket = set_socket (alternate_editor || start_daemon_if_needed);
1547 || start_daemon_if_needed)) == INVALID_SOCKET) 1567 if (emacs_socket == INVALID_SOCKET)
1548 if (start_daemon_if_needed) 1568 {
1549 { 1569 if (! start_daemon_if_needed)
1550 /* Reset socket_name and server_file if they were NULL 1570 fail ();
1551 before the set_socket call. */ 1571
1552 if (null_socket_name) 1572 /* Reset socket_name and server_file if they were NULL
1553 socket_name = NULL; 1573 before the set_socket call. */
1554 if (null_server_file) 1574 if (null_socket_name)
1555 server_file = NULL; 1575 socket_name = NULL;
1556 1576 if (null_server_file)
1557 start_daemon_and_retry_set_socket (); 1577 server_file = NULL;
1558 } 1578
1559 else 1579 start_daemon_and_retry_set_socket ();
1560 fail (); 1580 }
1561 1581
1562 cwd = get_current_dir_name (); 1582 cwd = get_current_dir_name ();
1563 if (cwd == 0) 1583 if (cwd == 0)
@@ -1615,7 +1635,7 @@ main (int argc, char **argv)
1615 frame is available. */ 1635 frame is available. */
1616 if (tty || (current_frame && !eval)) 1636 if (tty || (current_frame && !eval))
1617 { 1637 {
1618 char *tty_type, *tty_name; 1638 const char *tty_type, *tty_name;
1619 1639
1620 if (find_tty (&tty_type, &tty_name, !tty)) 1640 if (find_tty (&tty_type, &tty_name, !tty))
1621 { 1641 {
@@ -1635,6 +1655,7 @@ main (int argc, char **argv)
1635 1655
1636 if ((argc - optind > 0)) 1656 if ((argc - optind > 0))
1637 { 1657 {
1658 int i;
1638 for (i = optind; i < argc; i++) 1659 for (i = optind; i < argc; i++)
1639 { 1660 {
1640 1661
@@ -1699,7 +1720,7 @@ main (int argc, char **argv)
1699 send_to_emacs (emacs_socket, "\n"); 1720 send_to_emacs (emacs_socket, "\n");
1700 1721
1701 /* Wait for an answer. */ 1722 /* Wait for an answer. */
1702 if (!eval && !tty && !nowait) 1723 if (!eval && !tty && !nowait && !quiet)
1703 { 1724 {
1704 printf ("Waiting for Emacs..."); 1725 printf ("Waiting for Emacs...");
1705 needlf = 2; 1726 needlf = 2;
@@ -1708,10 +1729,21 @@ main (int argc, char **argv)
1708 fsync (1); 1729 fsync (1);
1709 1730
1710 /* Now, wait for an answer and print any messages. */ 1731 /* Now, wait for an answer and print any messages. */
1711 while (exit_status == EXIT_SUCCESS 1732 while (exit_status == EXIT_SUCCESS)
1712 && (rl = recv (emacs_socket, string, BUFSIZ, 0)) > 0)
1713 { 1733 {
1714 char *p; 1734 char *p;
1735 do
1736 {
1737 errno = 0;
1738 rl = recv (emacs_socket, string, BUFSIZ, 0);
1739 }
1740 /* If we receive a signal (e.g. SIGWINCH, which we pass
1741 through to Emacs), on some OSes we get EINTR and must retry. */
1742 while (rl < 0 && errno == EINTR);
1743
1744 if (rl <= 0)
1745 break;
1746
1715 string[rl] = '\0'; 1747 string[rl] = '\0';
1716 1748
1717 p = string + strlen (string) - 1; 1749 p = string + strlen (string) - 1;