summaryrefslogtreecommitdiff
path: root/lib-src/emacsclient.c
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2004-01-27 23:04:52 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2004-01-27 23:04:52 +0000
commit114199ee101f7d497ef48567823e4a592f9e424f (patch)
tree121a88aafa2a87259b0a280bb3e48ecfc1141cb3 /lib-src/emacsclient.c
parent3aa4d3a0cb61edf55ed351143c19c28875f3266f (diff)
downloademacs-114199ee101f7d497ef48567823e4a592f9e424f.tar.gz
(main): Don't use the hostname in the socket name.
Look for relative socket names in the /tmp dir rather than in cwd.
Diffstat (limited to 'lib-src/emacsclient.c')
-rw-r--r--lib-src/emacsclient.c45
1 files changed, 14 insertions, 31 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 3ae33f72a18..a3a73d9e067 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -299,8 +299,6 @@ main (argc, argv)
int argc;
char **argv;
{
- char *system_name;
- int system_name_length;
int s, i, needlf = 0;
FILE *out, *in;
struct sockaddr_un server;
@@ -333,39 +331,23 @@ main (argc, argv)
server.sun_family = AF_UNIX;
{
- char *dot;
- system_name_length = 32;
-
- while (1)
- {
- system_name = (char *) xmalloc (system_name_length + 1);
-
- /* system_name must be null-terminated string. */
- system_name[system_name_length] = '\0';
-
- if (gethostname (system_name, system_name_length) == 0)
- break;
-
- free (system_name);
- system_name_length *= 2;
- }
-
- /* We always use the non-dotted host name, for simplicity. */
- dot = index (system_name, '.');
- if (dot)
- *dot = '\0';
- }
-
- {
int sock_status = 0;
int default_sock = !socket_name;
int saved_errno;
+ char *server_name = "server";
+
+ if (socket_name && !index (socket_name, '/') && !index (socket_name, '\\'))
+ { /* socket_name is a file name component. */
+ server_name = socket_name;
+ socket_name = NULL;
+ default_sock = 1; /* Try both UIDs. */
+ }
if (default_sock)
{
- socket_name = alloca (system_name_length + 100);
- sprintf (socket_name, "/tmp/emacs%d-%s/server",
- (int) geteuid (), system_name);
+ socket_name = alloca (100 + strlen (server_name));
+ sprintf (socket_name, "/tmp/emacs%d/%s",
+ (int) geteuid (), server_name);
}
if (strlen (socket_name) < sizeof (server.sun_path))
@@ -399,8 +381,9 @@ main (argc, argv)
if (pw && (pw->pw_uid != geteuid ()))
{
/* We're running under su, apparently. */
- sprintf (socket_name, "/tmp/emacs%d-%s/server",
- (int) pw->pw_uid, system_name);
+ socket_name = alloca (100 + strlen (server_name));
+ sprintf (socket_name, "/tmp/emacs%d/%s",
+ (int) pw->pw_uid, server_name);
if (strlen (socket_name) < sizeof (server.sun_path))
strcpy (server.sun_path, socket_name);