comparison src/process.c @ 1594:b476a97ad17e

* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c: Added VMS changes from Roland Roberts. * process.c (read_process_output): Save, widen, insert the process output, and then restore the restriction if inserting text outside the visible region. * process.c (Fstart_process): Establish an unwind-protect to remove PROC from the process list if an error occurs while starting it. (start_process_unwind): New function to help with that. (create_process): There's no need to explicitly call remove_process if the fork fails; the record_unwind_protect in Fstart_process will take care of it. * process.c (wait_reading_process_input): Test the C preprocessor symbol "ultrix", not "__ultrix__" to see if we should ignore ENOMEM errors from select. * process.c (process_send_signal): On systems which have both the TIOCGETC and TCGETA ioctls, just use the former. * s/bsd4-2.h, s/bsd4-3.h: #define SIGNALS_VIA_CHARACTERS. * process.c (process_send_signal): Put all the code for sending signals via characters in a #ifdef SIGNALS_VIA_CHARACTERS. Decide whether to use the Berkeley-style or SYSV-style ioctls by seeing which ioctl commands are #defined. * process.c (process_send_signal): Doc fix.
author Jim Blandy <jimb@redhat.com>
date Mon, 16 Nov 1992 00:53:26 +0000
parents 52a69b6a8f96
children 05e84e6c7d04
comparison
equal deleted inserted replaced
1593:a3862c6dfcd0 1594:b476a97ad17e
160 #endif /* no WAITTYPE */ 160 #endif /* no WAITTYPE */
161 #else /* VMS */ 161 #else /* VMS */
162 162
163 /* For the CMU PTY driver + */ 163 /* For the CMU PTY driver + */
164 #define DCL_PROMPT "$ " 164 #define DCL_PROMPT "$ "
165 165 /* This is a hack. I have no idea what needs to go here, but this */
166 /* will get it to compile. We can fix it later. rbr */
167 #define WAITTYPE int
166 #include <ssdef.h> 168 #include <ssdef.h>
167 #include <iodef.h> 169 #include <iodef.h>
168 #include <clidef.h> 170 #include <clidef.h>
169 #include "vmsproc.h" 171 #include "vmsproc.h"
170 #endif /* VMS */ 172 #endif /* VMS */
347 349
348 decode_status (status, &symbol, &code, &coredump); 350 decode_status (status, &symbol, &code, &coredump);
349 351
350 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop)) 352 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
351 { 353 {
354 #ifndef VMS
352 string = build_string (code < NSIG ? sys_siglist[code] : "unknown"); 355 string = build_string (code < NSIG ? sys_siglist[code] : "unknown");
356 #else
357 string = build_string (code < NSIG ? sys_errlist[code] : "unknown");
358 #endif
353 string2 = build_string (coredump ? " (core dumped)\n" : "\n"); 359 string2 = build_string (coredump ? " (core dumped)\n" : "\n");
354 XSTRING (string)->data[0] = DOWNCASE (XSTRING (string)->data[0]); 360 XSTRING (string)->data[0] = DOWNCASE (XSTRING (string)->data[0]);
355 return concat2 (string, string2); 361 return concat2 (string, string2);
356 } 362 }
357 else if (EQ (symbol, Qexit)) 363 else if (EQ (symbol, Qexit))
845 { 851 {
846 Lisp_Object tem; 852 Lisp_Object tem;
847 tem = Fcar (Fcdr (p->status)); 853 tem = Fcar (Fcdr (p->status));
848 #ifdef VMS 854 #ifdef VMS
849 if (XINT (tem) < NSIG) 855 if (XINT (tem) < NSIG)
850 write_string (sys_siglist [XINT (tem)], -1); 856 write_string (sys_errlist [XINT (tem)], -1);
851 else 857 else
852 #endif 858 #endif
853 Fprinc (symbol, Qnil); 859 Fprinc (symbol, Qnil);
854 } 860 }
855 else if (NETCONN_P (proc)) 861 else if (NETCONN_P (proc))
928 () 934 ()
929 { 935 {
930 return Fmapcar (Qcdr, Vprocess_alist); 936 return Fmapcar (Qcdr, Vprocess_alist);
931 } 937 }
932 938
939 /* Starting asynchronous inferior processes. */
940
941 static Lisp_Object start_process_unwind ();
942
933 DEFUN ("start-process", Fstart_process, Sstart_process, 3, MANY, 0, 943 DEFUN ("start-process", Fstart_process, Sstart_process, 3, MANY, 0,
934 "Start a program in a subprocess. Return the process object for it.\n\ 944 "Start a program in a subprocess. Return the process object for it.\n\
935 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS\n\ 945 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS\n\
936 NAME is name for process. It is modified if necessary to make it unique.\n\ 946 NAME is name for process. It is modified if necessary to make it unique.\n\
937 BUFFER is the buffer or (buffer-name) to associate with the process.\n\ 947 BUFFER is the buffer or (buffer-name) to associate with the process.\n\
951 int len; 961 int len;
952 #else 962 #else
953 register unsigned char **new_argv; 963 register unsigned char **new_argv;
954 #endif 964 #endif
955 register int i; 965 register int i;
966 int count = specpdl_ptr - specpdl;
956 967
957 buffer = args[1]; 968 buffer = args[1];
958 if (!NILP (buffer)) 969 if (!NILP (buffer))
959 buffer = Fget_buffer_create (buffer); 970 buffer = Fget_buffer_create (buffer);
960 971
982 tem = args[i]; 993 tem = args[i];
983 CHECK_STRING (tem, i); 994 CHECK_STRING (tem, i);
984 strcat (new_argv, " "); 995 strcat (new_argv, " ");
985 strcat (new_argv, XSTRING (tem)->data); 996 strcat (new_argv, XSTRING (tem)->data);
986 } 997 }
998 /* Need to add code here to check for program existence on VMS */
999
987 #else /* not VMS */ 1000 #else /* not VMS */
988 new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *)); 1001 new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *));
989 1002
990 for (i = 3; i < nargs; i++) 1003 for (i = 3; i < nargs; i++)
991 { 1004 {
1006 new_argv[0] = XSTRING (tem)->data; 1019 new_argv[0] = XSTRING (tem)->data;
1007 } 1020 }
1008 #endif /* not VMS */ 1021 #endif /* not VMS */
1009 1022
1010 proc = make_process (name); 1023 proc = make_process (name);
1024 /* If an error occurs and we can't start the process, we want to
1025 remove it from the process list. This means that each error
1026 check in create_process doesn't need to call remove_process
1027 itself; it's all taken care of here. */
1028 record_unwind_protect (start_process_unwind, proc);
1011 1029
1012 XPROCESS (proc)->childp = Qt; 1030 XPROCESS (proc)->childp = Qt;
1013 XPROCESS (proc)->command_channel_p = Qnil; 1031 XPROCESS (proc)->command_channel_p = Qnil;
1014 XPROCESS (proc)->buffer = buffer; 1032 XPROCESS (proc)->buffer = buffer;
1015 XPROCESS (proc)->sentinel = Qnil; 1033 XPROCESS (proc)->sentinel = Qnil;
1016 XPROCESS (proc)->filter = Qnil; 1034 XPROCESS (proc)->filter = Qnil;
1017 XPROCESS (proc)->command = Flist (nargs - 2, args + 2); 1035 XPROCESS (proc)->command = Flist (nargs - 2, args + 2);
1018 1036
1019 create_process (proc, new_argv); 1037 create_process (proc, new_argv);
1020 1038
1021 return proc; 1039 return unbind_to (count, proc);
1022 } 1040 }
1041
1042 /* This function is the unwind_protect form for Fstart_process. If
1043 PROC doesn't have its pid set, then we know someone has signalled
1044 an error and the process wasn't started successfully, so we should
1045 remove it from the process list. */
1046 static Lisp_Object
1047 start_process_unwind (proc)
1048 Lisp_Object proc;
1049 {
1050 if (XTYPE (proc) != Lisp_Process)
1051 abort ();
1052
1053 /* Was PROC started successfully? */
1054 if (XPROCESS (proc)->pid <= 0)
1055 remove_process (proc);
1056
1057 return Qnil;
1058 }
1059
1023 1060
1024 SIGTYPE 1061 SIGTYPE
1025 create_process_1 (signo) 1062 create_process_1 (signo)
1026 int signo; 1063 int signo;
1027 { 1064 {
1280 } 1317 }
1281 environ = save_environ; 1318 environ = save_environ;
1282 } 1319 }
1283 1320
1284 if (pid < 0) 1321 if (pid < 0)
1285 { 1322 report_file_error ("Doing vfork", Qnil);
1286 remove_process (process); 1323
1287 report_file_error ("Doing vfork", Qnil);
1288 }
1289
1290 XFASTINT (XPROCESS (process)->pid) = pid; 1324 XFASTINT (XPROCESS (process)->pid) = pid;
1291 1325
1292 FD_SET (inchannel, &input_wait_mask); 1326 FD_SET (inchannel, &input_wait_mask);
1293 1327
1294 /* If the subfork execv fails, and it exits, 1328 /* If the subfork execv fails, and it exits,
1739 break; 1773 break;
1740 if (nfds < 0) 1774 if (nfds < 0)
1741 { 1775 {
1742 if (xerrno == EINTR) 1776 if (xerrno == EINTR)
1743 FD_ZERO (&Available); 1777 FD_ZERO (&Available);
1744 #ifdef __ultrix__ 1778 #ifdef ultrix
1745 /* Ultrix select seems to return ENOMEM when it is interrupted. 1779 /* Ultrix select seems to return ENOMEM when it is
1746 Treat it just like EINTR. Bleah. -JimB */ 1780 interrupted. Treat it just like EINTR. Bleah. Note
1781 that we want to test for the "ultrix" CPP symbol, not
1782 "__ultrix__"; the latter is only defined under GCC, but
1783 not by DEC's bundled CC. -JimB */
1747 else if (xerrno == ENOMEM) 1784 else if (xerrno == ENOMEM)
1748 FD_ZERO (&Available); 1785 FD_ZERO (&Available);
1749 #endif 1786 #endif
1750 #ifdef ALLIANT 1787 #ifdef ALLIANT
1751 /* This happens for no known reason on ALLIANT. 1788 /* This happens for no known reason on ALLIANT.
2012 } 2049 }
2013 2050
2014 /* If no filter, write into buffer if it isn't dead. */ 2051 /* If no filter, write into buffer if it isn't dead. */
2015 if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name)) 2052 if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name))
2016 { 2053 {
2017 Lisp_Object tem; 2054 Lisp_Object old_read_only;
2055 Lisp_Object old_begv, old_zv;
2018 2056
2019 Fset_buffer (p->buffer); 2057 Fset_buffer (p->buffer);
2020 opoint = point; 2058 opoint = point;
2059 old_read_only = current_buffer->read_only;
2060 XFASTINT (old_begv) = BEGV;
2061 XFASTINT (old_zv) = ZV;
2062
2063 current_buffer->read_only = Qnil;
2021 2064
2022 /* Insert new output into buffer 2065 /* Insert new output into buffer
2023 at the current end-of-output marker, 2066 at the current end-of-output marker,
2024 thus preserving logical ordering of input and output. */ 2067 thus preserving logical ordering of input and output. */
2025 if (XMARKER (p->mark)->buffer) 2068 if (XMARKER (p->mark)->buffer)
2026 SET_PT (marker_position (p->mark)); 2069 SET_PT (marker_position (p->mark));
2027 else 2070 else
2028 SET_PT (ZV); 2071 SET_PT (ZV);
2072
2073 /* If the output marker is outside of the visible region, save
2074 the restriction and widen. */
2075 if (! (BEGV <= point && point <= ZV))
2076 Fwiden ();
2077
2078 /* Make sure opoint floats ahead of any new text, just as point
2079 would. */
2029 if (point <= opoint) 2080 if (point <= opoint)
2030 opoint += nchars; 2081 opoint += nchars;
2031 2082
2032 tem = current_buffer->read_only; 2083 /* Insert after old_begv, but before old_zv. */
2033 current_buffer->read_only = Qnil; 2084 if (point < XFASTINT (old_begv))
2085 XFASTINT (old_begv) += nchars;
2086 if (point <= XFASTINT (old_zv))
2087 XFASTINT (old_zv) += nchars;
2088
2034 /* Insert before markers in case we are inserting where 2089 /* Insert before markers in case we are inserting where
2035 the buffer's mark is, and the user's next command is Meta-y. */ 2090 the buffer's mark is, and the user's next command is Meta-y. */
2036 insert_before_markers (chars, nchars); 2091 insert_before_markers (chars, nchars);
2037 current_buffer->read_only = tem;
2038 Fset_marker (p->mark, make_number (point), p->buffer); 2092 Fset_marker (p->mark, make_number (point), p->buffer);
2093
2039 update_mode_lines++; 2094 update_mode_lines++;
2040 2095
2096 /* If the restriction isn't what it should be, set it. */
2097 if (XFASTINT (old_begv) != BEGV || XFASTINT (old_zv) != ZV)
2098 Fnarrow_to_region (old_begv, old_zv);
2099
2100 current_buffer->read_only = old_read_only;
2041 SET_PT (opoint); 2101 SET_PT (opoint);
2042 set_buffer_internal (old); 2102 set_buffer_internal (old);
2043 } 2103 }
2044 #ifdef VMS 2104 #ifdef VMS
2045 start_vms_process_read (vs); 2105 start_vms_process_read (vs);
2207 /* send a signal number SIGNO to PROCESS. 2267 /* send a signal number SIGNO to PROCESS.
2208 CURRENT_GROUP means send to the process group that currently owns 2268 CURRENT_GROUP means send to the process group that currently owns
2209 the terminal being used to communicate with PROCESS. 2269 the terminal being used to communicate with PROCESS.
2210 This is used for various commands in shell mode. 2270 This is used for various commands in shell mode.
2211 If NOMSG is zero, insert signal-announcements into process's buffers 2271 If NOMSG is zero, insert signal-announcements into process's buffers
2212 right away. */ 2272 right away.
2273
2274 If we can, we try to signal PROCESS by sending control characters
2275 down the pipe. This allows us to signal inferiors who have changed
2276 their uid, for which killpg would return an EPERM error. */
2213 2277
2214 static void 2278 static void
2215 process_send_signal (process, signo, current_group, nomsg) 2279 process_send_signal (process, signo, current_group, nomsg)
2216 Lisp_Object process; 2280 Lisp_Object process;
2217 int signo; 2281 int signo;
2237 current_group = Qnil; 2301 current_group = Qnil;
2238 2302
2239 /* If we are using pgrps, get a pgrp number and make it negative. */ 2303 /* If we are using pgrps, get a pgrp number and make it negative. */
2240 if (!NILP (current_group)) 2304 if (!NILP (current_group))
2241 { 2305 {
2306 #ifdef SIGNALS_VIA_CHARACTERS
2242 /* If possible, send signals to the entire pgrp 2307 /* If possible, send signals to the entire pgrp
2243 by sending an input character to it. */ 2308 by sending an input character to it. */
2309
2310 /* On Berkeley descendants, the following IOCTL's retrieve the
2311 current control characters. */
2244 #if defined (TIOCGLTC) && defined (TIOCGETC) 2312 #if defined (TIOCGLTC) && defined (TIOCGETC)
2313
2245 struct tchars c; 2314 struct tchars c;
2246 struct ltchars lc; 2315 struct ltchars lc;
2247 2316
2248 switch (signo) 2317 switch (signo)
2249 { 2318 {
2258 #ifdef SIGTSTP 2327 #ifdef SIGTSTP
2259 case SIGTSTP: 2328 case SIGTSTP:
2260 ioctl (XFASTINT (p->infd), TIOCGLTC, &lc); 2329 ioctl (XFASTINT (p->infd), TIOCGLTC, &lc);
2261 send_process (proc, &lc.t_suspc, 1); 2330 send_process (proc, &lc.t_suspc, 1);
2262 return; 2331 return;
2263 #endif /* SIGTSTP */ 2332 #endif /* ! defined (SIGTSTP) */
2264 } 2333 }
2265 #endif /* ! defined (TIOCGLTC) && defined (TIOCGETC) */ 2334
2266 /* It is possible that the following code would work 2335 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
2267 on other kinds of USG systems, not just on the IRIS. 2336
2268 This should be tried in Emacs 19. */ 2337 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
2269 #if defined (USG) 2338 characters. */
2339 #ifdef TCGETA
2270 struct termio t; 2340 struct termio t;
2271 switch (signo) 2341 switch (signo)
2272 { 2342 {
2273 case SIGINT: 2343 case SIGINT:
2274 ioctl (XFASTINT (p->infd), TCGETA, &t); 2344 ioctl (XFASTINT (p->infd), TCGETA, &t);
2281 #ifdef SIGTSTP 2351 #ifdef SIGTSTP
2282 case SIGTSTP: 2352 case SIGTSTP:
2283 ioctl (XFASTINT (p->infd), TCGETA, &t); 2353 ioctl (XFASTINT (p->infd), TCGETA, &t);
2284 send_process (proc, &t.c_cc[VSWTCH], 1); 2354 send_process (proc, &t.c_cc[VSWTCH], 1);
2285 return; 2355 return;
2286 #endif 2356 #endif /* ! defined (SIGTSTP) */
2287 } 2357 }
2288 #endif /* ! defined (USG) */ 2358 #else /* ! defined (TCGETA) */
2359 Your configuration files are messed up.
2360 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
2361 you'd better be using one of the alternatives above! */
2362 #endif /* ! defined (TCGETA) */
2363 #endif /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
2364 #endif /* ! defined (SIGNALS_VIA_CHARACTERS) */
2289 2365
2290 #ifdef TIOCGPGRP 2366 #ifdef TIOCGPGRP
2291 /* Get the pgrp using the tty itself, if we have that. 2367 /* Get the pgrp using the tty itself, if we have that.
2292 Otherwise, use the pty to get the pgrp. 2368 Otherwise, use the pty to get the pgrp.
2293 On pfa systems, saka@pfu.fujitsu.co.JP writes: 2369 On pfa systems, saka@pfu.fujitsu.co.JP writes:
2294 "TICGPGRP symbol defined in sys/ioctl.h at E50. 2370 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
2295 But, TIOCGPGRP does not work on E50 ;-P works fine on E60" 2371 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
2296 His patch indicates that if TIOCGPGRP returns an error, then 2372 His patch indicates that if TIOCGPGRP returns an error, then
2297 we should just assume that p->pid is also the process group id. */ 2373 we should just assume that p->pid is also the process group id. */
2298 { 2374 {
2299 int err; 2375 int err;
2300 2376
2310 } 2386 }
2311 if (gid == -1) 2387 if (gid == -1)
2312 no_pgrp = 1; 2388 no_pgrp = 1;
2313 else 2389 else
2314 gid = - gid; 2390 gid = - gid;
2315 #else /* ! defined (TIOCGPGRP ) */ 2391 #else /* ! defined (TIOCGPGRP ) */
2316 /* Can't select pgrps on this system, so we know that 2392 /* Can't select pgrps on this system, so we know that
2317 the child itself heads the pgrp. */ 2393 the child itself heads the pgrp. */
2318 gid = - XFASTINT (p->pid); 2394 gid = - XFASTINT (p->pid);
2319 #endif /* ! defined (TIOCGPGRP ) */ 2395 #endif /* ! defined (TIOCGPGRP ) */
2320 } 2396 }
2628 2704
2629 /* Report the status of the synchronous process. */ 2705 /* Report the status of the synchronous process. */
2630 if (WIFEXITED (w)) 2706 if (WIFEXITED (w))
2631 synch_process_retcode = WRETCODE (w); 2707 synch_process_retcode = WRETCODE (w);
2632 else if (WIFSIGNALED (w)) 2708 else if (WIFSIGNALED (w))
2709 #ifndef VMS
2633 synch_process_death = sys_siglist[WTERMSIG (w)]; 2710 synch_process_death = sys_siglist[WTERMSIG (w)];
2711 #else
2712 synch_process_death = sys_errlist[WTERMSIG (w)];
2713 #endif
2634 } 2714 }
2635 2715
2636 /* On some systems, we must return right away. 2716 /* On some systems, we must return right away.
2637 If any more processes want to signal us, we will 2717 If any more processes want to signal us, we will
2638 get another signal. 2718 get another signal.