comparison src/process-nt.c @ 363:972bbb6d6ca2 r21-1-11

Import from CVS: tag r21-1-11
author cvs
date Mon, 13 Aug 2007 10:59:28 +0200
parents 8e84bee8ddd0
children cc15677e0335
comparison
equal deleted inserted replaced
362:1e474c183006 363:972bbb6d6ca2
47 47
48 /* Implemenation-specific data. Pointed to by Lisp_Process->process_data */ 48 /* Implemenation-specific data. Pointed to by Lisp_Process->process_data */
49 struct nt_process_data 49 struct nt_process_data
50 { 50 {
51 HANDLE h_process; 51 HANDLE h_process;
52 int need_enable_child_signals;
53 }; 52 };
54 53
55 #define NT_DATA(p) ((struct nt_process_data*)((p)->process_data)) 54 #define NT_DATA(p) ((struct nt_process_data*)((p)->process_data))
56 55
57 /*-----------------------------------------------------------------------*/ 56 /*-----------------------------------------------------------------------*/
467 CreatePipe (&hprocin, &hmyshove, &sa, 0); 466 CreatePipe (&hprocin, &hmyshove, &sa, 0);
468 CreatePipe (&hmyslurp, &hprocout, &sa, 0); 467 CreatePipe (&hmyslurp, &hprocout, &sa, 0);
469 468
470 /* Duplicate the stdout handle for use as stderr */ 469 /* Duplicate the stdout handle for use as stderr */
471 DuplicateHandle(GetCurrentProcess(), hprocout, GetCurrentProcess(), &hprocerr, 470 DuplicateHandle(GetCurrentProcess(), hprocout, GetCurrentProcess(), &hprocerr,
472 0, TRUE, DUPLICATE_SAME_ACCESS); 471 0, TRUE, DUPLICATE_SAME_ACCESS);
473 472
474 /* Stupid Win32 allows to create a pipe with *both* ends either 473 /* Stupid Win32 allows to create a pipe with *both* ends either
475 inheritable or not. We need process ends inheritable, and local 474 inheritable or not. We need process ends inheritable, and local
476 ends not inheritable. */ 475 ends not inheritable. */
477 DuplicateHandle (GetCurrentProcess(), hmyshove, GetCurrentProcess(), &htmp, 476 DuplicateHandle (GetCurrentProcess(), hmyshove, GetCurrentProcess(), &htmp,
596 si.wShowWindow = windowed ? SW_SHOWNORMAL : SW_HIDE; 595 si.wShowWindow = windowed ? SW_SHOWNORMAL : SW_HIDE;
597 if (do_io) 596 if (do_io)
598 { 597 {
599 si.hStdInput = hprocin; 598 si.hStdInput = hprocin;
600 si.hStdOutput = hprocout; 599 si.hStdOutput = hprocout;
601 si.hStdError = hprocerr; 600 si.hStdError = hprocerr;
602 si.dwFlags |= STARTF_USESTDHANDLES; 601 si.dwFlags |= STARTF_USESTDHANDLES;
603 } 602 }
604 603
605 err = (CreateProcess (NULL, command_line, NULL, NULL, TRUE, 604 err = (CreateProcess (NULL, command_line, NULL, NULL, TRUE,
606 CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP 605 CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP
611 if (do_io) 610 if (do_io)
612 { 611 {
613 /* These just have been inherited; we do not need a copy */ 612 /* These just have been inherited; we do not need a copy */
614 CloseHandle (hprocin); 613 CloseHandle (hprocin);
615 CloseHandle (hprocout); 614 CloseHandle (hprocout);
616 CloseHandle (hprocerr); 615 CloseHandle (hprocerr);
617 } 616 }
618 617
619 /* Handle process creation failure */ 618 /* Handle process creation failure */
620 if (err) 619 if (err)
621 { 620 {
638 /* Indicate as if the process has exited immediately. */ 637 /* Indicate as if the process has exited immediately. */
639 p->status_symbol = Qexit; 638 p->status_symbol = Qexit;
640 CloseHandle (pi.hProcess); 639 CloseHandle (pi.hProcess);
641 } 640 }
642 641
642 if (!windowed)
643 enable_child_signals (pi.hProcess);
644
643 ResumeThread (pi.hThread); 645 ResumeThread (pi.hThread);
644 CloseHandle (pi.hThread); 646 CloseHandle (pi.hThread);
645
646 /* Remember to enable child signals later if this is not a windowed
647 app. Can't do it right now because that screws up the MKS Toolkit
648 shell. */
649 if (!windowed)
650 {
651 NT_DATA(p)->need_enable_child_signals = 10;
652 kick_status_notify ();
653 }
654 647
655 /* Hack to support Windows 95 negative pids */ 648 /* Hack to support Windows 95 negative pids */
656 return ((int)pi.dwProcessId < 0 649 return ((int)pi.dwProcessId < 0
657 ? -(int)pi.dwProcessId : (int)pi.dwProcessId); 650 ? -(int)pi.dwProcessId : (int)pi.dwProcessId);
658 } 651 }
668 661
669 static void 662 static void
670 nt_update_status_if_terminated (struct Lisp_Process* p) 663 nt_update_status_if_terminated (struct Lisp_Process* p)
671 { 664 {
672 DWORD exit_code; 665 DWORD exit_code;
673
674 if (NT_DATA(p)->need_enable_child_signals > 1)
675 {
676 NT_DATA(p)->need_enable_child_signals -= 1;
677 kick_status_notify ();
678 }
679 else if (NT_DATA(p)->need_enable_child_signals == 1)
680 {
681 enable_child_signals(NT_DATA(p)->h_process);
682 NT_DATA(p)->need_enable_child_signals = 0;
683 }
684
685 if (GetExitCodeProcess (NT_DATA(p)->h_process, &exit_code) 666 if (GetExitCodeProcess (NT_DATA(p)->h_process, &exit_code)
686 && exit_code != STILL_ACTIVE) 667 && exit_code != STILL_ACTIVE)
687 { 668 {
688 p->tick++; 669 p->tick++;
689 p->core_dumped = 0; 670 p->core_dumped = 0;
780 static void 761 static void
781 nt_kill_child_process (Lisp_Object proc, int signo, 762 nt_kill_child_process (Lisp_Object proc, int signo,
782 int current_group, int nomsg) 763 int current_group, int nomsg)
783 { 764 {
784 struct Lisp_Process *p = XPROCESS (proc); 765 struct Lisp_Process *p = XPROCESS (proc);
785
786 /* Enable child signals if necessary. This may lose the first
787 but it's better than nothing. */
788 if (NT_DATA(p)->need_enable_child_signals > 0)
789 {
790 enable_child_signals(NT_DATA(p)->h_process);
791 NT_DATA(p)->need_enable_child_signals = 0;
792 }
793 766
794 /* Signal error if SIGNO cannot be sent */ 767 /* Signal error if SIGNO cannot be sent */
795 validate_signal_number (signo); 768 validate_signal_number (signo);
796 769
797 /* Send signal */ 770 /* Send signal */