diff options
| author | Stefan Monnier | 2010-10-15 17:55:33 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2010-10-15 17:55:33 -0400 |
| commit | 0c747cb143fa227e78f350ac353d703f489209df (patch) | |
| tree | 5b434055c797bd75eaa1e3d9d0773e586d44daee /lib-src/emacsclient.c | |
| parent | a01a7932080e8a6e7bc8472c58cefabcc2c37df3 (diff) | |
| parent | aa095b2db98ae149737f8de00ee733b1d257ed33 (diff) | |
| download | emacs-0c747cb143fa227e78f350ac353d703f489209df.tar.gz emacs-0c747cb143fa227e78f350ac353d703f489209df.zip | |
Merge from trunk
Diffstat (limited to 'lib-src/emacsclient.c')
| -rw-r--r-- | lib-src/emacsclient.c | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 1f96c481129..b60b2661805 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -39,6 +39,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 39 | # define CLOSE_SOCKET closesocket | 39 | # define CLOSE_SOCKET closesocket |
| 40 | # define INITIALIZE() (initialize_sockets ()) | 40 | # define INITIALIZE() (initialize_sockets ()) |
| 41 | 41 | ||
| 42 | char *w32_getenv (char *); | ||
| 43 | #define egetenv(VAR) w32_getenv(VAR) | ||
| 44 | |||
| 42 | #else /* !WINDOWSNT */ | 45 | #else /* !WINDOWSNT */ |
| 43 | 46 | ||
| 44 | # include "syswait.h" | 47 | # include "syswait.h" |
| @@ -62,6 +65,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 62 | # define WCONTINUED 8 | 65 | # define WCONTINUED 8 |
| 63 | # endif | 66 | # endif |
| 64 | 67 | ||
| 68 | #define egetenv(VAR) getenv(VAR) | ||
| 69 | |||
| 65 | #endif /* !WINDOWSNT */ | 70 | #endif /* !WINDOWSNT */ |
| 66 | 71 | ||
| 67 | #undef signal | 72 | #undef signal |
| @@ -86,13 +91,6 @@ char *getenv (const char *), *getwd (char *); | |||
| 86 | char *(getcwd) (char *, size_t); | 91 | char *(getcwd) (char *, size_t); |
| 87 | #endif | 92 | #endif |
| 88 | 93 | ||
| 89 | #ifdef WINDOWSNT | ||
| 90 | char *w32_getenv (char *); | ||
| 91 | #define egetenv(VAR) w32_getenv(VAR) | ||
| 92 | #else | ||
| 93 | #define egetenv(VAR) getenv(VAR) | ||
| 94 | #endif | ||
| 95 | |||
| 96 | #ifndef VERSION | 94 | #ifndef VERSION |
| 97 | #define VERSION "unspecified" | 95 | #define VERSION "unspecified" |
| 98 | #endif | 96 | #endif |
| @@ -119,7 +117,7 @@ char *w32_getenv (char *); | |||
| 119 | 117 | ||
| 120 | 118 | ||
| 121 | /* Name used to invoke this program. */ | 119 | /* Name used to invoke this program. */ |
| 122 | char *progname; | 120 | const char *progname; |
| 123 | 121 | ||
| 124 | /* The second argument to main. */ | 122 | /* The second argument to main. */ |
| 125 | char **main_argv; | 123 | char **main_argv; |
| @@ -752,7 +750,7 @@ send_to_emacs (HSOCKET s, const char *data) | |||
| 752 | { | 750 | { |
| 753 | while (data) | 751 | while (data) |
| 754 | { | 752 | { |
| 755 | int dlen = strlen (data); | 753 | size_t dlen = strlen (data); |
| 756 | if (dlen + sblen >= SEND_BUFFER_SIZE) | 754 | if (dlen + sblen >= SEND_BUFFER_SIZE) |
| 757 | { | 755 | { |
| 758 | int part = SEND_BUFFER_SIZE - sblen; | 756 | int part = SEND_BUFFER_SIZE - sblen; |
| @@ -910,14 +908,13 @@ initialize_sockets (void) | |||
| 910 | 908 | ||
| 911 | /* | 909 | /* |
| 912 | * Read the information needed to set up a TCP comm channel with | 910 | * Read the information needed to set up a TCP comm channel with |
| 913 | * the Emacs server: host, port, pid and authentication string. | 911 | * the Emacs server: host, port, and authentication string. |
| 914 | */ | 912 | */ |
| 915 | int | 913 | int |
| 916 | get_server_config (struct sockaddr_in *server, char *authentication) | 914 | get_server_config (struct sockaddr_in *server, char *authentication) |
| 917 | { | 915 | { |
| 918 | char dotted[32]; | 916 | char dotted[32]; |
| 919 | char *port; | 917 | char *port; |
| 920 | char *pid; | ||
| 921 | FILE *config = NULL; | 918 | FILE *config = NULL; |
| 922 | 919 | ||
| 923 | if (file_name_absolute_p (server_file)) | 920 | if (file_name_absolute_p (server_file)) |
| @@ -948,12 +945,8 @@ get_server_config (struct sockaddr_in *server, char *authentication) | |||
| 948 | return FALSE; | 945 | return FALSE; |
| 949 | 946 | ||
| 950 | if (fgets (dotted, sizeof dotted, config) | 947 | if (fgets (dotted, sizeof dotted, config) |
| 951 | && (port = strchr (dotted, ':')) | 948 | && (port = strchr (dotted, ':'))) |
| 952 | && (pid = strchr (port, ' '))) | 949 | *port++ = '\0'; |
| 953 | { | ||
| 954 | *port++ = '\0'; | ||
| 955 | *pid++ = '\0'; | ||
| 956 | } | ||
| 957 | else | 950 | else |
| 958 | { | 951 | { |
| 959 | message (TRUE, "%s: invalid configuration info\n", progname); | 952 | message (TRUE, "%s: invalid configuration info\n", progname); |
| @@ -972,8 +965,6 @@ get_server_config (struct sockaddr_in *server, char *authentication) | |||
| 972 | 965 | ||
| 973 | fclose (config); | 966 | fclose (config); |
| 974 | 967 | ||
| 975 | emacs_pid = atoi (pid); | ||
| 976 | |||
| 977 | return TRUE; | 968 | return TRUE; |
| 978 | } | 969 | } |
| 979 | 970 | ||
| @@ -1232,7 +1223,18 @@ set_local_socket (void) | |||
| 1232 | { | 1223 | { |
| 1233 | tmpdir = egetenv ("TMPDIR"); | 1224 | tmpdir = egetenv ("TMPDIR"); |
| 1234 | if (!tmpdir) | 1225 | if (!tmpdir) |
| 1235 | tmpdir = "/tmp"; | 1226 | { |
| 1227 | #ifdef DARWIN_OS | ||
| 1228 | size_t n = confstr (_CS_DARWIN_USER_TEMP_DIR, NULL, (size_t) 0); | ||
| 1229 | if (n > 0) | ||
| 1230 | { | ||
| 1231 | tmpdir = alloca (n); | ||
| 1232 | confstr (_CS_DARWIN_USER_TEMP_DIR, tmpdir, n); | ||
| 1233 | } | ||
| 1234 | else | ||
| 1235 | #endif | ||
| 1236 | tmpdir = "/tmp"; | ||
| 1237 | } | ||
| 1236 | socket_name = alloca (strlen (tmpdir) + strlen (server_name) | 1238 | socket_name = alloca (strlen (tmpdir) + strlen (server_name) |
| 1237 | + EXTRA_SPACE); | 1239 | + EXTRA_SPACE); |
| 1238 | sprintf (socket_name, "%s/emacs%d/%s", | 1240 | sprintf (socket_name, "%s/emacs%d/%s", |
| @@ -1506,6 +1508,7 @@ main (int argc, char **argv) | |||
| 1506 | char *cwd, *str; | 1508 | char *cwd, *str; |
| 1507 | char string[BUFSIZ+1]; | 1509 | char string[BUFSIZ+1]; |
| 1508 | int null_socket_name, null_server_file, start_daemon_if_needed; | 1510 | int null_socket_name, null_server_file, start_daemon_if_needed; |
| 1511 | int exit_status = EXIT_SUCCESS; | ||
| 1509 | 1512 | ||
| 1510 | main_argv = argv; | 1513 | main_argv = argv; |
| 1511 | progname = argv[0]; | 1514 | progname = argv[0]; |
| @@ -1705,7 +1708,8 @@ main (int argc, char **argv) | |||
| 1705 | fsync (1); | 1708 | fsync (1); |
| 1706 | 1709 | ||
| 1707 | /* Now, wait for an answer and print any messages. */ | 1710 | /* Now, wait for an answer and print any messages. */ |
| 1708 | while ((rl = recv (emacs_socket, string, BUFSIZ, 0)) > 0) | 1711 | while (exit_status == EXIT_SUCCESS |
| 1712 | && (rl = recv (emacs_socket, string, BUFSIZ, 0)) > 0) | ||
| 1709 | { | 1713 | { |
| 1710 | char *p; | 1714 | char *p; |
| 1711 | string[rl] = '\0'; | 1715 | string[rl] = '\0'; |
| @@ -1744,6 +1748,7 @@ main (int argc, char **argv) | |||
| 1744 | printf ("\n"); | 1748 | printf ("\n"); |
| 1745 | fprintf (stderr, "*ERROR*: %s", str); | 1749 | fprintf (stderr, "*ERROR*: %s", str); |
| 1746 | needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; | 1750 | needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; |
| 1751 | exit_status = EXIT_FAILURE; | ||
| 1747 | } | 1752 | } |
| 1748 | #ifdef SIGSTOP | 1753 | #ifdef SIGSTOP |
| 1749 | else if (strprefix ("-suspend ", string)) | 1754 | else if (strprefix ("-suspend ", string)) |
| @@ -1761,7 +1766,8 @@ main (int argc, char **argv) | |||
| 1761 | if (needlf) | 1766 | if (needlf) |
| 1762 | printf ("\n"); | 1767 | printf ("\n"); |
| 1763 | printf ("*ERROR*: Unknown message: %s", string); | 1768 | printf ("*ERROR*: Unknown message: %s", string); |
| 1764 | needlf = string[0] == '\0' ? needlf : string[strlen (string) - 1] != '\n'; | 1769 | needlf = string[0] |
| 1770 | == '\0' ? needlf : string[strlen (string) - 1] != '\n'; | ||
| 1765 | } | 1771 | } |
| 1766 | } | 1772 | } |
| 1767 | 1773 | ||
| @@ -1770,8 +1776,11 @@ main (int argc, char **argv) | |||
| 1770 | fflush (stdout); | 1776 | fflush (stdout); |
| 1771 | fsync (1); | 1777 | fsync (1); |
| 1772 | 1778 | ||
| 1779 | if (rl < 0) | ||
| 1780 | exit_status = EXIT_FAILURE; | ||
| 1781 | |||
| 1773 | CLOSE_SOCKET (emacs_socket); | 1782 | CLOSE_SOCKET (emacs_socket); |
| 1774 | return EXIT_SUCCESS; | 1783 | return exit_status; |
| 1775 | } | 1784 | } |
| 1776 | 1785 | ||
| 1777 | #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ | 1786 | #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ |