comparison lib-src/emacsclient.c @ 91367:c70e45a7acfd

Merge from emacs--devo--0 Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-324
author Miles Bader <miles@gnu.org>
date Wed, 30 Jan 2008 07:57:28 +0000
parents 606f2d163a64 e830695cdb7f
children
comparison
equal deleted inserted replaced
91366:86f3a8f0a3a6 91367:c70e45a7acfd
168 { "alternate-editor", required_argument, NULL, 'a' }, 168 { "alternate-editor", required_argument, NULL, 'a' },
169 #ifndef NO_SOCKETS_IN_FILE_SYSTEM 169 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
170 { "socket-name", required_argument, NULL, 's' }, 170 { "socket-name", required_argument, NULL, 's' },
171 #endif 171 #endif
172 { "server-file", required_argument, NULL, 'f' }, 172 { "server-file", required_argument, NULL, 'f' },
173 #ifndef WINDOWSNT
173 { "display", required_argument, NULL, 'd' }, 174 { "display", required_argument, NULL, 'd' },
175 #endif
174 { 0, 0, 0, 0 } 176 { 0, 0, 0, 0 }
175 }; 177 };
176 178
177 179
178 /* Like malloc but get fatal error if memory is exhausted. */ 180 /* Like malloc but get fatal error if memory is exhausted. */
225 #define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_)) 227 #define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_))
226 #endif 228 #endif
227 229
228 230
229 /* Return the current working directory. Returns NULL on errors. 231 /* Return the current working directory. Returns NULL on errors.
230 Any other returned value must be freed with free. This is used 232 Any other returned value must be freed with free. This is used
231 only when get_current_dir_name is not defined on the system. */ 233 only when get_current_dir_name is not defined on the system. */
232 char* 234 char*
233 get_current_dir_name () 235 get_current_dir_name ()
234 { 236 {
235 char *buf; 237 char *buf;
475 decode_options (argc, argv) 477 decode_options (argc, argv)
476 int argc; 478 int argc;
477 char **argv; 479 char **argv;
478 { 480 {
479 alternate_editor = egetenv ("ALTERNATE_EDITOR"); 481 alternate_editor = egetenv ("ALTERNATE_EDITOR");
482
483 /* We used to set `display' to $DISPLAY by default, but this changed the
484 default behavior and is sometimes inconvenient. So instead of forcing
485 users to say "--display ''" when they want to use Emacs's existing tty
486 or display connection, we force them to use "--display $DISPLAY" if
487 they want Emacs to connect to their current display. */
488 #if 0
480 display = egetenv ("DISPLAY"); 489 display = egetenv ("DISPLAY");
481 if (display && strlen (display) == 0) 490 #endif
482 display = NULL;
483 491
484 while (1) 492 while (1)
485 { 493 {
486 int opt = getopt_long (argc, argv, 494 int opt = getopt_long (argc, argv,
487 #ifndef NO_SOCKETS_IN_FILE_SYSTEM 495 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
513 521
514 case 'f': 522 case 'f':
515 server_file = optarg; 523 server_file = optarg;
516 break; 524 break;
517 525
526 /* We used to disallow this argument in w32, but it seems better
527 to allow it, for the occasional case where the user is
528 connecting with a w32 client to a server compiled with X11
529 support. */
530 #if 1 /* !defined WINDOWS */
518 case 'd': 531 case 'd':
519 display = optarg; 532 display = optarg;
520 break; 533 break;
534 #endif
521 535
522 case 'n': 536 case 'n':
523 nowait = 1; 537 nowait = 1;
524 break; 538 break;
525 539
549 message (TRUE, "Try `%s --help' for more information\n", progname); 563 message (TRUE, "Try `%s --help' for more information\n", progname);
550 exit (EXIT_FAILURE); 564 exit (EXIT_FAILURE);
551 break; 565 break;
552 } 566 }
553 } 567 }
568
569 if (display && strlen (display) == 0)
570 display = NULL;
554 571
555 if (!tty && display) 572 if (!tty && display)
556 window_system = 1; 573 window_system = 1;
557 #if !defined (WINDOWSNT) && !defined (HAVE_CARBON) 574 #if !defined (WINDOWSNT) && !defined (HAVE_CARBON)
558 else 575 else
592 -H, --help Print this usage information message\n\ 609 -H, --help Print this usage information message\n\
593 -t, --tty Open a new Emacs frame on the current terminal\n\ 610 -t, --tty Open a new Emacs frame on the current terminal\n\
594 -c, --create-frame Create a new frame instead of trying to\n\ 611 -c, --create-frame Create a new frame instead of trying to\n\
595 use the current Emacs frame\n\ 612 use the current Emacs frame\n\
596 -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ 613 -e, --eval Evaluate the FILE arguments as ELisp expressions\n\
597 -n, --no-wait Don't wait for the server to return\n\ 614 -n, --no-wait Don't wait for the server to return\n"
598 -d, --display=DISPLAY Visit the file in the given display\n" 615 #ifndef WINDOWSNT
616 "-d, --display=DISPLAY Visit the file in the given display\n"
617 #endif
599 #ifndef NO_SOCKETS_IN_FILE_SYSTEM 618 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
600 "-s, --socket-name=FILENAME\n\ 619 "-s, --socket-name=FILENAME\n\
601 Set filename of the UNIX socket for communication\n" 620 Set filename of the UNIX socket for communication\n"
602 #endif 621 #endif
603 "-f, --server-file=FILENAME\n\ 622 "-f, --server-file=FILENAME\n\
880 { 899 {
881 WSADATA wsaData; 900 WSADATA wsaData;
882 901
883 if (WSAStartup (MAKEWORD (2, 0), &wsaData)) 902 if (WSAStartup (MAKEWORD (2, 0), &wsaData))
884 { 903 {
885 message (TRUE, "%s: error initializing WinSock2", progname); 904 message (TRUE, "%s: error initializing WinSock2\n", progname);
886 exit (EXIT_FAILURE); 905 exit (EXIT_FAILURE);
887 } 906 }
888 907
889 atexit (close_winsock); 908 atexit (close_winsock);
890 } 909 }
937 *port++ = '\0'; 956 *port++ = '\0';
938 *pid++ = '\0'; 957 *pid++ = '\0';
939 } 958 }
940 else 959 else
941 { 960 {
942 message (TRUE, "%s: invalid configuration info", progname); 961 message (TRUE, "%s: invalid configuration info\n", progname);
943 exit (EXIT_FAILURE); 962 exit (EXIT_FAILURE);
944 } 963 }
945 964
946 server->sin_family = AF_INET; 965 server->sin_family = AF_INET;
947 server->sin_addr.s_addr = inet_addr (dotted); 966 server->sin_addr.s_addr = inet_addr (dotted);
948 server->sin_port = htons (atoi (port)); 967 server->sin_port = htons (atoi (port));
949 968
950 if (! fread (authentication, AUTH_KEY_LENGTH, 1, config)) 969 if (! fread (authentication, AUTH_KEY_LENGTH, 1, config))
951 { 970 {
952 message (TRUE, "%s: cannot read authentication info", progname); 971 message (TRUE, "%s: cannot read authentication info\n", progname);
953 exit (EXIT_FAILURE); 972 exit (EXIT_FAILURE);
954 } 973 }
955 974
956 fclose (config); 975 fclose (config);
957 976
1000 */ 1019 */
1001 auth_string[AUTH_KEY_LENGTH] = '\0'; 1020 auth_string[AUTH_KEY_LENGTH] = '\0';
1002 1021
1003 send_to_emacs (s, "-auth "); 1022 send_to_emacs (s, "-auth ");
1004 send_to_emacs (s, auth_string); 1023 send_to_emacs (s, auth_string);
1005 send_to_emacs (s, "\n"); 1024 send_to_emacs (s, " ");
1006 1025
1007 return s; 1026 return s;
1008 } 1027 }
1009 1028
1010 1029
1090 sigset_t set; 1109 sigset_t set;
1091 1110
1092 if (emacs_socket) 1111 if (emacs_socket)
1093 send_to_emacs (emacs_socket, "-suspend \n"); 1112 send_to_emacs (emacs_socket, "-suspend \n");
1094 1113
1095 /* Unblock this signal and call the default handler by temprarily 1114 /* Unblock this signal and call the default handler by temporarily
1096 changing the handler and resignalling. */ 1115 changing the handler and resignalling. */
1097 sigprocmask (SIG_BLOCK, NULL, &set); 1116 sigprocmask (SIG_BLOCK, NULL, &set);
1098 sigdelset (&set, signalnum); 1117 sigdelset (&set, signalnum);
1099 signal (signalnum, SIG_DFL); 1118 signal (signalnum, SIG_DFL);
1100 kill (getpid (), signalnum); 1119 kill (getpid (), signalnum);
1165 1184
1166 if (strlen (socket_name) < sizeof (server.sun_path)) 1185 if (strlen (socket_name) < sizeof (server.sun_path))
1167 strcpy (server.sun_path, socket_name); 1186 strcpy (server.sun_path, socket_name);
1168 else 1187 else
1169 { 1188 {
1170 message (TRUE, "%s: socket-name %s too long", 1189 message (TRUE, "%s: socket-name %s too long\n",
1171 progname, socket_name); 1190 progname, socket_name);
1172 fail (); 1191 fail ();
1173 } 1192 }
1174 1193
1175 /* See if the socket exists, and if it's owned by us. */ 1194 /* See if the socket exists, and if it's owned by us. */
1200 1219
1201 if (strlen (socket_name) < sizeof (server.sun_path)) 1220 if (strlen (socket_name) < sizeof (server.sun_path))
1202 strcpy (server.sun_path, socket_name); 1221 strcpy (server.sun_path, socket_name);
1203 else 1222 else
1204 { 1223 {
1205 message (TRUE, "%s: socket-name %s too long", 1224 message (TRUE, "%s: socket-name %s too long\n",
1206 progname, socket_name); 1225 progname, socket_name);
1207 exit (EXIT_FAILURE); 1226 exit (EXIT_FAILURE);
1208 } 1227 }
1209 1228
1210 sock_status = socket_status (server.sun_path); 1229 sock_status = socket_status (server.sun_path);
1264 if (socket_name) 1283 if (socket_name)
1265 { 1284 {
1266 s = set_local_socket (); 1285 s = set_local_socket ();
1267 if ((s != INVALID_SOCKET) || alternate_editor) 1286 if ((s != INVALID_SOCKET) || alternate_editor)
1268 return s; 1287 return s;
1269 message (TRUE, "%s: error accessing socket \"%s\"", 1288 message (TRUE, "%s: error accessing socket \"%s\"\n",
1270 progname, socket_name); 1289 progname, socket_name);
1271 exit (EXIT_FAILURE); 1290 exit (EXIT_FAILURE);
1272 } 1291 }
1273 #endif 1292 #endif
1274 1293
1280 { 1299 {
1281 s = set_tcp_socket (); 1300 s = set_tcp_socket ();
1282 if ((s != INVALID_SOCKET) || alternate_editor) 1301 if ((s != INVALID_SOCKET) || alternate_editor)
1283 return s; 1302 return s;
1284 1303
1285 message (TRUE, "%s: error accessing server file \"%s\"", 1304 message (TRUE, "%s: error accessing server file \"%s\"\n",
1286 progname, server_file); 1305 progname, server_file);
1287 exit (EXIT_FAILURE); 1306 exit (EXIT_FAILURE);
1288 } 1307 }
1289 1308
1290 #ifndef NO_SOCKETS_IN_FILE_SYSTEM 1309 #ifndef NO_SOCKETS_IN_FILE_SYSTEM