aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index cfbf73a20c7..6cf07d35e8a 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1,5 +1,5 @@
1/* Client process that communicates with GNU Emacs acting as server. 1/* Client process that communicates with GNU Emacs acting as server.
2 Copyright (C) 1986, 1987, 1994, 1999, 2000, 2001, 2003 2 Copyright (C) 1986, 1987, 1994, 1999, 2000, 2001, 2003, 2004
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -438,9 +438,10 @@ main (argc, argv)
438 438
439 { 439 {
440 int sock_status = 0; 440 int sock_status = 0;
441 int default_sock = !socket_name;
441 int saved_errno = 0; 442 int saved_errno = 0;
442 443
443 if (! socket_name) 444 if (default_sock)
444 { 445 {
445 socket_name = alloca (system_name_length + 100); 446 socket_name = alloca (system_name_length + 100);
446 sprintf (socket_name, "/tmp/emacs%d-%s/server", 447 sprintf (socket_name, "/tmp/emacs%d-%s/server",
@@ -459,7 +460,7 @@ main (argc, argv)
459 /* See if the socket exists, and if it's owned by us. */ 460 /* See if the socket exists, and if it's owned by us. */
460 sock_status = socket_status (server.sun_path); 461 sock_status = socket_status (server.sun_path);
461 saved_errno = errno; 462 saved_errno = errno;
462 if (sock_status) 463 if (sock_status && default_sock)
463 { 464 {
464 /* Failing that, see if LOGNAME or USER exist and differ from 465 /* Failing that, see if LOGNAME or USER exist and differ from
465 our euid. If so, look for a socket based on the UID 466 our euid. If so, look for a socket based on the UID
@@ -476,8 +477,18 @@ main (argc, argv)
476 if (pw && (pw->pw_uid != geteuid ())) 477 if (pw && (pw->pw_uid != geteuid ()))
477 { 478 {
478 /* We're running under su, apparently. */ 479 /* We're running under su, apparently. */
479 sprintf (server.sun_path, "/tmp/emacs%d-%s/server", 480 sprintf (socket_name, "/tmp/emacs%d-%s/server",
480 (int) pw->pw_uid, system_name); 481 (int) pw->pw_uid, system_name);
482
483 if (strlen (socket_name) < sizeof (server.sun_path))
484 strcpy (server.sun_path, socket_name);
485 else
486 {
487 fprintf (stderr, "%s: socket-name %s too long",
488 argv[0], socket_name);
489 exit (1);
490 }
491
481 sock_status = socket_status (server.sun_path); 492 sock_status = socket_status (server.sun_path);
482 saved_errno = errno; 493 saved_errno = errno;
483 } 494 }