Mercurial > hg > xemacs-beta
comparison lib-src/gnuclient.c @ 108:360340f9fd5f r20-1b6
Import from CVS: tag r20-1b6
| author | cvs |
|---|---|
| date | Mon, 13 Aug 2007 09:18:39 +0200 |
| parents | c7528f8e288d |
| children | 538048ae2ab8 |
comparison
equal
deleted
inserted
replaced
| 107:523141596bda | 108:360340f9fd5f |
|---|---|
| 63 } /* main */ | 63 } /* main */ |
| 64 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */ | 64 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */ |
| 65 | 65 |
| 66 static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */ | 66 static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */ |
| 67 static char *cp = NULL; /* ptr into valid bit of cwd above */ | 67 static char *cp = NULL; /* ptr into valid bit of cwd above */ |
| 68 | |
| 69 #ifdef GNUATTACH | |
| 70 #include <signal.h> | |
| 71 | |
| 72 static pid_t emacs_pid; /* Process id for emacs process */ | |
| 73 | |
| 74 void tell_emacs_to_resume(int sig) | |
| 75 { | |
| 76 char buffer[GSERV_BUFSZ+1]; | |
| 77 int s; /* socket / msqid to server */ | |
| 78 int connect_type; /* CONN_UNIX, CONN_INTERNET, or | |
| 79 * CONN_IPC */ | |
| 80 | |
| 81 /* Why is SYSV so retarded? */ | |
| 82 /* We want emacs to realize that we are resuming */ | |
| 83 signal(SIGCONT, tell_emacs_to_resume); | |
| 84 | |
| 85 connect_type = make_connection (NULL, (u_short) 0, &s); | |
| 86 | |
| 87 sprintf(buffer,"(server-eval '(resume-pid-console %d))", getpid()); | |
| 88 send_string(s, buffer); | |
| 89 | |
| 90 #ifdef SYSV_IPC | |
| 91 if (connect_type == (int) CONN_IPC) | |
| 92 disconnect_from_ipc_server (s, msgp, FALSE); | |
| 93 #else /* !SYSV_IPC */ | |
| 94 if (connect_type != (int) CONN_IPC) | |
| 95 disconnect_from_server (s, FALSE); | |
| 96 #endif /* !SYSV_IPC */ | |
| 97 } | |
| 98 | |
| 99 void pass_signal_to_emacs(int sig) | |
| 100 { | |
| 101 if (kill(emacs_pid, sig) == -1) { | |
| 102 fprintf(stderr, "gnuattach: Could not pass signal to emacs process\n"); | |
| 103 exit(1); | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 void initialize_signals() | |
| 108 { | |
| 109 /* Set up signal handler to pass relevant signals to emacs process */ | |
| 110 signal(SIGHUP, pass_signal_to_emacs); | |
| 111 signal(SIGQUIT, pass_signal_to_emacs); | |
| 112 signal(SIGILL, pass_signal_to_emacs); | |
| 113 signal(SIGTRAP, pass_signal_to_emacs); | |
| 114 signal(SIGSEGV, pass_signal_to_emacs); | |
| 115 signal(SIGPIPE, pass_signal_to_emacs); | |
| 116 signal(SIGTERM, pass_signal_to_emacs); | |
| 117 #ifdef SIGBUS | |
| 118 signal(SIGBUS, pass_signal_to_emacs); | |
| 119 #endif | |
| 120 #ifdef SIGIOT | |
| 121 signal(SIGIOT, pass_signal_to_emacs); | |
| 122 #endif | |
| 123 | |
| 124 /* We want emacs to realize that we are resuming */ | |
| 125 signal(SIGCONT, tell_emacs_to_resume); | |
| 126 } | |
| 127 | |
| 128 #endif /* GNUATTACH */ | |
| 68 | 129 |
| 69 | 130 |
| 70 /* | 131 /* |
| 71 get_current_working_directory -- return the cwd. | 132 get_current_working_directory -- return the cwd. |
| 72 */ | 133 */ |
| 129 | 190 |
| 130 int | 191 int |
| 131 main (int argc, char *argv[]) | 192 main (int argc, char *argv[]) |
| 132 { | 193 { |
| 133 int starting_line = 1; /* line to start editing at */ | 194 int starting_line = 1; /* line to start editing at */ |
| 134 char command[MAXPATHLEN+50]; /* emacs command buffer */ | 195 char command[MAXPATHLEN+50]; /* emacs command buffer */ |
| 135 char fullpath[MAXPATHLEN+1]; /* full pathname to file */ | 196 char fullpath[MAXPATHLEN+1]; /* full pathname to file */ |
| 136 #ifndef GNUATTACH | 197 #ifndef GNUATTACH |
| 137 int qflg = 0; /* quick edit, don't wait for | 198 int qflg = 0; /* quick edit, don't wait for |
| 138 * user to finish */ | 199 * user to finish */ |
| 139 #endif | 200 #endif |
| 153 #ifdef SYSV_IPC | 214 #ifdef SYSV_IPC |
| 154 struct msgbuf *msgp; /* message */ | 215 struct msgbuf *msgp; /* message */ |
| 155 #endif /* SYSV_IPC */ | 216 #endif /* SYSV_IPC */ |
| 156 #ifdef GNUATTACH | 217 #ifdef GNUATTACH |
| 157 char *tty; | 218 char *tty; |
| 219 char buffer[GSERV_BUFSZ+1]; /* buffer to read pid */ | |
| 158 #endif | 220 #endif |
| 159 | 221 |
| 160 #ifdef INTERNET_DOMAIN_SOCKETS | 222 #ifdef INTERNET_DOMAIN_SOCKETS |
| 161 memset (remotepath, 0, sizeof (remotepath)); | 223 memset (remotepath, 0, sizeof (remotepath)); |
| 162 #endif /* INTERNET_DOMAIN_SOCKETS */ | 224 #endif /* INTERNET_DOMAIN_SOCKETS */ |
| 164 progname = argv[0]; | 226 progname = argv[0]; |
| 165 | 227 |
| 166 while ((c = getopt (argc, argv, | 228 while ((c = getopt (argc, argv, |
| 167 | 229 |
| 168 #ifdef INTERNET_DOMAIN_SOCKETS | 230 #ifdef INTERNET_DOMAIN_SOCKETS |
| 169 # ifdef GNUATTACH | |
| 170 "h:p:r" | |
| 171 # else | |
| 172 "h:p:r:q" | 231 "h:p:r:q" |
| 173 # endif | |
| 174 #else /* !INTERNET_DOMAIN_SOCKETS */ | 232 #else /* !INTERNET_DOMAIN_SOCKETS */ |
| 175 # ifdef GNUATTACH | 233 # ifdef GNUATTACH |
| 176 "" | 234 "" |
| 177 # else | 235 # else |
| 178 "q" | 236 "q" |
| 207 | 265 |
| 208 if (errflg) | 266 if (errflg) |
| 209 { | 267 { |
| 210 fprintf (stderr, | 268 fprintf (stderr, |
| 211 #ifdef INTERNET_DOMAIN_SOCKETS | 269 #ifdef INTERNET_DOMAIN_SOCKETS |
| 212 # ifdef GNUATTACH | |
| 213 "usage: %s [-h hostname] [-p port] [-r pathname] " | |
| 214 "[[+line] path] ...\n", | |
| 215 # else | |
| 216 "usage: %s [-q] [-h hostname] [-p port] [-r pathname] " | 270 "usage: %s [-q] [-h hostname] [-p port] [-r pathname] " |
| 217 "[[+line] path] ...\n", | 271 "[[+line] path] ...\n", |
| 218 # endif | |
| 219 #else /* !INTERNET_DOMAIN_SOCKETS */ | 272 #else /* !INTERNET_DOMAIN_SOCKETS */ |
| 220 # ifdef GNUATTACH | 273 # ifdef GNUATTACH |
| 221 "usage: %s [[+line] path] ...\n", | 274 "usage: %s [[+line] path] ...\n", |
| 222 # else | 275 # else |
| 223 "usage: %s [-q] [[+line] path] ...\n", | 276 "usage: %s [-q] [[+line] path] ...\n", |
| 232 if (!tty) | 285 if (!tty) |
| 233 { | 286 { |
| 234 fprintf (stderr, "%s: Not connected to a tty", progname); | 287 fprintf (stderr, "%s: Not connected to a tty", progname); |
| 235 exit (1); | 288 exit (1); |
| 236 } | 289 } |
| 237 #endif | 290 |
| 238 | 291 /* This next stuff added in an attempt to make handling of |
| 239 #ifdef INTERNET_DOMAIN_SOCKETS | 292 the tty do the right thing when dealing with signals. |
| 293 Idea is to pass all the appropriate signals to the emacs process | |
| 294 */ | |
| 295 | |
| 296 connect_type = make_connection (NULL, (u_short) 0, &s); | |
| 297 | |
| 298 send_string(s,"(server-eval '(emacs-pid))"); | |
| 299 send_string(s,EOT_STR); | |
| 300 | |
| 301 if (read_line(s,buffer) == 0) { | |
| 302 fprintf(stderr, "%s: Could not establish emacs procces id\n",progname); | |
| 303 exit(1); | |
| 304 } | |
| 305 /* don't do disconnect_from_server becasue we have already read data, | |
| 306 and disconnect doesn't do anything else | |
| 307 */ | |
| 308 #ifdef SYSV_IPC | |
| 309 if (connect_type == (int) CONN_IPC) | |
| 310 disconnect_from_ipc_server (s, msgp, FALSE); | |
| 311 #endif /* !SYSV_IPC */ | |
| 312 | |
| 313 emacs_pid = (pid_t)atol(buffer); | |
| 314 initialize_signals(); | |
| 315 | |
| 316 #endif /*GNUATTACH */ | |
| 317 | |
| 318 #if defined(INTERNET_DOMAIN_SOCKETS) && !defined(GNUATTACH) | |
| 240 connect_type = make_connection (hostarg, portarg, &s); | 319 connect_type = make_connection (hostarg, portarg, &s); |
| 241 #else | 320 #else |
| 242 connect_type = make_connection (NULL, (u_short) 0, &s); | 321 connect_type = make_connection (NULL, (u_short) 0, &s); |
| 243 #endif | 322 #endif |
| 244 | 323 |
| 286 if (!ptr) | 365 if (!ptr) |
| 287 { | 366 { |
| 288 fprintf (stderr, "%s: unknown terminal type\n", progname); | 367 fprintf (stderr, "%s: unknown terminal type\n", progname); |
| 289 exit (1); | 368 exit (1); |
| 290 } | 369 } |
| 291 sprintf (command, "(server-tty-edit-files \"%s\" \"%s\" '(", tty, ptr); | 370 sprintf (command, "(server-tty-edit-files \"%s\" \"%s\" %d '(", |
| 371 tty, ptr, getpid()); | |
| 292 send_string (s, command); | 372 send_string (s, command); |
| 293 #else | 373 #else |
| 294 if (qflg) | 374 if (qflg) |
| 295 { | 375 { |
| 296 send_string (s, "(server-edit-files-quickly '("); | 376 send_string (s, "(server-edit-files-quickly '("); |
