Mercurial > hg > xemacs-beta
comparison src/process-unix.c @ 386:4af0ddfb7c5b r21-2-8
Import from CVS: tag r21-2-8
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:08:50 +0200 |
parents | 8626e4521993 |
children | 74fd4e045ea6 |
comparison
equal
deleted
inserted
replaced
385:bc48d89bf15c | 386:4af0ddfb7c5b |
---|---|
696 { | 696 { |
697 UNIX_DATA(p)->infd = (int)in; | 697 UNIX_DATA(p)->infd = (int)in; |
698 } | 698 } |
699 | 699 |
700 /* | 700 /* |
701 * Fork off a subprocess. P is a pointer to newly created subprocess | 701 * Fork off a subprocess. P is a pointer to a newly created subprocess |
702 * object. If this function signals, the caller is responsible for | 702 * object. If this function signals, the caller is responsible for |
703 * deleting (and finalizing) the process object. | 703 * deleting (and finalizing) the process object. |
704 * | 704 * |
705 * The method must return PID of the new process, a (positive??? ####) number | 705 * The method must return PID of the new process, a (positive??? ####) number |
706 * which fits into Lisp_Int. No return value indicates an error, the method | 706 * which fits into Lisp_Int. No return value indicates an error, the method |
712 Lisp_Object *argv, int nargv, | 712 Lisp_Object *argv, int nargv, |
713 Lisp_Object program, Lisp_Object cur_dir) | 713 Lisp_Object program, Lisp_Object cur_dir) |
714 { | 714 { |
715 /* This function rewritten by ben@xemacs.org. */ | 715 /* This function rewritten by ben@xemacs.org. */ |
716 | 716 |
717 int pid, inchannel, outchannel; | 717 int pid; |
718 int inchannel = -1; | |
719 int outchannel = -1; | |
718 /* Use volatile to protect variables from being clobbered by longjmp. */ | 720 /* Use volatile to protect variables from being clobbered by longjmp. */ |
719 volatile int forkin, forkout; | 721 volatile int forkin = -1; |
722 volatile int forkout = -1; | |
720 volatile int pty_flag = 0; | 723 volatile int pty_flag = 0; |
721 char **env; | |
722 char **new_argv; | |
723 char *current_dir; | |
724 int i; | |
725 | |
726 env = environ; | |
727 | |
728 inchannel = outchannel = forkin = forkout = -1; | |
729 | |
730 /* Nothing below here GCs so our string pointers shouldn't move. */ | |
731 new_argv = alloca_array (char *, nargv + 2); | |
732 GET_C_STRING_FILENAME_DATA_ALLOCA (program, new_argv[0]); | |
733 for (i = 0; i < nargv; i++) | |
734 { | |
735 Lisp_Object tem = argv[i]; | |
736 CHECK_STRING (tem); | |
737 new_argv[i + 1] = (char *) XSTRING_DATA (tem); | |
738 } | |
739 new_argv[i + 1] = 0; | |
740 GET_C_STRING_FILENAME_DATA_ALLOCA (cur_dir, current_dir); | |
741 | 724 |
742 #ifdef HAVE_PTYS | 725 #ifdef HAVE_PTYS |
743 if (!NILP (Vprocess_connection_type)) | 726 if (!NILP (Vprocess_connection_type)) |
744 { | 727 { |
745 /* find a new pty, open the master side, return the opened | 728 /* find a new pty, open the master side, return the opened |
753 /* You're "supposed" to now open the slave in the child. | 736 /* You're "supposed" to now open the slave in the child. |
754 On some systems, we can open it here; this allows for | 737 On some systems, we can open it here; this allows for |
755 better error checking. */ | 738 better error checking. */ |
756 #if !defined(USG) | 739 #if !defined(USG) |
757 /* On USG systems it does not work to open the pty's tty here | 740 /* On USG systems it does not work to open the pty's tty here |
758 and then close and reopen it in the child. */ | 741 and then close and reopen it in the child. */ |
759 #ifdef O_NOCTTY | 742 #ifdef O_NOCTTY |
760 /* Don't let this terminal become our controlling terminal | 743 /* Don't let this terminal become our controlling terminal |
761 (in case we don't have one). */ | 744 (in case we don't have one). */ |
762 forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY | OPEN_BINARY, 0); | 745 forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY | OPEN_BINARY, 0); |
763 #else | 746 #else |
913 a SIG_IGN handling from our parent (nohup) and we are in new | 896 a SIG_IGN handling from our parent (nohup) and we are in new |
914 process group. | 897 process group. |
915 */ | 898 */ |
916 signal (SIGHUP, SIG_DFL); | 899 signal (SIGHUP, SIG_DFL); |
917 } | 900 } |
901 | |
902 if (pty_flag) | |
903 /* Set up the terminal characteristics of the pty. */ | |
904 child_setup_tty (xforkout); | |
905 | |
918 #endif /* HAVE_PTYS */ | 906 #endif /* HAVE_PTYS */ |
919 | 907 |
920 signal (SIGINT, SIG_DFL); | 908 signal (SIGINT, SIG_DFL); |
921 signal (SIGQUIT, SIG_DFL); | 909 signal (SIGQUIT, SIG_DFL); |
922 | 910 |
923 if (pty_flag) | 911 { |
924 { | 912 char *current_dir; |
925 /* Set up the terminal characteristics of the pty. */ | 913 char **new_argv = alloca_array (char *, nargv + 2); |
926 child_setup_tty (xforkout); | 914 int i; |
927 } | 915 |
928 | 916 /* Nothing below here GCs so our string pointers shouldn't move. */ |
929 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir); | 917 new_argv[0] = (char *) XSTRING_DATA (program); |
930 } | 918 for (i = 0; i < nargv; i++) |
931 | 919 { |
920 CHECK_STRING (argv[i]); | |
921 new_argv[i + 1] = (char *) XSTRING_DATA (argv[i]); | |
922 } | |
923 new_argv[i + 1] = 0; | |
924 | |
925 GET_C_STRING_FILENAME_DATA_ALLOCA (cur_dir, current_dir); | |
926 | |
927 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir); | |
928 } | |
929 | |
930 } /**** End of child code ****/ | |
931 | |
932 /**** Back in parent process ****/ | |
932 #if !defined(__CYGWIN32__) | 933 #if !defined(__CYGWIN32__) |
933 environ = save_environ; | 934 environ = save_environ; |
934 #endif | 935 #endif |
935 } | 936 } |
936 | 937 |
966 we're waiting for an event, when status_notify() is called). */ | 967 we're waiting for an event, when status_notify() is called). */ |
967 return pid; | 968 return pid; |
968 | 969 |
969 io_failure: | 970 io_failure: |
970 { | 971 { |
971 int temp = errno; | 972 int save_errno = errno; |
972 close_descriptor_pair (forkin, forkout); | 973 close_descriptor_pair (forkin, forkout); |
973 close_descriptor_pair (inchannel, outchannel); | 974 close_descriptor_pair (inchannel, outchannel); |
974 errno = temp; | 975 errno = save_errno; |
975 report_file_error ("Opening pty or pipe", Qnil); | 976 report_file_error ("Opening pty or pipe", Qnil); |
977 return 0; /* not reached */ | |
976 } | 978 } |
977 | |
978 RETURN_NOT_REACHED (0); | |
979 } | 979 } |
980 | 980 |
981 /* Return nonzero if this process is a ToolTalk connection. */ | 981 /* Return nonzero if this process is a ToolTalk connection. */ |
982 | 982 |
983 static int | 983 static int |