diff options
Diffstat (limited to 'lib-src/emacsclient.c')
| -rw-r--r-- | lib-src/emacsclient.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index e8ffbe7c562..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", |
| @@ -1476,7 +1478,7 @@ start_daemon_and_retry_set_socket (void) | |||
| 1476 | else if (dpid < 0) | 1478 | else if (dpid < 0) |
| 1477 | { | 1479 | { |
| 1478 | fprintf (stderr, "Error: Cannot fork!\n"); | 1480 | fprintf (stderr, "Error: Cannot fork!\n"); |
| 1479 | exit (1); | 1481 | exit (EXIT_FAILURE); |
| 1480 | } | 1482 | } |
| 1481 | else | 1483 | else |
| 1482 | { | 1484 | { |
| @@ -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]; |
| @@ -1576,8 +1579,6 @@ main (int argc, char **argv) | |||
| 1576 | int i; | 1579 | int i; |
| 1577 | for (i = 0; environ[i]; i++) | 1580 | for (i = 0; environ[i]; i++) |
| 1578 | { | 1581 | { |
| 1579 | char *name = xstrdup (environ[i]); | ||
| 1580 | char *value = strchr (name, '='); | ||
| 1581 | send_to_emacs (emacs_socket, "-env "); | 1582 | send_to_emacs (emacs_socket, "-env "); |
| 1582 | quote_argument (emacs_socket, environ[i]); | 1583 | quote_argument (emacs_socket, environ[i]); |
| 1583 | send_to_emacs (emacs_socket, " "); | 1584 | send_to_emacs (emacs_socket, " "); |
| @@ -1707,7 +1708,8 @@ main (int argc, char **argv) | |||
| 1707 | fsync (1); | 1708 | fsync (1); |
| 1708 | 1709 | ||
| 1709 | /* Now, wait for an answer and print any messages. */ | 1710 | /* Now, wait for an answer and print any messages. */ |
| 1710 | while ((rl = recv (emacs_socket, string, BUFSIZ, 0)) > 0) | 1711 | while (exit_status == EXIT_SUCCESS |
| 1712 | && (rl = recv (emacs_socket, string, BUFSIZ, 0)) > 0) | ||
| 1711 | { | 1713 | { |
| 1712 | char *p; | 1714 | char *p; |
| 1713 | string[rl] = '\0'; | 1715 | string[rl] = '\0'; |
| @@ -1746,6 +1748,7 @@ main (int argc, char **argv) | |||
| 1746 | printf ("\n"); | 1748 | printf ("\n"); |
| 1747 | fprintf (stderr, "*ERROR*: %s", str); | 1749 | fprintf (stderr, "*ERROR*: %s", str); |
| 1748 | 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; | ||
| 1749 | } | 1752 | } |
| 1750 | #ifdef SIGSTOP | 1753 | #ifdef SIGSTOP |
| 1751 | else if (strprefix ("-suspend ", string)) | 1754 | else if (strprefix ("-suspend ", string)) |
| @@ -1763,7 +1766,8 @@ main (int argc, char **argv) | |||
| 1763 | if (needlf) | 1766 | if (needlf) |
| 1764 | printf ("\n"); | 1767 | printf ("\n"); |
| 1765 | printf ("*ERROR*: Unknown message: %s", string); | 1768 | printf ("*ERROR*: Unknown message: %s", string); |
| 1766 | needlf = string[0] == '\0' ? needlf : string[strlen (string) - 1] != '\n'; | 1769 | needlf = string[0] |
| 1770 | == '\0' ? needlf : string[strlen (string) - 1] != '\n'; | ||
| 1767 | } | 1771 | } |
| 1768 | } | 1772 | } |
| 1769 | 1773 | ||
| @@ -1772,8 +1776,11 @@ main (int argc, char **argv) | |||
| 1772 | fflush (stdout); | 1776 | fflush (stdout); |
| 1773 | fsync (1); | 1777 | fsync (1); |
| 1774 | 1778 | ||
| 1779 | if (rl < 0) | ||
| 1780 | exit_status = EXIT_FAILURE; | ||
| 1781 | |||
| 1775 | CLOSE_SOCKET (emacs_socket); | 1782 | CLOSE_SOCKET (emacs_socket); |
| 1776 | return EXIT_SUCCESS; | 1783 | return exit_status; |
| 1777 | } | 1784 | } |
| 1778 | 1785 | ||
| 1779 | #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ | 1786 | #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ |