diff options
Diffstat (limited to 'lib-src/emacsclient.c')
| -rw-r--r-- | lib-src/emacsclient.c | 89 |
1 files changed, 28 insertions, 61 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 29504445407..0ba6535b79d 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -21,7 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 21 | 21 | ||
| 22 | #ifdef WINDOWSNT | 22 | #ifdef WINDOWSNT |
| 23 | 23 | ||
| 24 | /* config.h defines these, which disables sockets altogether! */ | 24 | /* ms-w32.h defines these, which disables sockets altogether! */ |
| 25 | # undef _WINSOCKAPI_ | 25 | # undef _WINSOCKAPI_ |
| 26 | # undef _WINSOCK_H | 26 | # undef _WINSOCK_H |
| 27 | 27 | ||
| @@ -169,8 +169,7 @@ int emacs_pid = 0; | |||
| 169 | be used for the new frame */ | 169 | be used for the new frame */ |
| 170 | const char *frame_parameters = NULL; | 170 | const char *frame_parameters = NULL; |
| 171 | 171 | ||
| 172 | static void print_help_and_exit (void) NO_RETURN; | 172 | static _Noreturn void print_help_and_exit (void); |
| 173 | static void fail (void) NO_RETURN; | ||
| 174 | 173 | ||
| 175 | 174 | ||
| 176 | struct option longopts[] = | 175 | struct option longopts[] = |
| @@ -452,19 +451,19 @@ w32_window_app (void) | |||
| 452 | return window_app; | 451 | return window_app; |
| 453 | } | 452 | } |
| 454 | 453 | ||
| 455 | /* | 454 | /* execvp wrapper for Windows. Quotes arguments with embedded spaces. |
| 456 | execvp wrapper for Windows. Quotes arguments with embedded spaces. | ||
| 457 | 455 | ||
| 458 | This is necessary due to the broken implementation of exec* routines in | 456 | This is necessary due to the broken implementation of exec* routines in |
| 459 | the Microsoft libraries: they concatenate the arguments together without | 457 | the Microsoft libraries: they concatenate the arguments together without |
| 460 | quoting special characters, and pass the result to CreateProcess, with | 458 | quoting special characters, and pass the result to CreateProcess, with |
| 461 | predictably bad results. By contrast, POSIX execvp passes the arguments | 459 | predictably bad results. By contrast, POSIX execvp passes the arguments |
| 462 | directly into the argv array of the child process. | 460 | directly into the argv array of the child process. */ |
| 463 | */ | 461 | |
| 464 | int | 462 | int |
| 465 | w32_execvp (const char *path, char **argv) | 463 | w32_execvp (const char *path, char **argv) |
| 466 | { | 464 | { |
| 467 | int i; | 465 | int i; |
| 466 | extern int execvp (const char*, char **); | ||
| 468 | 467 | ||
| 469 | /* Required to allow a .BAT script as alternate editor. */ | 468 | /* Required to allow a .BAT script as alternate editor. */ |
| 470 | argv[0] = (char *) alternate_editor; | 469 | argv[0] = (char *) alternate_editor; |
| @@ -670,7 +669,7 @@ an empty string"); | |||
| 670 | } | 669 | } |
| 671 | 670 | ||
| 672 | 671 | ||
| 673 | static void | 672 | static _Noreturn void |
| 674 | print_help_and_exit (void) | 673 | print_help_and_exit (void) |
| 675 | { | 674 | { |
| 676 | /* Spaces and tabs are significant in this message; they're chosen so the | 675 | /* Spaces and tabs are significant in this message; they're chosen so the |
| @@ -713,12 +712,11 @@ Report bugs with M-x report-emacs-bug.\n", progname); | |||
| 713 | exit (EXIT_SUCCESS); | 712 | exit (EXIT_SUCCESS); |
| 714 | } | 713 | } |
| 715 | 714 | ||
| 716 | /* | 715 | /* Try to run a different command, or --if no alternate editor is |
| 717 | Try to run a different command, or --if no alternate editor is | 716 | defined-- exit with an errorcode. |
| 718 | defined-- exit with an errorcode. | 717 | Uses argv, but gets it from the global variable main_argv. */ |
| 719 | Uses argv, but gets it from the global variable main_argv. | 718 | |
| 720 | */ | 719 | static _Noreturn void |
| 721 | static void | ||
| 722 | fail (void) | 720 | fail (void) |
| 723 | { | 721 | { |
| 724 | if (alternate_editor) | 722 | if (alternate_editor) |
| @@ -751,16 +749,15 @@ main (int argc, char **argv) | |||
| 751 | #define AUTH_KEY_LENGTH 64 | 749 | #define AUTH_KEY_LENGTH 64 |
| 752 | #define SEND_BUFFER_SIZE 4096 | 750 | #define SEND_BUFFER_SIZE 4096 |
| 753 | 751 | ||
| 754 | extern char *strerror (int); | ||
| 755 | |||
| 756 | /* Buffer to accumulate data to send in TCP connections. */ | 752 | /* Buffer to accumulate data to send in TCP connections. */ |
| 757 | char send_buffer[SEND_BUFFER_SIZE + 1]; | 753 | char send_buffer[SEND_BUFFER_SIZE + 1]; |
| 758 | int sblen = 0; /* Fill pointer for the send buffer. */ | 754 | int sblen = 0; /* Fill pointer for the send buffer. */ |
| 759 | /* Socket used to communicate with the Emacs server process. */ | 755 | /* Socket used to communicate with the Emacs server process. */ |
| 760 | HSOCKET emacs_socket = 0; | 756 | HSOCKET emacs_socket = 0; |
| 761 | 757 | ||
| 762 | /* On Windows, the socket library was historically separate from the standard | 758 | /* On Windows, the socket library was historically separate from the |
| 763 | C library, so errors are handled differently. */ | 759 | standard C library, so errors are handled differently. */ |
| 760 | |||
| 764 | static void | 761 | static void |
| 765 | sock_err_message (const char *function_name) | 762 | sock_err_message (const char *function_name) |
| 766 | { | 763 | { |
| @@ -865,7 +862,7 @@ quote_argument (HSOCKET s, const char *str) | |||
| 865 | 862 | ||
| 866 | 863 | ||
| 867 | /* The inverse of quote_argument. Removes quoting in string STR by | 864 | /* The inverse of quote_argument. Removes quoting in string STR by |
| 868 | modifying the string in place. Returns STR. */ | 865 | modifying the string in place. Returns STR. */ |
| 869 | 866 | ||
| 870 | static char * | 867 | static char * |
| 871 | unquote_argument (char *str) | 868 | unquote_argument (char *str) |
| @@ -948,10 +945,9 @@ initialize_sockets (void) | |||
| 948 | #endif /* WINDOWSNT */ | 945 | #endif /* WINDOWSNT */ |
| 949 | 946 | ||
| 950 | 947 | ||
| 951 | /* | 948 | /* Read the information needed to set up a TCP comm channel with |
| 952 | * Read the information needed to set up a TCP comm channel with | 949 | the Emacs server: host, port, and authentication string. */ |
| 953 | * the Emacs server: host, port, and authentication string. | 950 | |
| 954 | */ | ||
| 955 | static int | 951 | static int |
| 956 | get_server_config (const char *config_file, struct sockaddr_in *server, | 952 | get_server_config (const char *config_file, struct sockaddr_in *server, |
| 957 | char *authentication) | 953 | char *authentication) |
| @@ -1032,18 +1028,14 @@ set_tcp_socket (const char *local_server_file) | |||
| 1032 | message (FALSE, "%s: connected to remote socket at %s\n", | 1028 | message (FALSE, "%s: connected to remote socket at %s\n", |
| 1033 | progname, inet_ntoa (server.sin_addr)); | 1029 | progname, inet_ntoa (server.sin_addr)); |
| 1034 | 1030 | ||
| 1035 | /* | 1031 | /* Open up an AF_INET socket. */ |
| 1036 | * Open up an AF_INET socket | ||
| 1037 | */ | ||
| 1038 | if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) | 1032 | if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) |
| 1039 | { | 1033 | { |
| 1040 | sock_err_message ("socket"); | 1034 | sock_err_message ("socket"); |
| 1041 | return INVALID_SOCKET; | 1035 | return INVALID_SOCKET; |
| 1042 | } | 1036 | } |
| 1043 | 1037 | ||
| 1044 | /* | 1038 | /* Set up the socket. */ |
| 1045 | * Set up the socket | ||
| 1046 | */ | ||
| 1047 | if (connect (s, (struct sockaddr *) &server, sizeof server) < 0) | 1039 | if (connect (s, (struct sockaddr *) &server, sizeof server) < 0) |
| 1048 | { | 1040 | { |
| 1049 | sock_err_message ("connect"); | 1041 | sock_err_message ("connect"); |
| @@ -1052,9 +1044,7 @@ set_tcp_socket (const char *local_server_file) | |||
| 1052 | 1044 | ||
| 1053 | setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg); | 1045 | setsockopt (s, SOL_SOCKET, SO_LINGER, (char *) &l_arg, sizeof l_arg); |
| 1054 | 1046 | ||
| 1055 | /* | 1047 | /* Send the authentication. */ |
| 1056 | * Send the authentication | ||
| 1057 | */ | ||
| 1058 | auth_string[AUTH_KEY_LENGTH] = '\0'; | 1048 | auth_string[AUTH_KEY_LENGTH] = '\0'; |
| 1059 | 1049 | ||
| 1060 | send_to_emacs (s, "-auth "); | 1050 | send_to_emacs (s, "-auth "); |
| @@ -1188,7 +1178,7 @@ handle_sigcont (int signalnum) | |||
| 1188 | going to sleep. Normally the suspend is initiated by Emacs via | 1178 | going to sleep. Normally the suspend is initiated by Emacs via |
| 1189 | server-handle-suspend-tty, but if the server gets out of sync with | 1179 | server-handle-suspend-tty, but if the server gets out of sync with |
| 1190 | reality, we may get a SIGTSTP on C-z. Handling this signal and | 1180 | reality, we may get a SIGTSTP on C-z. Handling this signal and |
| 1191 | notifying Emacs about it should get things under control again. */ | 1181 | notifying Emacs about it should get things under control again. */ |
| 1192 | 1182 | ||
| 1193 | static void | 1183 | static void |
| 1194 | handle_sigtstp (int signalnum) | 1184 | handle_sigtstp (int signalnum) |
| @@ -1240,10 +1230,7 @@ set_local_socket (const char *local_socket_name) | |||
| 1240 | HSOCKET s; | 1230 | HSOCKET s; |
| 1241 | struct sockaddr_un server; | 1231 | struct sockaddr_un server; |
| 1242 | 1232 | ||
| 1243 | /* | 1233 | /* Open up an AF_UNIX socket in this person's home directory. */ |
| 1244 | * Open up an AF_UNIX socket in this person's home directory | ||
| 1245 | */ | ||
| 1246 | |||
| 1247 | if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) | 1234 | if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) |
| 1248 | { | 1235 | { |
| 1249 | message (TRUE, "%s: socket: %s\n", progname, strerror (errno)); | 1236 | message (TRUE, "%s: socket: %s\n", progname, strerror (errno)); |
| @@ -1278,7 +1265,7 @@ set_local_socket (const char *local_socket_name) | |||
| 1278 | if (n > 0) | 1265 | if (n > 0) |
| 1279 | { | 1266 | { |
| 1280 | tmpdir = tmpdir_storage = xmalloc (n); | 1267 | tmpdir = tmpdir_storage = xmalloc (n); |
| 1281 | confstr (_CS_DARWIN_USER_TEMP_DIR, tmpdir, n); | 1268 | confstr (_CS_DARWIN_USER_TEMP_DIR, tmpdir_storage, n); |
| 1282 | } | 1269 | } |
| 1283 | else | 1270 | else |
| 1284 | #endif | 1271 | #endif |
| @@ -1477,10 +1464,9 @@ w32_find_emacs_process (HWND hWnd, LPARAM lParam) | |||
| 1477 | return FALSE; | 1464 | return FALSE; |
| 1478 | } | 1465 | } |
| 1479 | 1466 | ||
| 1480 | /* | 1467 | /* Search for a window of class "Emacs" and owned by a process with |
| 1481 | * Search for a window of class "Emacs" and owned by a process with | 1468 | process id = emacs_pid. If found, allow it to grab the focus. */ |
| 1482 | * process id = emacs_pid. If found, allow it to grab the focus. | 1469 | |
| 1483 | */ | ||
| 1484 | void | 1470 | void |
| 1485 | w32_give_focus (void) | 1471 | w32_give_focus (void) |
| 1486 | { | 1472 | { |
| @@ -1862,22 +1848,3 @@ main (int argc, char **argv) | |||
| 1862 | } | 1848 | } |
| 1863 | 1849 | ||
| 1864 | #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ | 1850 | #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ |
| 1865 | |||
| 1866 | |||
| 1867 | #ifndef HAVE_STRERROR | ||
| 1868 | char * | ||
| 1869 | strerror (errnum) | ||
| 1870 | int errnum; | ||
| 1871 | { | ||
| 1872 | extern char *sys_errlist[]; | ||
| 1873 | extern int sys_nerr; | ||
| 1874 | |||
| 1875 | if (errnum >= 0 && errnum < sys_nerr) | ||
| 1876 | return sys_errlist[errnum]; | ||
| 1877 | return (char *) "Unknown error"; | ||
| 1878 | } | ||
| 1879 | |||
| 1880 | #endif /* ! HAVE_STRERROR */ | ||
| 1881 | |||
| 1882 | |||
| 1883 | /* emacsclient.c ends here */ | ||