comparison src/process.c @ 39361:2d3bee6a3848

(sigchld_handler): Use GC_CONSP, GC_INTEGERP, GC_EQ since this function can be called during GC.
author Gerd Moellmann <gerd@gnu.org>
date Thu, 20 Sep 2001 11:44:03 +0000
parents 270e6cb4c672
children 9dd4ad9bc53e
comparison
equal deleted inserted replaced
39360:baed97f2160b 39361:2d3bee6a3848
4084 #endif /* VMS */ 4084 #endif /* VMS */
4085 return process; 4085 return process;
4086 } 4086 }
4087 4087
4088 /* Kill all processes associated with `buffer'. 4088 /* Kill all processes associated with `buffer'.
4089 If `buffer' is nil, kill all processes */ 4089 If `buffer' is nil, kill all processes */
4090 4090
4091 void 4091 void
4092 kill_buffer_processes (buffer) 4092 kill_buffer_processes (buffer)
4093 Lisp_Object buffer; 4093 Lisp_Object buffer;
4094 { 4094 {
4106 process_send_signal (proc, SIGHUP, Qnil, 1); 4106 process_send_signal (proc, SIGHUP, Qnil, 1);
4107 } 4107 }
4108 } 4108 }
4109 } 4109 }
4110 4110
4111 /* On receipt of a signal that a child status has changed, 4111 /* On receipt of a signal that a child status has changed, loop asking
4112 loop asking about children with changed statuses until 4112 about children with changed statuses until the system says there
4113 the system says there are no more. 4113 are no more.
4114 All we do is change the status; 4114
4115 we do not run sentinels or print notifications. 4115 All we do is change the status; we do not run sentinels or print
4116 That is saved for the next time keyboard input is done, 4116 notifications. That is saved for the next time keyboard input is
4117 in order to avoid timing errors. */ 4117 done, in order to avoid timing errors.
4118 4118
4119 /** WARNING: this can be called during garbage collection. 4119 ** WARNING: this can be called during garbage collection.
4120 Therefore, it must not be fooled by the presence of mark bits in 4120 Therefore, it must not be fooled by the presence of mark bits in
4121 Lisp objects. */ 4121 Lisp objects.
4122 4122
4123 /** USG WARNING: Although it is not obvious from the documentation 4123 ** USG WARNING: Although it is not obvious from the documentation
4124 in signal(2), on a USG system the SIGCLD handler MUST NOT call 4124 in signal(2), on a USG system the SIGCLD handler MUST NOT call
4125 signal() before executing at least one wait(), otherwise the handler 4125 signal() before executing at least one wait(), otherwise the
4126 will be called again, resulting in an infinite loop. The relevant 4126 handler will be called again, resulting in an infinite loop. The
4127 portion of the documentation reads "SIGCLD signals will be queued 4127 relevant portion of the documentation reads "SIGCLD signals will be
4128 and the signal-catching function will be continually reentered until 4128 queued and the signal-catching function will be continually
4129 the queue is empty". Invoking signal() causes the kernel to reexamine 4129 reentered until the queue is empty". Invoking signal() causes the
4130 the SIGCLD queue. Fred Fish, UniSoft Systems Inc. */ 4130 kernel to reexamine the SIGCLD queue. Fred Fish, UniSoft Systems
4131 Inc. */
4131 4132
4132 SIGTYPE 4133 SIGTYPE
4133 sigchld_handler (signo) 4134 sigchld_handler (signo)
4134 int signo; 4135 int signo;
4135 { 4136 {
4157 do 4158 do
4158 { 4159 {
4159 errno = 0; 4160 errno = 0;
4160 pid = wait3 (&w, WNOHANG | WUNTRACED, 0); 4161 pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
4161 } 4162 }
4162 while (pid <= 0 && errno == EINTR); 4163 while (pid < 0 && errno == EINTR);
4163 4164
4164 if (pid <= 0) 4165 if (pid <= 0)
4165 { 4166 {
4166 /* A real failure. We have done all our job, so return. */ 4167 /* PID == 0 means no processes found, PID == -1 means a real
4168 failure. We have done all our job, so return. */
4167 4169
4168 /* USG systems forget handlers when they are used; 4170 /* USG systems forget handlers when they are used;
4169 must reestablish each time */ 4171 must reestablish each time */
4170 #if defined (USG) && !defined (POSIX_SIGNALS) 4172 #if defined (USG) && !defined (POSIX_SIGNALS)
4171 signal (signo, sigchld_handler); /* WARNING - must come after wait3() */ 4173 signal (signo, sigchld_handler); /* WARNING - must come after wait3() */
4182 #endif /* no WNOHANG */ 4184 #endif /* no WNOHANG */
4183 4185
4184 /* Find the process that signaled us, and record its status. */ 4186 /* Find the process that signaled us, and record its status. */
4185 4187
4186 p = 0; 4188 p = 0;
4187 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) 4189 for (tail = Vprocess_alist; GC_CONSP (tail); tail = XCDR (tail))
4188 { 4190 {
4189 proc = XCDR (XCAR (tail)); 4191 proc = XCDR (XCAR (tail));
4190 p = XPROCESS (proc); 4192 p = XPROCESS (proc);
4191 if (EQ (p->childp, Qt) && XFASTINT (p->pid) == pid) 4193 if (GC_EQ (p->childp, Qt) && XINT (p->pid) == pid)
4192 break; 4194 break;
4193 p = 0; 4195 p = 0;
4194 } 4196 }
4195 4197
4196 /* Look for an asynchronous process whose pid hasn't been filled 4198 /* Look for an asynchronous process whose pid hasn't been filled
4197 in yet. */ 4199 in yet. */
4198 if (p == 0) 4200 if (p == 0)
4199 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) 4201 for (tail = Vprocess_alist; GC_CONSP (tail); tail = XCDR (tail))
4200 { 4202 {
4201 proc = XCDR (XCAR (tail)); 4203 proc = XCDR (XCAR (tail));
4202 p = XPROCESS (proc); 4204 p = XPROCESS (proc);
4203 if (INTEGERP (p->pid) && XINT (p->pid) == -1) 4205 if (GC_INTEGERP (p->pid) && XINT (p->pid) == -1)
4204 break; 4206 break;
4205 p = 0; 4207 p = 0;
4206 } 4208 }
4207 4209
4208 /* Change the status of the process that was found. */ 4210 /* Change the status of the process that was found. */