comparison lib-src/emacsclient.c @ 53543:fec82b542db2

(main): Save errno from socket_status.
author Andreas Schwab <schwab@suse.de>
date Thu, 08 Jan 2004 12:20:32 +0000
parents 189db7d9de05
children 8c55b1b400d5 82554ed1aed8
comparison
equal deleted inserted replaced
53542:8bfc55c02f6f 53543:fec82b542db2
356 *dot = '\0'; 356 *dot = '\0';
357 } 357 }
358 358
359 { 359 {
360 int sock_status = 0; 360 int sock_status = 0;
361 int saved_errno;
361 362
362 if (! socket_name) 363 if (! socket_name)
363 { 364 {
364 socket_name = alloca (system_name_length + 100); 365 socket_name = alloca (system_name_length + 100);
365 sprintf (socket_name, "/tmp/emacs%d-%s/server", 366 sprintf (socket_name, "/tmp/emacs%d-%s/server",
372 fprintf (stderr, "%s: socket-name %s too long", 373 fprintf (stderr, "%s: socket-name %s too long",
373 argv[0], socket_name); 374 argv[0], socket_name);
374 375
375 /* See if the socket exists, and if it's owned by us. */ 376 /* See if the socket exists, and if it's owned by us. */
376 sock_status = socket_status (server.sun_path); 377 sock_status = socket_status (server.sun_path);
378 saved_errno = errno;
377 if (sock_status) 379 if (sock_status)
378 { 380 {
379 /* Failing that, see if LOGNAME or USER exist and differ from 381 /* Failing that, see if LOGNAME or USER exist and differ from
380 our euid. If so, look for a socket based on the UID 382 our euid. If so, look for a socket based on the UID
381 associated with the name. This is reminiscent of the logic 383 associated with the name. This is reminiscent of the logic
392 { 394 {
393 /* We're running under su, apparently. */ 395 /* We're running under su, apparently. */
394 sprintf (server.sun_path, "/tmp/emacs%d-%s/server", 396 sprintf (server.sun_path, "/tmp/emacs%d-%s/server",
395 (int) pw->pw_uid, system_name); 397 (int) pw->pw_uid, system_name);
396 sock_status = socket_status (server.sun_path); 398 sock_status = socket_status (server.sun_path);
399 saved_errno = errno;
397 } 400 }
398 } 401 }
399 } 402 }
400 403
401 switch (sock_status) 404 switch (sock_status)
410 } 413 }
411 break; 414 break;
412 415
413 case 2: 416 case 2:
414 /* `stat' failed */ 417 /* `stat' failed */
415 if (errno == ENOENT) 418 if (saved_errno == ENOENT)
416 fprintf (stderr, 419 fprintf (stderr,
417 "%s: can't find socket; have you started the server?\n\ 420 "%s: can't find socket; have you started the server?\n\
418 To start the server in Emacs, type \"M-x server-start\".\n", 421 To start the server in Emacs, type \"M-x server-start\".\n",
419 argv[0]); 422 argv[0]);
420 else 423 else
421 fprintf (stderr, "%s: can't stat %s: %s\n", 424 fprintf (stderr, "%s: can't stat %s: %s\n",
422 argv[0], server.sun_path, strerror (errno)); 425 argv[0], server.sun_path, strerror (saved_errno));
423 fail (argc, argv); 426 fail (argc, argv);
424 break; 427 break;
425 } 428 }
426 } 429 }
427 430