comparison src/sysdep.c @ 4760:217abcf015c4

sys_subshell() is needed for WIndows native builds
author Vin Shelton <acs@xemacs.org>
date Thu, 19 Nov 2009 18:21:06 -0500
parents aa5ed11f473b
children b3ea9c582280
comparison
equal deleted inserted replaced
4759:aa5ed11f473b 4760:217abcf015c4
551 EMACS_SIGNAL (saved_handlers->code, saved_handlers->handler); 551 EMACS_SIGNAL (saved_handlers->code, saved_handlers->handler);
552 saved_handlers++; 552 saved_handlers++;
553 } 553 }
554 } 554 }
555 555
556 /* Fork a subshell. */
557 static void
558 sys_subshell (void)
559 {
560 Lisp_Object dir;
561 Ibyte *str = 0;
562 Bytecount len;
563 struct gcpro gcpro1;
564 Ibyte *sh = 0;
565 Extbyte *shext;
566
567 /* Use our buffer's default directory for the subshell. */
568
569 /* Note: These calls are spread out to insure that the return values
570 of the calls (which may be newly-created strings) are properly
571 GC-protected. */
572
573 GCPRO1 (dir);
574
575 dir = current_buffer->directory;
576 /* If the current dir has no terminating slash, we'll get undesirable
577 results, so put the slash back. */
578 dir = Ffile_name_as_directory (dir);
579 dir = Funhandled_file_name_directory (dir);
580 dir = expand_and_dir_to_file (dir, Qnil);
581
582 str = alloca_ibytes (XSTRING_LENGTH (dir) + 2);
583 len = XSTRING_LENGTH (dir);
584 memcpy (str, XSTRING_DATA (dir), len);
585 if (!IS_ANY_SEP (str[len - 1]))
586 str[len++] = DIRECTORY_SEP;
587 str[len] = 0;
588
589 if (sh == 0)
590 sh = egetenv ("SHELL");
591 if (sh == 0)
592 sh = (Ibyte *) "sh";
593
594 PATHNAME_CONVERT_OUT (sh, shext);
595
596 UNGCPRO;
597
598 #ifdef WIN32_NATIVE
599
600 if (str)
601 qxe_chdir (str);
602
603 /* Waits for process completion */
604 if (XEUNICODE_P ?
605 _wspawnlp (_P_WAIT, (const wchar_t *) shext,
606 (const wchar_t *) shext, NULL) != 0 :
607 _spawnlp (_P_WAIT, shext, shext, NULL) != 0)
608 report_process_error ("Can't spawn subshell", Qunbound);
609 else
610 return; /* we're done, no need to wait for termination */
611
612 #else /* not WIN32_NATIVE */
613
614 {
615 int pid;
616 struct save_signal saved_handlers[5];
617
618 saved_handlers[0].code = SIGINT;
619 saved_handlers[1].code = SIGQUIT;
620 saved_handlers[2].code = SIGTERM;
621 #ifdef SIGIO
622 saved_handlers[3].code = SIGIO;
623 saved_handlers[4].code = 0;
624 #else
625 saved_handlers[3].code = 0;
626 #endif
627
628 pid = fork ();
629
630 if (pid == -1)
631 report_process_error ("Can't spawn subshell", Qunbound);
632 if (pid == 0)
633 {
634 if (str)
635 qxe_chdir (str);
636
637 #if !defined (NO_SUBPROCESSES)
638 close_process_descs (); /* Close Emacs's pipes/ptys */
639 #endif
640
641 #ifdef SET_EMACS_PRIORITY
642 if (emacs_priority != 0)
643 nice (-emacs_priority); /* Give the new shell the default priority */
644 #endif
645
646 execlp (shext, shext, 0);
647 retry_write (1, "Can't execute subshell", 22);
648 _exit (1);
649 }
650
651 save_signal_handlers (saved_handlers);
652 synch_process_alive = 1;
653 wait_for_termination (pid);
654 restore_signal_handlers (saved_handlers);
655 }
656
657 #endif /* not WIN32_NATIVE */
658 }
659
556 #endif /* !defined (SIGTSTP) */ 660 #endif /* !defined (SIGTSTP) */
557 661
558 662
559 663
560 /* Suspend the Emacs process; give terminal to its superior. */ 664 /* Suspend the Emacs process; give terminal to its superior. */
566 int pgrp = EMACS_GET_PROCESS_GROUP (); 670 int pgrp = EMACS_GET_PROCESS_GROUP ();
567 EMACS_KILLPG (pgrp, SIGTSTP); 671 EMACS_KILLPG (pgrp, SIGTSTP);
568 } 672 }
569 673
570 #else /* No SIGTSTP */ 674 #else /* No SIGTSTP */
571 /* If you don't know what this is don't mess with it */ 675
572 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */ 676 /* On a system where suspending is not implemented,
573 kill (getpid (), SIGQUIT); 677 instead fork a subshell and let it talk directly to the terminal
678 while we wait. */
679 sys_subshell ();
680
574 #endif 681 #endif
575 } 682 }
576 683
577 /* Suspend a process if possible; give terminal to its superior. */ 684 /* Suspend a process if possible; give terminal to its superior. */
578 void 685 void