Mercurial > hg > xemacs-beta
diff lib-src/gnuclient.c @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | ec9a17fef872 |
children | c7528f8e288d |
line wrap: on
line diff
--- a/lib-src/gnuclient.c Mon Aug 13 09:00:04 2007 +0200 +++ b/lib-src/gnuclient.c Mon Aug 13 09:02:59 2007 +0200 @@ -52,8 +52,7 @@ #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \ !defined(INTERNET_DOMAIN_SOCKETS) -int -main (int argc, char *argv[]) +main () { fprintf (stderr, "Sorry, the Emacs server is only " "supported on systems that have\n"); @@ -66,67 +65,6 @@ static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */ static char *cp = NULL; /* ptr into valid bit of cwd above */ -#ifdef GNUATTACH -#include <signal.h> - -static pid_t emacs_pid; /* Process id for emacs process */ - -void tell_emacs_to_resume(int sig) -{ - char buffer[GSERV_BUFSZ+1]; - int s; /* socket / msqid to server */ - int connect_type; /* CONN_UNIX, CONN_INTERNET, or - * CONN_IPC */ - - /* Why is SYSV so retarded? */ - /* We want emacs to realize that we are resuming */ - signal(SIGCONT, tell_emacs_to_resume); - - connect_type = make_connection (NULL, (u_short) 0, &s); - - sprintf(buffer,"(server-eval '(resume-pid-console %d))", getpid()); - send_string(s, buffer); - -#ifdef SYSV_IPC - if (connect_type == (int) CONN_IPC) - disconnect_from_ipc_server (s, msgp, FALSE); -#else /* !SYSV_IPC */ - if (connect_type != (int) CONN_IPC) - disconnect_from_server (s, FALSE); -#endif /* !SYSV_IPC */ -} - -void pass_signal_to_emacs(int sig) -{ - if (kill(emacs_pid, sig) == -1) { - fprintf(stderr, "gnuattach: Could not pass signal to emacs process\n"); - exit(1); - } -} - -void initialize_signals() -{ - /* Set up signal handler to pass relevant signals to emacs process */ - signal(SIGHUP, pass_signal_to_emacs); - signal(SIGQUIT, pass_signal_to_emacs); - signal(SIGILL, pass_signal_to_emacs); - signal(SIGTRAP, pass_signal_to_emacs); - signal(SIGSEGV, pass_signal_to_emacs); - signal(SIGPIPE, pass_signal_to_emacs); - signal(SIGTERM, pass_signal_to_emacs); -#ifdef SIGBUS - signal(SIGBUS, pass_signal_to_emacs); -#endif -#ifdef SIGIOT - signal(SIGIOT, pass_signal_to_emacs); -#endif - - /* We want emacs to realize that we are resuming */ - signal(SIGCONT, tell_emacs_to_resume); -} - -#endif /* GNUATTACH */ - /* get_current_working_directory -- return the cwd. @@ -188,11 +126,11 @@ } /* filename_expand */ -int -main (int argc, char *argv[]) +void +main (int argc, char **argv) { int starting_line = 1; /* line to start editing at */ - char command[MAXPATHLEN+50]; /* emacs command buffer */ + char command[MAXPATHLEN+50]; /* emacs command buffer */ char fullpath[MAXPATHLEN+1]; /* full pathname to file */ #ifndef GNUATTACH int qflg = 0; /* quick edit, don't wait for @@ -216,7 +154,6 @@ #endif /* SYSV_IPC */ #ifdef GNUATTACH char *tty; - char buffer[GSERV_BUFSZ+1]; /* buffer to read pid */ #endif #ifdef INTERNET_DOMAIN_SOCKETS @@ -228,7 +165,11 @@ while ((c = getopt (argc, argv, #ifdef INTERNET_DOMAIN_SOCKETS +# ifdef GNUATTACH + "h:p:r" +# else "h:p:r:q" +# endif #else /* !INTERNET_DOMAIN_SOCKETS */ # ifdef GNUATTACH "" @@ -267,8 +208,13 @@ { fprintf (stderr, #ifdef INTERNET_DOMAIN_SOCKETS +# ifdef GNUATTACH + "usage: %s [-h hostname] [-p port] [-r pathname] " + "[[+line] path] ...\n", +# else "usage: %s [-q] [-h hostname] [-p port] [-r pathname] " "[[+line] path] ...\n", +# endif #else /* !INTERNET_DOMAIN_SOCKETS */ # ifdef GNUATTACH "usage: %s [[+line] path] ...\n", @@ -287,35 +233,9 @@ fprintf (stderr, "%s: Not connected to a tty", progname); exit (1); } - - /* This next stuff added in an attempt to make handling of - the tty do the right thing when dealing with signals. - Idea is to pass all the appropriate signals to the emacs process - */ - - connect_type = make_connection (NULL, (u_short) 0, &s); +#endif - send_string(s,"(server-eval '(emacs-pid))"); - send_string(s,EOT_STR); - - if (read_line(s,buffer) == 0) { - fprintf(stderr, "%s: Could not establish emacs procces id\n",progname); - exit(1); - } - /* don't do disconnect_from_server becasue we have already read data, - and disconnect doesn't do anything else - */ -#ifdef SYSV_IPC - if (connect_type == (int) CONN_IPC) - disconnect_from_ipc_server (s, msgp, FALSE); -#endif /* !SYSV_IPC */ - - emacs_pid = (pid_t)atol(buffer); - initialize_signals(); - -#endif /*GNUATTACH */ - -#if defined(INTERNET_DOMAIN_SOCKETS) && !defined(GNUATTACH) +#ifdef INTERNET_DOMAIN_SOCKETS connect_type = make_connection (hostarg, portarg, &s); #else connect_type = make_connection (NULL, (u_short) 0, &s); @@ -367,8 +287,7 @@ fprintf (stderr, "%s: unknown terminal type\n", progname); exit (1); } - sprintf (command, "(server-tty-edit-files \"%s\" \"%s\" %d '(", - tty, ptr, getpid()); + sprintf (command, "(server-tty-edit-files \"%s\" \"%s\" '(", tty, ptr); send_string (s, command); #else if (qflg) @@ -411,7 +330,7 @@ disconnect_from_server (s, FALSE); #endif /* !SYSV_IPC */ - return 0; + exit (0); } /* main */