Mercurial > hg > xemacs-beta
comparison src/process.c @ 209:41ff10fd062f r20-4b3
Import from CVS: tag r20-4b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:04:58 +0200 |
parents | e45d5e7c476e |
children | d44af0c54775 |
comparison
equal
deleted
inserted
replaced
208:f427b8ec4379 | 209:41ff10fd062f |
---|---|
699 *forkin = sv[0]; | 699 *forkin = sv[0]; |
700 #endif /* not SKTPAIR */ | 700 #endif /* not SKTPAIR */ |
701 return 0; | 701 return 0; |
702 } | 702 } |
703 | 703 |
704 #ifndef VMS /* VMS version of this function is in vmsproc.c. */ | |
705 | 704 |
706 static Bufbyte | 705 static Bufbyte |
707 get_eof_char (struct Lisp_Process *p) | 706 get_eof_char (struct Lisp_Process *p) |
708 { | 707 { |
709 /* Figure out the eof character for the outfd of the given process. | 708 /* Figure out the eof character for the outfd of the given process. |
1081 close_descriptor_pair (inchannel, outchannel); | 1080 close_descriptor_pair (inchannel, outchannel); |
1082 errno = temp; | 1081 errno = temp; |
1083 report_file_error ("Opening pty or pipe", Qnil); | 1082 report_file_error ("Opening pty or pipe", Qnil); |
1084 } | 1083 } |
1085 } | 1084 } |
1086 #endif /* not VMS */ | |
1087 | 1085 |
1088 /* This function is the unwind_protect form for Fstart_process_internal. If | 1086 /* This function is the unwind_protect form for Fstart_process_internal. If |
1089 PROC doesn't have its pid set, then we know someone has signalled | 1087 PROC doesn't have its pid set, then we know someone has signalled |
1090 an error and the process wasn't started successfully, so we should | 1088 an error and the process wasn't started successfully, so we should |
1091 remove it from the process list. */ | 1089 remove it from the process list. */ |
1119 /* !!#### This function has not been Mule-ized */ | 1117 /* !!#### This function has not been Mule-ized */ |
1120 Lisp_Object buffer, name, program, proc, current_dir; | 1118 Lisp_Object buffer, name, program, proc, current_dir; |
1121 Lisp_Object tem; | 1119 Lisp_Object tem; |
1122 int speccount = specpdl_depth (); | 1120 int speccount = specpdl_depth (); |
1123 struct gcpro gcpro1, gcpro2, gcpro3; | 1121 struct gcpro gcpro1, gcpro2, gcpro3; |
1124 #ifdef VMS | |
1125 char *new_argv; | |
1126 int len; | |
1127 #else | |
1128 char **new_argv; | 1122 char **new_argv; |
1129 #endif | |
1130 int i; | 1123 int i; |
1131 | 1124 |
1132 name = args[0]; | 1125 name = args[0]; |
1133 buffer = args[1]; | 1126 buffer = args[1]; |
1134 program = args[2]; | 1127 program = args[2]; |
1160 if (NILP (Ffile_accessible_directory_p (current_dir))) | 1153 if (NILP (Ffile_accessible_directory_p (current_dir))) |
1161 report_file_error ("Setting current directory", | 1154 report_file_error ("Setting current directory", |
1162 list1 (current_buffer->directory)); | 1155 list1 (current_buffer->directory)); |
1163 #endif /* 0 */ | 1156 #endif /* 0 */ |
1164 | 1157 |
1165 #ifdef VMS | |
1166 /* Make a one member argv with all args concatenated | |
1167 together separated by a blank. */ | |
1168 len = XSTRING_LENGTH (program) + 2; | |
1169 for (i = 3; i < nargs; i++) | |
1170 { | |
1171 tem = args[i]; | |
1172 CHECK_STRING (tem); | |
1173 len += XSTRING_LENGTH (tem) + 1; /* count the blank */ | |
1174 } | |
1175 new_argv = (char *) alloca (len); | |
1176 strcpy (new_argv, XSTRING_DATA (program)); | |
1177 for (i = 3; i < nargs; i++) | |
1178 { | |
1179 tem = args[i]; | |
1180 CHECK_STRING (tem); | |
1181 strcat (new_argv, " "); | |
1182 strcat (new_argv, XSTRING_DATA (tem)); | |
1183 } | |
1184 /* Need to add code here to check for program existence on VMS */ | |
1185 | |
1186 #else /* not VMS */ | |
1187 /* If program file name is not absolute, search our path for it */ | 1158 /* If program file name is not absolute, search our path for it */ |
1188 if (!IS_DIRECTORY_SEP (XSTRING_BYTE (program, 0)) | 1159 if (!IS_DIRECTORY_SEP (XSTRING_BYTE (program, 0)) |
1189 && !(XSTRING_LENGTH (program) > 1 | 1160 && !(XSTRING_LENGTH (program) > 1 |
1190 && IS_DEVICE_SEP (XSTRING_BYTE (program, 1)))) | 1161 && IS_DEVICE_SEP (XSTRING_BYTE (program, 1)))) |
1191 { | 1162 { |
1214 tem = args[i]; | 1185 tem = args[i]; |
1215 CHECK_STRING (tem); | 1186 CHECK_STRING (tem); |
1216 new_argv[i - 2] = (char *) XSTRING_DATA (tem); | 1187 new_argv[i - 2] = (char *) XSTRING_DATA (tem); |
1217 } | 1188 } |
1218 new_argv[i - 2] = 0; | 1189 new_argv[i - 2] = 0; |
1219 | |
1220 #endif /* not VMS */ | |
1221 | 1190 |
1222 proc = make_process_internal (name); | 1191 proc = make_process_internal (name); |
1223 | 1192 |
1224 XPROCESS (proc)->buffer = buffer; | 1193 XPROCESS (proc)->buffer = buffer; |
1225 XPROCESS (proc)->command = Flist (nargs - 2, | 1194 XPROCESS (proc)->command = Flist (nargs - 2, |
1603 Charcount | 1572 Charcount |
1604 read_process_output (Lisp_Object proc) | 1573 read_process_output (Lisp_Object proc) |
1605 { | 1574 { |
1606 /* This function can GC */ | 1575 /* This function can GC */ |
1607 Bytecount nbytes, nchars; | 1576 Bytecount nbytes, nchars; |
1608 #ifdef VMS | |
1609 char *chars; | |
1610 #else | |
1611 Bufbyte chars[1024]; | 1577 Bufbyte chars[1024]; |
1612 #endif | |
1613 Lisp_Object outstream; | 1578 Lisp_Object outstream; |
1614 struct Lisp_Process *p = XPROCESS (proc); | 1579 struct Lisp_Process *p = XPROCESS (proc); |
1615 | 1580 |
1616 /* If there is a lot of output from the subprocess, the loop in | 1581 /* If there is a lot of output from the subprocess, the loop in |
1617 execute_internal_event() might call read_process_output() more | 1582 execute_internal_event() might call read_process_output() more |
1637 restore_match_data (); | 1602 restore_match_data (); |
1638 CHECK_INT (filter_result); | 1603 CHECK_INT (filter_result); |
1639 return XINT (filter_result); | 1604 return XINT (filter_result); |
1640 } | 1605 } |
1641 | 1606 |
1642 #ifdef VMS | |
1643 VMS_PROC_STUFF *vs, *get_vms_process_pointer(); | |
1644 | |
1645 vs = get_vms_process_pointer (XINT (p->pid)); | |
1646 if (vs) | |
1647 { | |
1648 if (!vs->iosb[0]) | |
1649 return 0; /* Really weird if it does this */ | |
1650 if (!(vs->iosb[0] & 1)) | |
1651 return -1; /* I/O error */ | |
1652 } | |
1653 else | |
1654 error ("Could not get VMS process pointer"); | |
1655 chars = vs->inputBuffer; | |
1656 nbytes = clean_vms_buffer (chars, vs->iosb[1]); | |
1657 if (nbytes <= 0) | |
1658 { | |
1659 start_vms_process_read (vs); /* Crank up the next read on the process */ | |
1660 return 1; /* Nothing worth printing, say we got 1 */ | |
1661 } | |
1662 #else /* not VMS */ | |
1663 | |
1664 #if 0 /* FSFmacs */ | 1607 #if 0 /* FSFmacs */ |
1665 /* #### equivalent code from FSFmacs. Would need some porting | 1608 /* #### equivalent code from FSFmacs. Would need some porting |
1666 for Windows NT. */ | 1609 for Windows NT. */ |
1667 if (proc_buffered_char[channel] < 0) | 1610 if (proc_buffered_char[channel] < 0) |
1668 #ifdef WINDOWSNT | 1611 #ifdef WINDOWSNT |
1686 } | 1629 } |
1687 #endif /* FSFmacs */ | 1630 #endif /* FSFmacs */ |
1688 | 1631 |
1689 nbytes = Lstream_read (XLSTREAM (p->instream), chars, sizeof (chars)); | 1632 nbytes = Lstream_read (XLSTREAM (p->instream), chars, sizeof (chars)); |
1690 if (nbytes <= 0) return nbytes; | 1633 if (nbytes <= 0) return nbytes; |
1691 #endif /* not VMS */ | |
1692 | 1634 |
1693 nchars = bytecount_to_charcount (chars, nbytes); | 1635 nchars = bytecount_to_charcount (chars, nbytes); |
1694 outstream = p->filter; | 1636 outstream = p->filter; |
1695 if (!NILP (outstream)) | 1637 if (!NILP (outstream)) |
1696 { | 1638 { |
1699 running_asynch_code = 1; | 1641 running_asynch_code = 1; |
1700 call2_trapping_errors ("Error in process filter", | 1642 call2_trapping_errors ("Error in process filter", |
1701 outstream, proc, make_string (chars, nbytes)); | 1643 outstream, proc, make_string (chars, nbytes)); |
1702 running_asynch_code = 0; | 1644 running_asynch_code = 0; |
1703 restore_match_data (); | 1645 restore_match_data (); |
1704 #ifdef VMS | |
1705 start_vms_process_read (vs); | |
1706 #endif | |
1707 return nchars; | 1646 return nchars; |
1708 } | 1647 } |
1709 | 1648 |
1710 /* If no filter, write into buffer if it isn't dead. */ | 1649 /* If no filter, write into buffer if it isn't dead. */ |
1711 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) | 1650 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) |
1790 BUF_ZV (buf)); | 1729 BUF_ZV (buf)); |
1791 BUF_SET_PT (buf, old_point); | 1730 BUF_SET_PT (buf, old_point); |
1792 | 1731 |
1793 UNGCPRO; | 1732 UNGCPRO; |
1794 } | 1733 } |
1795 #ifdef VMS | |
1796 start_vms_process_read (vs); | |
1797 #endif | |
1798 return nchars; | 1734 return nchars; |
1799 } | 1735 } |
1800 | 1736 |
1801 /* Sending data to subprocess */ | 1737 /* Sending data to subprocess */ |
1802 | 1738 |
1834 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc; | 1770 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc; |
1835 #else | 1771 #else |
1836 Lisp_Object defeat_volatile_kludge = proc; | 1772 Lisp_Object defeat_volatile_kludge = proc; |
1837 #endif | 1773 #endif |
1838 | 1774 |
1839 #ifdef VMS | |
1840 VMS_PROC_STUFF *vs, *get_vms_process_pointer (int); | |
1841 #endif /* VMS */ | |
1842 | |
1843 GCPRO2 (defeat_volatile_kludge, lstream); | 1775 GCPRO2 (defeat_volatile_kludge, lstream); |
1844 | 1776 |
1845 if (p->outfd < 0) | 1777 if (p->outfd < 0) |
1846 signal_simple_error ("Process not open for writing", proc); | 1778 signal_simple_error ("Process not open for writing", proc); |
1847 | |
1848 #ifdef VMS | |
1849 vs = get_vms_process_pointer (XINT (p->pid)); | |
1850 if (vs == 0) | |
1851 error ("Could not find this process: %x", | |
1852 XINT (p->pid)); | |
1853 else if (write_to_vms_process (vs, buf, len)) | |
1854 ; | |
1855 #else | |
1856 | 1779 |
1857 if (nonrelocatable) | 1780 if (nonrelocatable) |
1858 lstream = | 1781 lstream = |
1859 make_fixed_buffer_input_stream (nonrelocatable + start, len); | 1782 make_fixed_buffer_input_stream (nonrelocatable + start, len); |
1860 else if (GC_BUFFERP (relocatable)) | 1783 else if (GC_BUFFERP (relocatable)) |
1903 Lstream_flush (XLSTREAM (p->filedesc_stream)); | 1826 Lstream_flush (XLSTREAM (p->filedesc_stream)); |
1904 signal (SIGPIPE, old_sigpipe); | 1827 signal (SIGPIPE, old_sigpipe); |
1905 } | 1828 } |
1906 } | 1829 } |
1907 } | 1830 } |
1908 #endif /* !VMS */ | |
1909 else | 1831 else |
1910 { /* We got here from a longjmp() from the SIGPIPE handler */ | 1832 { /* We got here from a longjmp() from the SIGPIPE handler */ |
1911 signal (SIGPIPE, old_sigpipe); | 1833 signal (SIGPIPE, old_sigpipe); |
1912 p->status_symbol = Qexit; | 1834 p->status_symbol = Qexit; |
1913 p->exit_code = 256; /* #### SIGPIPE ??? */ | 1835 p->exit_code = 256; /* #### SIGPIPE ??? */ |
1914 p->core_dumped = 0; | 1836 p->core_dumped = 0; |
1915 p->tick++; | 1837 p->tick++; |
1916 process_tick++; | 1838 process_tick++; |
1917 deactivate_process (proc); | 1839 deactivate_process (proc); |
1918 #ifdef VMS | |
1919 error ("Error writing to process %s; closed it", | |
1920 XSTRING_DATA (p->name)); | |
1921 #else | |
1922 error ("SIGPIPE raised on process %s; closed it", | 1840 error ("SIGPIPE raised on process %s; closed it", |
1923 XSTRING_DATA (p->name)); | 1841 XSTRING_DATA (p->name)); |
1924 #endif | |
1925 } | 1842 } |
1926 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap); | 1843 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap); |
1927 Lstream_flush (XLSTREAM (p->outstream)); | 1844 Lstream_flush (XLSTREAM (p->outstream)); |
1928 signal (SIGPIPE, old_sigpipe); | 1845 signal (SIGPIPE, old_sigpipe); |
1929 UNGCPRO; | 1846 UNGCPRO; |
2204 | 2121 |
2205 CONST char * | 2122 CONST char * |
2206 signal_name (int signum) | 2123 signal_name (int signum) |
2207 { | 2124 { |
2208 if (signum >= 0 && signum < NSIG) | 2125 if (signum >= 0 && signum < NSIG) |
2209 #ifndef VMS | |
2210 return (CONST char *) sys_siglist[signum]; | 2126 return (CONST char *) sys_siglist[signum]; |
2211 #else | 2127 |
2212 return (CONST char *) sys_errlist[signum]; | |
2213 #endif | |
2214 return (CONST char *) GETTEXT ("unknown signal"); | 2128 return (CONST char *) GETTEXT ("unknown signal"); |
2215 } | 2129 } |
2216 | 2130 |
2217 /* Compute the Lisp form of the process status from | 2131 /* Compute the Lisp form of the process status from |
2218 the numeric status that was returned by `wait'. */ | 2132 the numeric status that was returned by `wait'. */ |
2880 if (!nomsg) | 2794 if (!nomsg) |
2881 status_notify (); | 2795 status_notify (); |
2882 break; | 2796 break; |
2883 #endif /* ! defined (SIGCONT) */ | 2797 #endif /* ! defined (SIGCONT) */ |
2884 case SIGINT: | 2798 case SIGINT: |
2885 #ifdef VMS | |
2886 send_process (proc, Qnil, (Bufbyte *) "\003", 0, | |
2887 1); /* ^C */ | |
2888 goto whoosh; | |
2889 #endif | |
2890 case SIGQUIT: | 2799 case SIGQUIT: |
2891 #ifdef VMS | |
2892 send_process (proc, Qnil, (Bufbyte *) "\031", 0, | |
2893 1); /* ^Y */ | |
2894 goto whoosh; | |
2895 #endif | |
2896 case SIGKILL: | 2800 case SIGKILL: |
2897 #ifdef VMS | |
2898 sys$forcex (&(XINT (p->pid)), 0, 1); | |
2899 whoosh: | |
2900 #endif | |
2901 flush_pending_output (p->infd); | 2801 flush_pending_output (p->infd); |
2902 break; | 2802 break; |
2903 } | 2803 } |
2904 | 2804 |
2905 /* If we don't have process groups, send the signal to the immediate | 2805 /* If we don't have process groups, send the signal to the immediate |
3138 | 3038 |
3139 /* Make sure the process is really alive. */ | 3039 /* Make sure the process is really alive. */ |
3140 if (! EQ (XPROCESS (proc)->status_symbol, Qrun)) | 3040 if (! EQ (XPROCESS (proc)->status_symbol, Qrun)) |
3141 error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name)); | 3041 error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name)); |
3142 | 3042 |
3143 #ifdef VMS | |
3144 send_process (proc, Qnil, (Bufbyte *) "\032", 0, 1); /* ^Z */ | |
3145 #else | |
3146 if (XPROCESS (proc)->pty_flag) | 3043 if (XPROCESS (proc)->pty_flag) |
3147 { | 3044 { |
3148 /* #### get_eof_char simply doesn't return the correct character | 3045 /* #### get_eof_char simply doesn't return the correct character |
3149 here. Maybe it is needed to determine the right eof | 3046 here. Maybe it is needed to determine the right eof |
3150 character in init_process_fds but here it simply screws | 3047 character in init_process_fds but here it simply screws |
3159 else | 3056 else |
3160 { | 3057 { |
3161 close (XPROCESS (proc)->outfd); | 3058 close (XPROCESS (proc)->outfd); |
3162 XPROCESS (proc)->outfd = open (NULL_DEVICE, O_WRONLY, 0); | 3059 XPROCESS (proc)->outfd = open (NULL_DEVICE, O_WRONLY, 0); |
3163 } | 3060 } |
3164 #endif /* !VMS */ | 3061 |
3165 return process; | 3062 return process; |
3166 } | 3063 } |
3167 | 3064 |
3168 | 3065 |
3169 /************************************************************************/ | 3066 /************************************************************************/ |
3199 /* It's possible that we got as far in the process-creation | 3096 /* It's possible that we got as far in the process-creation |
3200 process as creating the descriptors but didn't get so | 3097 process as creating the descriptors but didn't get so |
3201 far as selecting the process for input. In this | 3098 far as selecting the process for input. In this |
3202 case, p->pid is nil: p->pid is set at the same time that | 3099 case, p->pid is nil: p->pid is set at the same time that |
3203 the process is selected for input. */ | 3100 the process is selected for input. */ |
3204 #ifdef VMS | |
3205 { | |
3206 VMS_PROC_STUFF *get_vms_process_pointer (), *vs; | |
3207 if (outchannel >= 0) | |
3208 sys$dassgn (outchannel); | |
3209 vs = get_vms_process_pointer (XINT (p->pid)); | |
3210 if (vs) | |
3211 give_back_vms_process_stuff (vs); | |
3212 } | |
3213 #endif /* VMS */ | |
3214 /* Must call this before setting the file descriptors to 0 */ | 3101 /* Must call this before setting the file descriptors to 0 */ |
3215 event_stream_unselect_process (p); | 3102 event_stream_unselect_process (p); |
3216 } | 3103 } |
3217 | 3104 |
3218 p->infd = -1; | 3105 p->infd = -1; |