comparison src/process.c @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents 8e84bee8ddd0
children 8626e4521993
comparison
equal deleted inserted replaced
370:bd866891f083 371:cc15677e0335
57 #include "systime.h" 57 #include "systime.h"
58 #include "syssignal.h" /* Always include before systty.h */ 58 #include "syssignal.h" /* Always include before systty.h */
59 #include "systty.h" 59 #include "systty.h"
60 #include "syswait.h" 60 #include "syswait.h"
61 61
62 Lisp_Object Qprocessp, Qprocess_live_p; 62 Lisp_Object Qprocessp;
63 63
64 /* Process methods */ 64 /* Process methods */
65 struct process_methods the_process_methods; 65 struct process_methods the_process_methods;
66 66
67 /* a process object is a network connection when its pid field a cons 67 /* a process object is a network connection when its pid field a cons
252 Return t if OBJECT is a process. 252 Return t if OBJECT is a process.
253 */ 253 */
254 (obj)) 254 (obj))
255 { 255 {
256 return PROCESSP (obj) ? Qt : Qnil; 256 return PROCESSP (obj) ? Qt : Qnil;
257 }
258
259 DEFUN ("process-live-p", Fprocess_live_p, 1, 1, 0, /*
260 Return t if OBJECT is a process that is alive.
261 */
262 (obj))
263 {
264 return PROCESSP (obj) && PROCESS_LIVE_P (XPROCESS (obj)) ? Qt : Qnil;
265 } 257 }
266 258
267 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /* 259 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
268 Return a list of all processes. 260 Return a list of all processes.
269 */ 261 */
515 p->exit_code = 0; 507 p->exit_code = 0;
516 508
517 pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir)); 509 pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir));
518 510
519 p->pid = make_int (pid); 511 p->pid = make_int (pid);
520 if (PROCESS_LIVE_P (p)) 512 if (!NILP(p->pipe_instream))
521 event_stream_select_process (p); 513 event_stream_select_process (p);
522 } 514 }
523 515
524 /* This function is the unwind_protect form for Fstart_process_internal. If 516 /* This function is the unwind_protect form for Fstart_process_internal. If
525 PROC doesn't have its pid set, then we know someone has signalled 517 PROC doesn't have its pid set, then we know someone has signalled
821 calls set the filter to t, we have to stop now. Return -1 rather 813 calls set the filter to t, we have to stop now. Return -1 rather
822 than 0 so execute_internal_event() doesn't close the process. 814 than 0 so execute_internal_event() doesn't close the process.
823 Really, the loop in execute_internal_event() should check itself 815 Really, the loop in execute_internal_event() should check itself
824 for a process-filter change, like in status_notify(); but the 816 for a process-filter change, like in status_notify(); but the
825 struct Lisp_Process is not exported outside of this file. */ 817 struct Lisp_Process is not exported outside of this file. */
826 if (!PROCESS_LIVE_P (p)) 818 if (NILP(p->pipe_instream))
827 return -1; /* already closed */ 819 return -1; /* already closed */
828 820
829 if (!NILP (p->filter) && (p->filter_does_read)) 821 if (!NILP (p->filter) && (p->filter_does_read))
830 { 822 {
831 Lisp_Object filter_result; 823 Lisp_Object filter_result;
1030 1022
1031 void 1023 void
1032 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read) 1024 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
1033 { 1025 {
1034 CHECK_PROCESS (proc); 1026 CHECK_PROCESS (proc);
1035 if (PROCESS_LIVE_P (XPROCESS (proc))) { 1027 if (PROCESS_LIVE_P (proc)) {
1036 if (EQ (filter, Qt)) 1028 if (EQ (filter, Qt))
1037 event_stream_unselect_process (XPROCESS (proc)); 1029 event_stream_unselect_process (XPROCESS (proc));
1038 else 1030 else
1039 event_stream_select_process (XPROCESS (proc)); 1031 event_stream_select_process (XPROCESS (proc));
1040 } 1032 }
1119 Return PROCESS's input coding system. 1111 Return PROCESS's input coding system.
1120 */ 1112 */
1121 (process)) 1113 (process))
1122 { 1114 {
1123 process = get_process (process); 1115 process = get_process (process);
1124 CHECK_LIVE_PROCESS (process);
1125 return decoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_instream) ); 1116 return decoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_instream) );
1126 } 1117 }
1127 1118
1128 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /* 1119 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
1129 Return PROCESS's output coding system. 1120 Return PROCESS's output coding system.
1130 */ 1121 */
1131 (process)) 1122 (process))
1132 { 1123 {
1133 process = get_process (process); 1124 process = get_process (process);
1134 CHECK_LIVE_PROCESS (process);
1135 return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_outstream)); 1125 return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_outstream));
1136 } 1126 }
1137 1127
1138 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /* 1128 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
1139 Return a pair of coding-system for decoding and encoding of PROCESS. 1129 Return a pair of coding-system for decoding and encoding of PROCESS.
1140 */ 1130 */
1141 (process)) 1131 (process))
1142 { 1132 {
1143 process = get_process (process); 1133 process = get_process (process);
1144 CHECK_LIVE_PROCESS (process);
1145 return Fcons (decoding_stream_coding_system 1134 return Fcons (decoding_stream_coding_system
1146 (XLSTREAM (XPROCESS (process)->coding_instream)), 1135 (XLSTREAM (XPROCESS (process)->coding_instream)),
1147 encoding_stream_coding_system 1136 encoding_stream_coding_system
1148 (XLSTREAM (XPROCESS (process)->coding_outstream))); 1137 (XLSTREAM (XPROCESS (process)->coding_outstream)));
1149 } 1138 }
1154 */ 1143 */
1155 (process, codesys)) 1144 (process, codesys))
1156 { 1145 {
1157 codesys = Fget_coding_system (codesys); 1146 codesys = Fget_coding_system (codesys);
1158 process = get_process (process); 1147 process = get_process (process);
1159 CHECK_LIVE_PROCESS (process);
1160
1161 set_decoding_stream_coding_system 1148 set_decoding_stream_coding_system
1162 (XLSTREAM (XPROCESS (process)->coding_instream), codesys); 1149 (XLSTREAM (XPROCESS (process)->coding_instream), codesys);
1163 return Qnil; 1150 return Qnil;
1164 } 1151 }
1165 1152
1169 */ 1156 */
1170 (process, codesys)) 1157 (process, codesys))
1171 { 1158 {
1172 codesys = Fget_coding_system (codesys); 1159 codesys = Fget_coding_system (codesys);
1173 process = get_process (process); 1160 process = get_process (process);
1174 CHECK_LIVE_PROCESS (process);
1175
1176 set_encoding_stream_coding_system 1161 set_encoding_stream_coding_system
1177 (XLSTREAM (XPROCESS (process)->coding_outstream), codesys); 1162 (XLSTREAM (XPROCESS (process)->coding_outstream), codesys);
1178 return Qnil; 1163 return Qnil;
1179 } 1164 }
1180 1165
1532 Lisp_Object proc = get_process (process); 1517 Lisp_Object proc = get_process (process);
1533 1518
1534 if (network_connection_p (proc)) 1519 if (network_connection_p (proc))
1535 error ("Network connection %s is not a subprocess", 1520 error ("Network connection %s is not a subprocess",
1536 XSTRING_DATA (XPROCESS(proc)->name)); 1521 XSTRING_DATA (XPROCESS(proc)->name));
1537 CHECK_LIVE_PROCESS (proc); 1522 if (!PROCESS_LIVE_P (proc))
1523 error ("Process %s is not active",
1524 XSTRING_DATA (XPROCESS(proc)->name));
1538 1525
1539 MAYBE_PROCMETH (kill_child_process, (proc, signo, current_group, nomsg)); 1526 MAYBE_PROCMETH (kill_child_process, (proc, signo, current_group, nomsg));
1540 } 1527 }
1541 1528
1542 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /* 1529 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
1886 p->exit_code = 0; 1873 p->exit_code = 0;
1887 p->core_dumped = 0; 1874 p->core_dumped = 0;
1888 p->tick++; 1875 p->tick++;
1889 process_tick++; 1876 process_tick++;
1890 } 1877 }
1891 else if (PROCESS_LIVE_P (p)) 1878 else if (!NILP(p->pipe_instream))
1892 { 1879 {
1893 Fkill_process (proc, Qnil); 1880 Fkill_process (proc, Qnil);
1894 /* Do this now, since remove_process will make sigchld_handler do nothing. */ 1881 /* Do this now, since remove_process will make sigchld_handler do nothing. */
1895 p->status_symbol = Qsignal; 1882 p->status_symbol = Qsignal;
1896 p->exit_code = SIGKILL; 1883 p->exit_code = SIGKILL;
1918 if (GC_PROCESSP (proc) 1905 if (GC_PROCESSP (proc)
1919 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer))) 1906 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer)))
1920 { 1907 {
1921 if (network_connection_p (proc)) 1908 if (network_connection_p (proc))
1922 Fdelete_process (proc); 1909 Fdelete_process (proc);
1923 else if (PROCESS_LIVE_P (XPROCESS (proc))) 1910 else if (!NILP (XPROCESS (proc)->pipe_instream))
1924 process_send_signal (proc, SIGHUP, 0, 1); 1911 process_send_signal (proc, SIGHUP, 0, 1);
1925 } 1912 }
1926 } 1913 }
1927 } 1914 }
1928 1915
1977 1964
1978 void 1965 void
1979 syms_of_process (void) 1966 syms_of_process (void)
1980 { 1967 {
1981 defsymbol (&Qprocessp, "processp"); 1968 defsymbol (&Qprocessp, "processp");
1982 defsymbol (&Qprocess_live_p, "process-live-p");
1983 defsymbol (&Qrun, "run"); 1969 defsymbol (&Qrun, "run");
1984 defsymbol (&Qstop, "stop"); 1970 defsymbol (&Qstop, "stop");
1985 defsymbol (&Qopen, "open"); 1971 defsymbol (&Qopen, "open");
1986 defsymbol (&Qclosed, "closed"); 1972 defsymbol (&Qclosed, "closed");
1987 1973
1990 #ifdef HAVE_MULTICAST 1976 #ifdef HAVE_MULTICAST
1991 defsymbol(&Qmulticast, "multicast"); /* Used for occasional warnings */ 1977 defsymbol(&Qmulticast, "multicast"); /* Used for occasional warnings */
1992 #endif 1978 #endif
1993 1979
1994 DEFSUBR (Fprocessp); 1980 DEFSUBR (Fprocessp);
1995 DEFSUBR (Fprocess_live_p);
1996 DEFSUBR (Fget_process); 1981 DEFSUBR (Fget_process);
1997 DEFSUBR (Fget_buffer_process); 1982 DEFSUBR (Fget_buffer_process);
1998 DEFSUBR (Fdelete_process); 1983 DEFSUBR (Fdelete_process);
1999 DEFSUBR (Fprocess_status); 1984 DEFSUBR (Fprocess_status);
2000 DEFSUBR (Fprocess_exit_status); 1985 DEFSUBR (Fprocess_exit_status);