aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 0ff8f2e6a3b..51f94877af1 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -102,6 +102,12 @@ char *getcwd ();
102/* Name used to invoke this program. */ 102/* Name used to invoke this program. */
103char *progname; 103char *progname;
104 104
105/* The first argument to main. */
106int main_argc;
107
108/* The second argument to main. */
109char **main_argv;
110
105/* Nonzero means don't wait for a response from Emacs. --no-wait. */ 111/* Nonzero means don't wait for a response from Emacs. --no-wait. */
106int nowait = 0; 112int nowait = 0;
107 113
@@ -294,14 +300,12 @@ xmalloc (size)
294 defined-- exit with an errorcode. 300 defined-- exit with an errorcode.
295*/ 301*/
296void 302void
297fail (argc, argv) 303fail ()
298 int argc;
299 char **argv;
300{ 304{
301 if (alternate_editor) 305 if (alternate_editor)
302 { 306 {
303 int i = optind - 1; 307 int i = optind - 1;
304 execvp (alternate_editor, argv + i); 308 execvp (alternate_editor, main_argv + i);
305 return; 309 return;
306 } 310 }
307 else 311 else
@@ -603,7 +607,7 @@ window_change ()
603#endif /* not SunOS-style */ 607#endif /* not SunOS-style */
604#endif /* not BSD-style */ 608#endif /* not BSD-style */
605 609
606 if (width != 0 && height != 0) 610 if (emacs_pid && width && height)
607 kill (emacs_pid, SIGWINCH); 611 kill (emacs_pid, SIGWINCH);
608} 612}
609 613
@@ -721,7 +725,7 @@ copy_from_to (int in, int out, int sigio)
721 if (r < 0) 725 if (r < 0)
722 return 0; /* Error */ 726 return 0; /* Error */
723 727
724 if (sigio) 728 if (emacs_pid && sigio)
725 { 729 {
726 kill (emacs_pid, SIGIO); 730 kill (emacs_pid, SIGIO);
727 } 731 }
@@ -730,8 +734,10 @@ copy_from_to (int in, int out, int sigio)
730} 734}
731 735
732int 736int
733pty_conversation () 737pty_conversation (FILE *in)
734{ 738{
739 char *str;
740 char string[BUFSIZ];
735 fd_set set; 741 fd_set set;
736 742
737 in_conversation = 1; 743 in_conversation = 1;
@@ -742,6 +748,7 @@ pty_conversation ()
742 FD_ZERO (&set); 748 FD_ZERO (&set);
743 FD_SET (master, &set); 749 FD_SET (master, &set);
744 FD_SET (1, &set); 750 FD_SET (1, &set);
751 FD_SET (fileno (in), &set);
745 res = select (FD_SETSIZE, &set, NULL, NULL, NULL); 752 res = select (FD_SETSIZE, &set, NULL, NULL, NULL);
746 if (res < 0) 753 if (res < 0)
747 { 754 {
@@ -762,6 +769,24 @@ pty_conversation ()
762 if (! copy_from_to (1, master, 1)) 769 if (! copy_from_to (1, master, 1))
763 return 1; 770 return 1;
764 } 771 }
772 if (FD_ISSET (fileno (in), &set))
773 {
774 if (! emacs_pid)
775 {
776 /* Get the pid of the Emacs process.
777 XXX Is there is some nifty libc/kernel feature for doing this?
778 */
779 str = fgets (string, BUFSIZ, in);
780 if (! str)
781 {
782 reset_tty ();
783 fprintf (stderr, "%s: %s\n", progname, str);
784 fail ();
785 }
786
787 emacs_pid = atoi (str);
788 }
789 }
765 } 790 }
766 } 791 }
767 return 1; 792 return 1;
@@ -828,6 +853,8 @@ main (argc, argv)
828 char *cwd, *str; 853 char *cwd, *str;
829 char string[BUFSIZ]; 854 char string[BUFSIZ];
830 855
856 main_argc = argc;
857 main_argv = argv;
831 progname = argv[0]; 858 progname = argv[0];
832 859
833 /* Process options. */ 860 /* Process options. */
@@ -1087,19 +1114,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
1087 1114
1088 if (here) 1115 if (here)
1089 { 1116 {
1090 /* First of all, get the pid of the Emacs process. 1117 if (! pty_conversation (out))
1091 XXX Is there is some nifty libc/kernel feature for doing this?
1092 */
1093 str = fgets (string, BUFSIZ, in);
1094 emacs_pid = atoi (str);
1095 if (emacs_pid == 0)
1096 {
1097 reset_tty ();
1098 fprintf (stderr, "%s: %s\n", argv[0], str);
1099 fail (argc, argv);
1100 }
1101
1102 if (! pty_conversation ())
1103 { 1118 {
1104 reset_tty (); 1119 reset_tty ();
1105 fprintf (stderr, "%s: ", argv[0]); 1120 fprintf (stderr, "%s: ", argv[0]);