comparison src/process-nt.c @ 853:2b6fa2618f76

[xemacs-hg @ 2002-05-28 08:44:22 by ben] merge my stderr-proc ws make-docfile.c: Fix places where we forget to check for EOF. code-init.el: Don't use CRLF conversion by default on process output. CMD.EXE and friends work both ways but Cygwin programs don't like the CRs. code-process.el, multicast.el, process.el: Removed. Improvements to call-process-internal: -- allows a buffer to be specified for input and stderr output -- use it on all systems -- implement C-g as documented -- clean up and comment call-process-region uses new call-process facilities; no temp file. remove duplicate funs in process.el. comment exactly how coding systems work and fix various problems. open-multicast-group now does similar coding-system frobbing to open-network-stream. dumped-lisp.el, faces.el, msw-faces.el: Fix some hidden errors due to code not being defined at the right time. xemacs.mak: Add -DSTRICT. ================================================================ ALLOW SEPARATION OF STDOUT AND STDERR IN PROCESSES ================================================================ Standard output and standard error can be processed separately in a process. Each can have its own buffer, its own mark in that buffer, and its filter function. You can specify a separate buffer for stderr in `start-process' to get things started, or use the new primitives: set-process-stderr-buffer process-stderr-buffer process-stderr-mark set-process-stderr-filter process-stderr-filter Also, process-send-region takes a 4th optional arg, a buffer. Currently always uses a pipe() under Unix to read the error output. (#### Would a PTY be better?) sysdep.h, sysproc.h, unexfreebsd.c, unexsunos4.c, nt.c, emacs.c, callproc.c, symsinit.h, sysdep.c, Makefile.in.in, process-unix.c: Delete callproc.c. Move child_setup() to process-unix.c. wait_for_termination() now only needed on a few really old systems. console-msw.h, event-Xt.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.h, process-nt.c, process-unix.c, process.c, process.h, procimpl.h: Rewrite the process methods to handle a separate channel for error input. Create Lstreams for reading in the error channel. Many process methods need change. In general the changes are fairly clear as they involve duplicating what's used for reading the normal stdout and changing for stderr -- although tedious, as such changes are required throughout the entire process code. Rewrote the code that reads process output to do two loops, one for stdout and one for stderr. gpmevent.c, tooltalk.c: set_process_filter takes an argument for stderr. ================================================================ NEW ERROR-TRAPPING MECHANISM ================================================================ Totally rewrite error trapping code to be unified and support more features. Basic function is call_trapping_problems(), which lets you specify, by means of flags, what sorts of problems you want trapped. these can include -- quit -- errors -- throws past the function -- creation of "display objects" (e.g. buffers) -- deletion of already-existing "display objects" (e.g. buffers) -- modification of already-existing buffers -- entering the debugger -- gc -- errors->warnings (ala suspended errors) etc. All other error funs rewritten in terms of this one. Various older mechanisms removed or rewritten. window.c, insdel.c, console.c, buffer.c, device.c, frame.c: When creating a display object, added call to note_object_created(), for use with trapping_problems mechanism. When deleting, call check_allowed_operation() and note_object deleted(). The trapping-problems code records the objects created since the call-trapping-problems began. Those objects can be deleted, but none others (i.e. previously existing ones). bytecode.c, cmdloop.c: internal_catch takes another arg. eval.c: Add long comments describing the "five lists" used to maintain state (backtrace, gcpro, specbind, etc.) in the Lisp engine. backtrace.h, eval.c: Implement trapping-problems mechanism, eliminate old mechanisms or redo in terms of new one. frame.c, gutter.c: Flush out the concept of "critical display section", defined by the in_display() var. Use an internal_bind() to get it reset, rather than just doing it at end, because there may be a non-local exit. event-msw.c, event-stream.c, console-msw.h, device.c, dialog-msw.c, frame.c, frame.h, intl.c, toolbar.c, menubar-msw.c, redisplay.c, alloc.c, menubar-x.c: Make use of new trapping-errors stuff and rewrite code based on old mechanisms. glyphs-widget.c, redisplay.h: Protect calling Lisp in redisplay. insdel.c: Protect hooks against deleting existing buffers. frame-msw.c: Use EQ, not EQUAL in hash tables whose keys are just numbers. Otherwise we run into stickiness in redisplay because internal_equal() can QUIT. ================================================================ SIGNAL, C-G CHANGES ================================================================ Here we change the way that C-g interacts with event reading. The idea is that a C-g occurring while we're reading a user event should be read as C-g, but elsewhere should be a QUIT. The former code did all sorts of bizarreness -- requiring that no QUIT occurs anywhere in event-reading code (impossible to enforce given the stuff called or Lisp code invoked), and having some weird system involving enqueue/dequeue of a C-g and interaction with Vquit_flag -- and it didn't work. Now, we simply enclose all code where we want C-g read as an event with {begin/end}_dont_check_for_quit(). This completely turns off the mechanism that checks (and may remove or alter) C-g in the read-ahead queues, so we just get the C-g normal. Signal.c documents this very carefully. cmdloop.c: Correct use of dont_check_for_quit to new scheme, remove old out-of-date comments. event-stream.c: Fix C-g handling to actually work. device-x.c: Disable quit checking when err out. signal.c: Cleanup. Add large descriptive comment. process-unix.c, process-nt.c, sysdep.c: Use QUIT instead of REALLY_QUIT. It's not necessary to use REALLY_QUIT and just confuses the issue. lisp.h: Comment quit handlers. ================================================================ CONS CHANGES ================================================================ free_cons() now takes a Lisp_Object not the result of XCONS(). car and cdr have been renamed so that they don't get used directly; go through XCAR(), XCDR() instead. alloc.c, dired.c, editfns.c, emodules.c, fns.c, glyphs-msw.c, glyphs-x.c, glyphs.c, keymap.c, minibuf.c, search.c, eval.c, lread.c, lisp.h: Correct free_cons calling convention: now takes Lisp_Object, not Lisp_Cons chartab.c: Eliminate direct use of ->car, ->cdr, should be black box. callint.c: Rewrote using EXTERNAL_LIST_LOOP to avoid use of Lisp_Cons. ================================================================ USE INTERNAL-BIND-* ================================================================ eval.c: Cleanups of these funs. alloc.c, fileio.c, undo.c, specifier.c, text.c, profile.c, lread.c, redisplay.c, menubar-x.c, macros.c: Rewrote to use internal_bind_int() and internal_bind_lisp_object() in place of whatever varied and cumbersome mechanisms were formerly there. ================================================================ SPECBIND SANITY ================================================================ backtrace.h: - Improved comments backtrace.h, bytecode.c, eval.c: Add new mechanism check_specbind_stack_sanity() for sanity checking code each time the catchlist or specbind stack change. Removed older prototype of same mechanism. ================================================================ MISC ================================================================ lisp.h, insdel.c, window.c, device.c, console.c, buffer.c: Fleshed out authorship. device-msw.c: Correct bad Unicode-ization. print.c: Be more careful when not initialized or in fatal error handling. search.c: Eliminate running_asynch_code, an FSF holdover. alloc.c: Added comments about gc-cons-threshold. dialog-x.c: Use begin_gc_forbidden() around code to build up a widget value tree, like in menubar-x.c. gui.c: Use Qunbound not Qnil as the default for gethash. lisp-disunion.h, lisp-union.h: Added warnings on use of VOID_TO_LISP(). lisp.h: Use ERROR_CHECK_STRUCTURES to turn on ERROR_CHECK_TRAPPING_PROBLEMS and ERROR_CHECK_TYPECHECK lisp.h: Add assert_with_message. lisp.h: Add macros for gcproing entire arrays. (You could do this before but it required manual twiddling the gcpro structure.) lisp.h: Add prototypes for new functions defined elsewhere.
author ben
date Tue, 28 May 2002 08:45:36 +0000
parents e7ee5f8bde58
children 1d8fb2eee1bb
comparison
equal deleted inserted replaced
852:d83885ef293b 853:2b6fa2618f76
48 struct nt_process_data 48 struct nt_process_data
49 { 49 {
50 HANDLE h_process; 50 HANDLE h_process;
51 DWORD dwProcessId; 51 DWORD dwProcessId;
52 HWND hwnd; /* console window */ 52 HWND hwnd; /* console window */
53 int selected_for_exit_notify;
53 }; 54 };
54 55
55 /* Control whether create_child causes the process to inherit Emacs' 56 /* Control whether create_child causes the process to inherit Emacs'
56 console window, or be given a new one of its own. The default is 57 console window, or be given a new one of its own. The default is
57 nil, to allow multiple DOS programs to run on Win95. Having separate 58 nil, to allow multiple DOS programs to run on Win95. Having separate
67 68
68 /*-----------------------------------------------------------------------*/ 69 /*-----------------------------------------------------------------------*/
69 /* Process helpers */ 70 /* Process helpers */
70 /*-----------------------------------------------------------------------*/ 71 /*-----------------------------------------------------------------------*/
71 72
72 /* This one breaks process abstraction. Prototype is in console-msw.h, 73 /* These break process abstraction. Prototypes in console-msw.h,
73 used by select_process method in event-msw.c */ 74 used by select_process method in event-msw.c.
75
76 If called the first time on a process, return the process handle, so we
77 can select on it and receive exit notification. "First time only" so we
78 don't select the same process multiple times if someone turns off and on
79 the receipt of process data. */
80
81 HANDLE
82 get_nt_process_handle_only_first_time (Lisp_Process *p)
83 {
84 if (NT_DATA (p)->selected_for_exit_notify)
85 return INVALID_HANDLE_VALUE;
86 NT_DATA (p)->selected_for_exit_notify = 1;
87 return (NT_DATA (p)->h_process);
88 }
89
74 HANDLE 90 HANDLE
75 get_nt_process_handle (Lisp_Process *p) 91 get_nt_process_handle (Lisp_Process *p)
76 { 92 {
77 return (NT_DATA (p)->h_process); 93 return (NT_DATA (p)->h_process);
78 } 94 }
395 assert (d.adr_SetConsoleCtrlHandler); 411 assert (d.adr_SetConsoleCtrlHandler);
396 run_in_other_process (h_process, (LPTHREAD_START_ROUTINE)sig_enable_proc, 412 run_in_other_process (h_process, (LPTHREAD_START_ROUTINE)sig_enable_proc,
397 &d, sizeof (d)); 413 &d, sizeof (d));
398 } 414 }
399 415
400 #pragma warning (default : 4113)
401
402 /* ---------------------------- the 95 way ------------------------------- */ 416 /* ---------------------------- the 95 way ------------------------------- */
403 417
404 static BOOL CALLBACK 418 static BOOL CALLBACK
405 find_child_console (HWND hwnd, long putada) 419 find_child_console (HWND hwnd, long putada)
406 { 420 {
656 WSADATA wsa_data; 670 WSADATA wsa_data;
657 /* Request Winsock v1.1 Note the order: (minor=1, major=1) */ 671 /* Request Winsock v1.1 Note the order: (minor=1, major=1) */
658 WSAStartup (MAKEWORD (1,1), &wsa_data); 672 WSAStartup (MAKEWORD (1,1), &wsa_data);
659 } 673 }
660 674
661 static DOESNT_RETURN
662 mswindows_report_winsock_error (const char *string, Lisp_Object data,
663 int errnum)
664 {
665 report_file_type_error (Qnetwork_error, mswindows_lisp_error (errnum),
666 string, data);
667 }
668
669 static void
670 ensure_console_window_exists (void)
671 {
672 if (mswindows_windows9x_p)
673 mswindows_hide_console ();
674 }
675
676 int
677 mswindows_compare_env (const void *strp1, const void *strp2)
678 {
679 const Intbyte *str1 = *(const Intbyte **)strp1,
680 *str2 = *(const Intbyte **)strp2;
681
682 while (*str1 && *str2 && *str1 != '=' && *str2 != '=')
683 {
684 if ((*str1) > (*str2))
685 return 1;
686 else if ((*str1) < (*str2))
687 return -1;
688 str1++, str2++;
689 }
690
691 if (*str1 == '=' && *str2 == '=')
692 return 0;
693 else if (*str1 == '=')
694 return -1;
695 else
696 return 1;
697 }
698
699 /* 675 /*
700 * Fork off a subprocess. P is a pointer to newly created subprocess 676 * Fork off a subprocess. P is a pointer to newly created subprocess
701 * object. If this function signals, the caller is responsible for 677 * object. If this function signals, the caller is responsible for
702 * deleting (and finalizing) the process object. 678 * deleting (and finalizing) the process object.
703 * 679 *
704 * The method must return PID of the new process, a (positive??? ####) number 680 * The method must return PID of the new process, a (positive??? ####) number
705 * which fits into Lisp_Int. No return value indicates an error, the method 681 * which fits into Lisp_Int. No return value indicates an error, the method
706 * must signal an error instead. 682 * must signal an error instead.
707 */ 683 */
708 684
685 static DOESNT_RETURN
686 mswindows_report_winsock_error (const char *string, Lisp_Object data,
687 int errnum)
688 {
689 report_file_type_error (Qnetwork_error, mswindows_lisp_error (errnum),
690 string, data);
691 }
692
693 static void
694 ensure_console_window_exists (void)
695 {
696 if (mswindows_windows9x_p)
697 mswindows_hide_console ();
698 }
699
700 int
701 mswindows_compare_env (const void *strp1, const void *strp2)
702 {
703 const Intbyte *str1 = *(const Intbyte **)strp1,
704 *str2 = *(const Intbyte **)strp2;
705
706 while (*str1 && *str2 && *str1 != '=' && *str2 != '=')
707 {
708 if ((*str1) > (*str2))
709 return 1;
710 else if ((*str1) < (*str2))
711 return -1;
712 str1++, str2++;
713 }
714
715 if (*str1 == '=' && *str2 == '=')
716 return 0;
717 else if (*str1 == '=')
718 return -1;
719 else
720 return 1;
721 }
722
723 /*
724 * Fork off a subprocess. P is a pointer to newly created subprocess
725 * object. If this function signals, the caller is responsible for
726 * deleting (and finalizing) the process object.
727 *
728 * The method must return PID of the new process, a (positive??? ####) number
729 * which fits into Lisp_Int. No return value indicates an error, the method
730 * must signal an error instead.
731 */
732
709 static int 733 static int
710 nt_create_process (Lisp_Process *p, 734 nt_create_process (Lisp_Process *p,
711 Lisp_Object *argv, int nargv, 735 Lisp_Object *argv, int nargv,
712 Lisp_Object program, Lisp_Object cur_dir) 736 Lisp_Object program, Lisp_Object cur_dir,
737 int separate_err)
713 { 738 {
714 /* Synched up with sys_spawnve in FSF 20.6. Significantly different 739 /* Synched up with sys_spawnve in FSF 20.6. Significantly different
715 but still synchable. */ 740 but still synchable. */
716 HANDLE hmyshove, hmyslurp, hprocin, hprocout, hprocerr; 741 HANDLE hmyshove, hmyslurp, hmyslurp_err, hprocin, hprocout, hprocerr;
717 Extbyte *command_line; 742 Extbyte *command_line;
718 BOOL do_io, windowed; 743 BOOL do_io, windowed;
719 Extbyte *proc_env; 744 Extbyte *proc_env;
720 745
721 /* No need to DOS-ize the filename; expand-file-name (called prior) 746 /* No need to DOS-ize the filename; expand-file-name (called prior)
773 sa.lpSecurityDescriptor = NULL; 798 sa.lpSecurityDescriptor = NULL;
774 799
775 CreatePipe (&hprocin, &hmyshove, &sa, 0); 800 CreatePipe (&hprocin, &hmyshove, &sa, 0);
776 CreatePipe (&hmyslurp, &hprocout, &sa, 0); 801 CreatePipe (&hmyslurp, &hprocout, &sa, 0);
777 802
778 /* Duplicate the stdout handle for use as stderr */ 803 if (separate_err)
779 DuplicateHandle(GetCurrentProcess(), hprocout, GetCurrentProcess(), 804 CreatePipe (&hmyslurp_err, &hprocerr, &sa, 0);
780 &hprocerr, 0, TRUE, DUPLICATE_SAME_ACCESS); 805 else
806 /* Duplicate the stdout handle for use as stderr */
807 DuplicateHandle(GetCurrentProcess(), hprocout, GetCurrentProcess(),
808 &hprocerr, 0, TRUE, DUPLICATE_SAME_ACCESS);
781 809
782 /* Stupid Win32 allows to create a pipe with *both* ends either 810 /* Stupid Win32 allows to create a pipe with *both* ends either
783 inheritable or not. We need process ends inheritable, and local 811 inheritable or not. We need process ends inheritable, and local
784 ends not inheritable. */ 812 ends not inheritable. */
785 DuplicateHandle (GetCurrentProcess(), hmyshove, GetCurrentProcess(), 813 DuplicateHandle (GetCurrentProcess(), hmyshove, GetCurrentProcess(),
788 hmyshove = htmp; 816 hmyshove = htmp;
789 DuplicateHandle (GetCurrentProcess(), hmyslurp, GetCurrentProcess(), 817 DuplicateHandle (GetCurrentProcess(), hmyslurp, GetCurrentProcess(),
790 &htmp, 0, FALSE, 818 &htmp, 0, FALSE,
791 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS); 819 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS);
792 hmyslurp = htmp; 820 hmyslurp = htmp;
821 if (separate_err)
822 {
823 DuplicateHandle (GetCurrentProcess(), hmyslurp_err,
824 GetCurrentProcess(), &htmp, 0, FALSE,
825 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS);
826 hmyslurp_err = htmp;
827 }
793 } 828 }
794 829
795 /* Convert an argv vector into Win32 style command line by a call to 830 /* Convert an argv vector into Win32 style command line by a call to
796 lisp function `mswindows-construct-process-command-line' 831 lisp function `mswindows-construct-process-command-line'
797 (in win32-native.el) */ 832 (in win32-native.el) */
975 { 1010 {
976 if (do_io) 1011 if (do_io)
977 { 1012 {
978 CloseHandle (hmyshove); 1013 CloseHandle (hmyshove);
979 CloseHandle (hmyslurp); 1014 CloseHandle (hmyslurp);
1015 if (separate_err)
1016 CloseHandle (hmyslurp_err);
980 } 1017 }
981 mswindows_report_process_error 1018 mswindows_report_process_error
982 ("Error starting", 1019 ("Error starting",
983 program, GetLastError ()); 1020 program, GetLastError ());
984 } 1021 }
986 /* The process started successfully */ 1023 /* The process started successfully */
987 if (do_io) 1024 if (do_io)
988 { 1025 {
989 NT_DATA(p)->h_process = pi.hProcess; 1026 NT_DATA(p)->h_process = pi.hProcess;
990 NT_DATA(p)->dwProcessId = pi.dwProcessId; 1027 NT_DATA(p)->dwProcessId = pi.dwProcessId;
991 init_process_io_handles (p, (void *)hmyslurp, (void *)hmyshove, 0); 1028 init_process_io_handles (p, (void *) hmyslurp, (void *) hmyshove,
1029 separate_err ? (void *) hmyslurp_err
1030 : (void *) -1, 0);
992 } 1031 }
993 else 1032 else
994 { 1033 {
995 /* Indicate as if the process has exited immediately. */ 1034 /* Indicate as if the process has exited immediately. */
996 p->status_symbol = Qexit; 1035 p->status_symbol = Qexit;
1217 if (QUITP) 1256 if (QUITP)
1218 { 1257 {
1219 WSACancelAsyncRequest (hasync); 1258 WSACancelAsyncRequest (hasync);
1220 KillTimer (hwnd, SOCK_TIMER_ID); 1259 KillTimer (hwnd, SOCK_TIMER_ID);
1221 DestroyWindow (hwnd); 1260 DestroyWindow (hwnd);
1222 REALLY_QUIT; 1261 QUIT;
1223 } 1262 }
1224 } 1263 }
1225 qxeDispatchMessage (&msg); 1264 qxeDispatchMessage (&msg);
1226 } 1265 }
1227 1266
1352 if (QUITP) 1391 if (QUITP)
1353 { 1392 {
1354 WSAAsyncSelect (s, hwnd, XM_SOCKREPLY, 0); 1393 WSAAsyncSelect (s, hwnd, XM_SOCKREPLY, 0);
1355 KillTimer (hwnd, SOCK_TIMER_ID); 1394 KillTimer (hwnd, SOCK_TIMER_ID);
1356 DestroyWindow (hwnd); 1395 DestroyWindow (hwnd);
1357 REALLY_QUIT; 1396 QUIT;
1358 } 1397 }
1359 } 1398 }
1360 DispatchMessage (&msg); 1399 DispatchMessage (&msg);
1361 } 1400 }
1362 1401
1376 int nsel; 1415 int nsel;
1377 1416
1378 if (QUITP) 1417 if (QUITP)
1379 { 1418 {
1380 closesocket (s); 1419 closesocket (s);
1381 REALLY_QUIT; 1420 QUIT;
1382 } 1421 }
1383 1422
1384 /* Poll for quit every 250 ms */ 1423 /* Poll for quit every 250 ms */
1385 tv.tv_sec = 0; 1424 tv.tv_sec = 0;
1386 tv.tv_usec = 250 * 1000; 1425 tv.tv_usec = 250 * 1000;