comparison lib-src/emacsclient.c @ 83031:1d2f73785d9d

Merged in changes from CVS HEAD Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-57 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-58 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-59 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-60 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-61 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-62 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-63 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-64 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-65 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-66 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-67 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-68 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-69 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-71
author Karoly Lorentey <lorentey@elte.hu>
date Mon, 02 Feb 2004 19:19:08 +0000
parents 895e130cc8da 132739917566
children 03a73693678e
comparison
equal deleted inserted replaced
83030:895e130cc8da 83031:1d2f73785d9d
380 int 380 int
381 main (argc, argv) 381 main (argc, argv)
382 int argc; 382 int argc;
383 char **argv; 383 char **argv;
384 { 384 {
385 char *system_name;
386 int system_name_length;
387 int s, i, needlf = 0; 385 int s, i, needlf = 0;
388 FILE *out, *in; 386 FILE *out, *in;
389 struct sockaddr_un server; 387 struct sockaddr_un server;
390 char *cwd, *str; 388 char *cwd, *str;
391 char string[BUFSIZ]; 389 char string[BUFSIZ];
416 } 414 }
417 415
418 server.sun_family = AF_UNIX; 416 server.sun_family = AF_UNIX;
419 417
420 { 418 {
421 char *dot;
422 system_name_length = 32;
423
424 while (1)
425 {
426 system_name = (char *) xmalloc (system_name_length + 1);
427
428 /* system_name must be null-terminated string. */
429 system_name[system_name_length] = '\0';
430
431 if (gethostname (system_name, system_name_length) == 0)
432 break;
433
434 free (system_name);
435 system_name_length *= 2;
436 }
437
438 /* We always use the non-dotted host name, for simplicity. */
439 dot = index (system_name, '.');
440 if (dot)
441 *dot = '\0';
442 }
443
444 {
445 int sock_status = 0; 419 int sock_status = 0;
446 int default_sock = !socket_name; 420 int default_sock = !socket_name;
447 int saved_errno = 0; 421 int saved_errno = 0;
448 422
449 if (default_sock) 423 char *server_name = "server";
424
425 if (socket_name && !index (socket_name, '/') && !index (socket_name, '\\'))
426 { /* socket_name is a file name component. */
427 server_name = socket_name;
428 socket_name = NULL;
429 default_sock = 1; /* Try both UIDs. */
430 }
431
432 if (default_sock)
450 { 433 {
451 socket_name = alloca (system_name_length + 100); 434 socket_name = alloca (100 + strlen (server_name));
452 sprintf (socket_name, "/tmp/emacs%d-%s/server", 435 sprintf (socket_name, "/tmp/emacs%d/%s",
453 (int) geteuid (), system_name); 436 (int) geteuid (), server_name);
454 } 437 }
455 438
456 if (strlen (socket_name) < sizeof (server.sun_path)) 439 if (strlen (socket_name) < sizeof (server.sun_path))
457 strcpy (server.sun_path, socket_name); 440 strcpy (server.sun_path, socket_name);
458 else 441 else
482 struct passwd *pw = getpwnam (user_name); 465 struct passwd *pw = getpwnam (user_name);
483 466
484 if (pw && (pw->pw_uid != geteuid ())) 467 if (pw && (pw->pw_uid != geteuid ()))
485 { 468 {
486 /* We're running under su, apparently. */ 469 /* We're running under su, apparently. */
487 sprintf (socket_name, "/tmp/emacs%d-%s/server", 470 socket_name = alloca (100 + strlen (server_name));
488 (int) pw->pw_uid, system_name); 471 sprintf (socket_name, "/tmp/emacs%d/%s",
472 (int) pw->pw_uid, server_name);
489 473
490 if (strlen (socket_name) < sizeof (server.sun_path)) 474 if (strlen (socket_name) < sizeof (server.sun_path))
491 strcpy (server.sun_path, socket_name); 475 strcpy (server.sun_path, socket_name);
492 else 476 else
493 { 477 {