Lines 112-117
Link Here
|
112 |
|
112 |
|
113 |
#include "extern.h" |
113 |
#include "extern.h" |
114 |
|
114 |
|
|
|
115 |
#if defined(USE_CREATEPROCESS) |
116 |
#include <windows.h> |
117 |
#endif |
118 |
|
115 |
#ifdef HAVE_WAIT_H |
119 |
#ifdef HAVE_WAIT_H |
116 |
# include <wait.h> |
120 |
# include <wait.h> |
117 |
#else |
121 |
#else |
Lines 148-156
Link Here
|
148 |
struct prp *prp_next; |
152 |
struct prp *prp_next; |
149 |
} RCP, *RCPPTR; |
153 |
} RCP, *RCPPTR; |
150 |
|
154 |
|
|
|
155 |
#if defined(USE_CREATEPROCESS) |
156 |
/* MS's HANDLE is basically a (void *) (winnt.h). */ |
157 |
typedef HANDLE DMHANDLE; |
158 |
#else |
159 |
typedef int DMHANDLE; |
160 |
#endif |
161 |
|
151 |
typedef struct pr { |
162 |
typedef struct pr { |
152 |
int pr_valid; |
163 |
int pr_valid; |
153 |
int pr_pid; |
164 |
DMHANDLE pr_pid; |
|
|
165 |
DMHANDLE pr_tid; |
154 |
CELLPTR pr_target; |
166 |
CELLPTR pr_target; |
155 |
int pr_ignore; |
167 |
int pr_ignore; |
156 |
int pr_last; |
168 |
int pr_last; |
Lines 160-176
Link Here
|
160 |
char *pr_dir; |
172 |
char *pr_dir; |
161 |
} PR; |
173 |
} PR; |
162 |
|
174 |
|
|
|
175 |
typedef struct tpid { |
176 |
DMHANDLE pid; |
177 |
DMHANDLE tid; |
178 |
} TPID; |
179 |
|
180 |
const TPID NOPID = { (DMHANDLE)-1, (DMHANDLE)0 }; |
181 |
|
163 |
static PR *_procs = NIL(PR); /* Array to hold concurrent processes. */ |
182 |
static PR *_procs = NIL(PR); /* Array to hold concurrent processes. */ |
164 |
static int _procs_size = 0; /* Savegard to find MAXPROCESS changes. */ |
183 |
static int _procs_size = 0; /* Savegard to find MAXPROCESS changes. */ |
165 |
static int _proc_cnt = 0; /* Number of running processes. */ |
184 |
static int _proc_cnt = 0; /* Number of running processes. */ |
166 |
static int _abort_flg= FALSE; |
185 |
static int _abort_flg= FALSE; |
167 |
static int _use_i = -1; |
186 |
static int _use_i = -1; |
|
|
187 |
#if defined(USE_CREATEPROCESS) |
188 |
static HANDLE *_wpList = NIL(HANDLE); /* Array to hold pids to wait for. */ |
189 |
#endif |
168 |
|
190 |
|
169 |
static int _add_child ANSI((int, CELLPTR, int, int, int)); |
191 |
static int _add_child ANSI((TPID, CELLPTR, int, int, int)); |
170 |
static void _attach_cmd ANSI((char *, int, CELLPTR, t_attr, int)); |
192 |
static void _attach_cmd ANSI((char *, int, CELLPTR, t_attr, int)); |
171 |
static void _finished_child ANSI((int, int)); |
193 |
static void _finished_child ANSI((DMHANDLE, int)); |
172 |
static int _running ANSI((CELLPTR)); |
194 |
static int _running ANSI((CELLPTR)); |
173 |
|
195 |
|
|
|
196 |
/* Machine/OS dependent helpers. */ |
197 |
static DMHANDLE dmwaitnext ANSI((int *)); |
198 |
static DMHANDLE dmwaitpid ANSI((int, int *)); |
199 |
|
200 |
#if defined( USE_SPAWN ) |
201 |
|
202 |
int terrno; /* Temporarily store errno. */ |
203 |
|
204 |
static TPID dmspawn ANSI((char **)); |
205 |
|
206 |
static TPID |
207 |
dmspawn( argv ) |
208 |
char **argv; |
209 |
{ |
210 |
TPID pid; |
211 |
|
212 |
/* No error output is done here as stdout/stderr might be redirected. */ |
213 |
#if defined( __CYGWIN__) || defined( __EMX__) |
214 |
pid.pid = spawnvp(_P_NOWAIT, argv[0], (const char**) argv); |
215 |
pid.tid = 0; |
216 |
#elif defined(USE_CREATEPROCESS) |
217 |
static STARTUPINFO si; |
218 |
static int initSTARTUPINFO = FALSE; |
219 |
PROCESS_INFORMATION pi; |
220 |
|
221 |
/* si can be reused. */ |
222 |
if( initSTARTUPINFO == FALSE ) { |
223 |
initSTARTUPINFO = TRUE; |
224 |
ZeroMemory( &si, sizeof(si) ); |
225 |
si.cb = sizeof(si); |
226 |
} |
227 |
ZeroMemory( &pi, sizeof(pi) ); |
228 |
|
229 |
/* Start the child process. CreateProcess() parameters: |
230 |
* No module name (use command line). |
231 |
* Command line. This fails if the path to the program contains spaces. |
232 |
* Process handle not inheritable. |
233 |
* Thread handle not inheritable. |
234 |
* Set handle inheritance to FALSE. |
235 |
* No creation flags. |
236 |
* Use parent's environment block. |
237 |
* Use parent's starting directory. |
238 |
* Pointer to STARTUPINFO structure. |
239 |
* Pointer to PROCESS_INFORMATION structure. */ |
240 |
if( CreateProcess(NULL, argv[0], NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) ) { |
241 |
pid.pid = pi.hProcess; |
242 |
pid.tid = pi.hThread; |
243 |
} else { |
244 |
printf( "CreateProcess failed (%d).\n", GetLastError() ); |
245 |
pid.pid = (DMHANDLE)-1; |
246 |
} |
247 |
#else /* Non cygwin, OS/2, MinGW and MSC */ |
248 |
int tpid; |
249 |
if (posix_spawnp (&tpid, argv[0], NULL, NULL, argv, (char *)NULL)) |
250 |
tpid = -1; /* posix_spawn failed */ |
251 |
|
252 |
pid.pid = tpid; |
253 |
pid.tid = 0; |
254 |
#endif /* __CYGWIN__ */ |
255 |
return pid; |
256 |
} |
257 |
|
258 |
#endif /* USE_SPAWN */ |
259 |
|
260 |
static DMHANDLE |
261 |
dmwaitnext( status ) |
262 |
int *status; |
263 |
/* return pid we waited for, -1 if there |
264 |
* was nothing to wait for (ECHILD) and -2 for other errors. */ |
265 |
{ |
266 |
DMHANDLE wid; |
267 |
#if !defined(USE_CREATEPROCESS) |
268 |
/* Here might be the culprit for the famous OOo build hang. If |
269 |
* cygwin manages to "loose" a process and none else is left the |
270 |
* wait() will wait forever. */ |
271 |
wid = wait(status); |
272 |
|
273 |
/* If ECHILD is set from waitpid/wait then no child was left. */ |
274 |
if( wid == -1 ) { |
275 |
fprintf(stderr, "%s: Internal Error: wait() failed: %d - %s\n", |
276 |
Pname, errno, strerror(errno) ); |
277 |
if(errno != ECHILD) { |
278 |
/* Wait was interrupted or a child was terminated (SIGCHLD) */ |
279 |
return -2; |
280 |
} else { |
281 |
return -1; |
282 |
} |
283 |
} |
284 |
#else |
285 |
DWORD pEvent; |
286 |
DWORD dwExitCode = 0; |
287 |
|
288 |
/* Create a list of possible objects to wait for. */ |
289 |
int i; |
290 |
int numProc = 0; |
291 |
for( i=0; i<Max_proc; i++ ) { |
292 |
if(_procs[i].pr_valid) { |
293 |
_wpList[numProc++] = _procs[i].pr_pid; |
294 |
} |
295 |
} |
296 |
|
297 |
/* Wait ... */ |
298 |
/* number of objects in array, array of objects, |
299 |
* wait for any object, wait for the next child to finish */ |
300 |
pEvent = WaitForMultipleObjects( numProc, _wpList, FALSE, INFINITE); |
301 |
|
302 |
if( pEvent >= 0 && pEvent < WAIT_OBJECT_0 + numProc ) { |
303 |
wid = _wpList[pEvent - WAIT_OBJECT_0]; |
304 |
for( i=0; i<Max_proc && _procs[i].pr_pid != wid; i++ ) |
305 |
; |
306 |
if( i == Max_proc ) |
307 |
Fatal("Internal Error: Process not in pq !"); |
308 |
|
309 |
GetExitCodeProcess(wid, &dwExitCode); |
310 |
if(dwExitCode == STILL_ACTIVE) { |
311 |
/* Process did not terminate -> force it, with exit code 1. */ |
312 |
TerminateProcess(wid, 1); |
313 |
dwExitCode = 1; |
314 |
fprintf(stderr, "%s: Internal Error: Process still running - " |
315 |
"terminate it!\n", Pname ); |
316 |
} |
317 |
|
318 |
/* Close process and thread handles. */ |
319 |
CloseHandle( wid ); |
320 |
CloseHandle( _procs[i].pr_tid ); |
321 |
} |
322 |
else { |
323 |
int err = GetLastError(); |
324 |
LPVOID lpMsgBuf; |
325 |
|
326 |
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | |
327 |
FORMAT_MESSAGE_FROM_SYSTEM | |
328 |
FORMAT_MESSAGE_IGNORE_INSERTS, |
329 |
NULL, |
330 |
err, |
331 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
332 |
(LPTSTR) &lpMsgBuf, |
333 |
0, NULL ); |
334 |
|
335 |
fprintf(stderr, "%s: Internal Error: WaitForMultipleObjects() failed:" |
336 |
" %d - %s\n", Pname, err, lpMsgBuf); |
337 |
LocalFree(lpMsgBuf); |
338 |
|
339 |
/* No way to identify something comparable to ECHILD, always return -2.*/ |
340 |
wid = (DMHANDLE)-2; |
341 |
} |
342 |
|
343 |
|
344 |
*status = dwExitCode; |
345 |
#endif |
346 |
return wid; |
347 |
} |
348 |
|
349 |
|
350 |
static DMHANDLE |
351 |
dmwaitpid( pqid, status ) |
352 |
int pqid; |
353 |
int *status; |
354 |
/* return pid we waited for, 0 if it didn't finish yet, -1 if there |
355 |
* was nothing to wait for (ECHILD) and -2 for other errors. */ |
356 |
{ |
357 |
DMHANDLE wid; |
358 |
|
359 |
#if !defined(USE_CREATEPROCESS) |
360 |
wid = waitpid(_procs[pqid].pr_pid, status, WNOHANG); |
361 |
/* If ECHILD is set from waitpid/wait then no child was left. */ |
362 |
if( wid == -1 ) { |
363 |
fprintf(stderr, "%s: Internal Error: waitpid() failed: %d - %s\n", |
364 |
Pname, errno, strerror(errno) ); |
365 |
if(errno != ECHILD) { |
366 |
/* Wait was interrupted or a child was terminated (SIGCHLD) */ |
367 |
return -2; |
368 |
} else { |
369 |
return -1; |
370 |
} |
371 |
} |
372 |
#else |
373 |
DWORD pEvent; |
374 |
DWORD dwExitCode = 0; |
375 |
|
376 |
/* Wait ... (Check status and return) */ |
377 |
pEvent = WaitForSingleObject(_procs[pqid].pr_pid, 0); |
378 |
|
379 |
if( pEvent == WAIT_OBJECT_0 ) { |
380 |
GetExitCodeProcess(_procs[pqid].pr_pid, &dwExitCode); |
381 |
if(dwExitCode == STILL_ACTIVE) { |
382 |
/* Process did not terminate -> force it, with exit code 1. */ |
383 |
TerminateProcess(_procs[pqid].pr_pid, 1); |
384 |
dwExitCode = 1; |
385 |
fprintf(stderr, "%s: Internal Error: Process still running - " |
386 |
"terminate it!\n", Pname ); |
387 |
} |
388 |
|
389 |
/* Close process and thread handles. */ |
390 |
CloseHandle( _procs[pqid].pr_pid ); |
391 |
CloseHandle( _procs[pqid].pr_tid ); |
392 |
} |
393 |
else if( pEvent == WAIT_TIMEOUT ) { |
394 |
wid = 0; |
395 |
} |
396 |
else { |
397 |
int err = GetLastError(); |
398 |
LPVOID lpMsgBuf; |
399 |
|
400 |
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | |
401 |
FORMAT_MESSAGE_FROM_SYSTEM | |
402 |
FORMAT_MESSAGE_IGNORE_INSERTS, |
403 |
NULL, |
404 |
err, |
405 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
406 |
(LPTSTR) &lpMsgBuf, |
407 |
0, NULL ); |
408 |
|
409 |
fprintf(stderr, "%s: Internal Error: WaitForSingleObject() failed:" |
410 |
" %d - %s\n", Pname, err, lpMsgBuf); |
411 |
LocalFree(lpMsgBuf); |
412 |
|
413 |
printf("pEvent:%d: %d %d\n", pEvent, WAIT_OBJECT_0, WAIT_TIMEOUT); |
414 |
|
415 |
exit(1); |
416 |
|
417 |
/* No way to identify something comparable to ECHILD, always return -2.*/ |
418 |
wid = (DMHANDLE)-2; |
419 |
} |
420 |
|
421 |
*status = dwExitCode; |
422 |
#endif |
423 |
|
424 |
return wid; |
425 |
} |
426 |
|
427 |
|
174 |
#if ! HAVE_STRERROR |
428 |
#if ! HAVE_STRERROR |
175 |
static char * |
429 |
static char * |
176 |
private_strerror (errnum) |
430 |
private_strerror (errnum) |
Lines 211-217
Link Here
|
211 |
int mute = (cmnd_attr & A_MUTE) != 0; /* Mute output ('@@'). */ |
465 |
int mute = (cmnd_attr & A_MUTE) != 0; /* Mute output ('@@'). */ |
212 |
int wfc = (cmnd_attr & A_WFC) != 0; /* Wait for completion. */ |
466 |
int wfc = (cmnd_attr & A_WFC) != 0; /* Wait for completion. */ |
213 |
|
467 |
|
214 |
int pid; |
468 |
TPID pid; |
215 |
int st_pq = 0; /* Current _exec_shell target process index */ |
469 |
int st_pq = 0; /* Current _exec_shell target process index */ |
216 |
char *tcmd = *cmd; /* For saver/easier string arithmetic on *cmd. */ |
470 |
char *tcmd = *cmd; /* For saver/easier string arithmetic on *cmd. */ |
217 |
char **argv; |
471 |
char **argv; |
Lines 300-307
Link Here
|
300 |
} |
554 |
} |
301 |
if ( internal ) { |
555 |
if ( internal ) { |
302 |
/* Use _add_child() / _finished_child() with internal command. */ |
556 |
/* Use _add_child() / _finished_child() with internal command. */ |
303 |
int cur_proc = _add_child(-1, target, ignore, last, FALSE); |
557 |
int cur_proc = _add_child(NOPID, target, ignore, last, FALSE); |
304 |
_finished_child(-cur_proc, 0); |
558 |
_finished_child( (DMHANDLE)-cur_proc, 0 ); |
305 |
DB_RETURN( 0 ); |
559 |
DB_RETURN( 0 ); |
306 |
} |
560 |
} |
307 |
|
561 |
|
Lines 309-315
Link Here
|
309 |
argv = Pack_argv( group, shell, cmd ); |
563 |
argv = Pack_argv( group, shell, cmd ); |
310 |
|
564 |
|
311 |
/* Really spawn or fork a child. */ |
565 |
/* Really spawn or fork a child. */ |
312 |
#if ENABLE_SPAWN && ( HAVE_SPAWN_H || __CYGWIN__ || __EMX__) |
566 |
#if defined( USE_SPAWN ) |
313 |
/* As no other childs are started while the output is redirected this |
567 |
/* As no other childs are started while the output is redirected this |
314 |
* is save. */ |
568 |
* is save. */ |
315 |
if( Is_exec_shell ) { |
569 |
if( Is_exec_shell ) { |
Lines 326-348
Link Here
|
326 |
dup2( zerofd, 1 ); |
580 |
dup2( zerofd, 1 ); |
327 |
} |
581 |
} |
328 |
} |
582 |
} |
329 |
#if defined( __CYGWIN__) || defined( __EMX__) |
583 |
|
330 |
pid = spawnvp(_P_NOWAIT, argv[0], (const char**) argv); |
584 |
pid = dmspawn( argv ); |
331 |
#else /* __CYGWIN__ */ |
585 |
terrno = errno; |
332 |
if (posix_spawnp (&pid, argv[0], NULL, NULL, argv, (char *)NULL)) |
586 |
|
333 |
pid = -1; /* posix_spawn failed */ |
|
|
334 |
#endif /* __CYGWIN__ */ |
335 |
if( old_stdout != -1 ) { |
587 |
if( old_stdout != -1 ) { |
336 |
dup2(old_stdout, 1); |
588 |
dup2(old_stdout, 1); |
337 |
if( old_stderr != -1 ) |
589 |
if( old_stderr != -1 ) |
338 |
dup2(old_stderr, 2); |
590 |
dup2(old_stderr, 2); |
339 |
} |
591 |
} |
340 |
if(pid == -1) { |
592 |
if(pid.pid == (DMHANDLE)-1) { |
341 |
/* spawn failed */ |
593 |
/* spawn failed */ |
342 |
int cur_proc; |
594 |
int cur_proc; |
343 |
|
595 |
|
344 |
fprintf(stderr, "%s: Error executing '%s': %s", |
596 |
fprintf(stderr, "%s: Error executing '%s': %s", |
345 |
Pname, argv[0], strerror(errno) ); |
597 |
Pname, argv[0], strerror(terrno) ); |
346 |
if( ignore||Continue ) { |
598 |
if( ignore||Continue ) { |
347 |
fprintf(stderr, " (Ignored)" ); |
599 |
fprintf(stderr, " (Ignored)" ); |
348 |
} |
600 |
} |
Lines 350-357
Link Here
|
350 |
|
602 |
|
351 |
/* Use _add_child() / _finished_child() to treat the failure |
603 |
/* Use _add_child() / _finished_child() to treat the failure |
352 |
* gracefully, if so requested. */ |
604 |
* gracefully, if so requested. */ |
353 |
cur_proc = _add_child(-1, target, ignore, last, FALSE); |
605 |
cur_proc = _add_child(NOPID, target, ignore, last, FALSE); |
354 |
_finished_child(cur_proc, SIGTERM); |
606 |
_finished_child((DMHANDLE)cur_proc, SIGTERM); |
355 |
|
607 |
|
356 |
/* _finished_child() aborts dmake if we are not told to |
608 |
/* _finished_child() aborts dmake if we are not told to |
357 |
* ignore errors. If we reach the this point return 0 as |
609 |
* ignore errors. If we reach the this point return 0 as |
Lines 361-370
Link Here
|
361 |
} else { |
613 |
} else { |
362 |
_add_child(pid, target, ignore, last, wfc); |
614 |
_add_child(pid, target, ignore, last, wfc); |
363 |
} |
615 |
} |
364 |
#else /* ENABLE_SPAWN && ... */ |
616 |
#else /* USE_SPAWN */ |
365 |
|
617 |
|
366 |
fflush(stdout); |
618 |
fflush(stdout); |
367 |
switch( pid=fork() ){ |
619 |
switch( pid.pid = fork() ){ |
368 |
|
620 |
|
369 |
case -1: /* fork failed */ |
621 |
case -1: /* fork failed */ |
370 |
Fatal("fork failed: %s: %s", argv[0], strerror( errno )); |
622 |
Fatal("fork failed: %s: %s", argv[0], strerror( errno )); |
Lines 408-414
Link Here
|
408 |
_add_child(pid, target, ignore, last, wfc); |
660 |
_add_child(pid, target, ignore, last, wfc); |
409 |
} |
661 |
} |
410 |
|
662 |
|
411 |
#endif /* ENABLE_SPAWN && ... */ |
663 |
#endif /* USE_SPAWN */ |
412 |
|
664 |
|
413 |
DB_RETURN( 1 ); |
665 |
DB_RETURN( 1 ); |
414 |
} |
666 |
} |
Lines 429-436
Link Here
|
429 |
int abort_flg; |
681 |
int abort_flg; |
430 |
int pqid; |
682 |
int pqid; |
431 |
{ |
683 |
{ |
432 |
int pid; |
684 |
DMHANDLE pid; |
433 |
int wid; |
685 |
DMHANDLE wid; |
434 |
int status; |
686 |
int status; |
435 |
/* Never wait for internal commands. */ |
687 |
/* Never wait for internal commands. */ |
436 |
int waitchild; |
688 |
int waitchild; |
Lines 452-458
Link Here
|
452 |
if( i == Max_proc ) |
704 |
if( i == Max_proc ) |
453 |
return(-1); |
705 |
return(-1); |
454 |
|
706 |
|
455 |
pid = -1; |
707 |
pid = (DMHANDLE)-1; |
456 |
waitchild = FALSE; |
708 |
waitchild = FALSE; |
457 |
} |
709 |
} |
458 |
else { |
710 |
else { |
Lines 477-510
Link Here
|
477 |
|
729 |
|
478 |
do { |
730 |
do { |
479 |
/* Wait for the next process to finish. */ |
731 |
/* Wait for the next process to finish. */ |
480 |
if( (pid != -1) && (wid = waitpid(pid, &status, WNOHANG)) ) { |
732 |
if( (pid != (DMHANDLE)-1) && (wid = dmwaitpid(pqid, &status)) ) { |
481 |
/* if wid is 0 this means that pid didn't finish yet. In this case |
733 |
/* if wid is 0 this means that pid didn't finish yet. In this case |
482 |
* just handle the next finished process in the following "else". */ |
734 |
* just handle the next finished process in the following "else". */ |
483 |
; |
735 |
; |
484 |
} |
736 |
} |
485 |
else { |
737 |
else { |
486 |
/* Here might be the culprit for the famous OOo build hang. If |
738 |
wid = dmwaitnext(&status); |
487 |
* cygwin manages to "loose" a process and none else is left the |
|
|
488 |
* wait() will wait forever. */ |
489 |
wid = wait(&status); |
490 |
/* If we get an error tell the error handling routine below that we |
739 |
/* If we get an error tell the error handling routine below that we |
491 |
* were not waiting for a specific pid. */ |
740 |
* were not waiting for a specific pid. */ |
492 |
if( wid == -1 ) |
741 |
if( wid == (DMHANDLE)-1 ) |
493 |
pid = -1; |
742 |
pid = (DMHANDLE)-1; |
494 |
} |
743 |
} |
495 |
|
744 |
|
496 |
/* If ECHILD is set from waitpid/wait then no child was left. */ |
745 |
/* If ECHILD is set from waitpid/wait then no child was left. */ |
497 |
if( wid == -1 ) { |
746 |
if( (int)wid < 0 ) { /* Force int to check for sign. BRRR */ |
498 |
if(errno != ECHILD) { |
747 |
if(wid == (DMHANDLE)-2) { |
499 |
/* Wait was interrupted or a child was terminated (SIGCHLD) */ |
748 |
/* Wait was interrupted or a child was terminated (SIGCHLD) */ |
500 |
if ( in_quit() ) { |
749 |
if ( in_quit() ) { |
501 |
/* We're already terminating, just continue. */ |
750 |
/* We're already terminating, just continue. */ |
502 |
return 0; |
751 |
return 0; |
503 |
} else { |
752 |
} else { |
504 |
Fatal( "dmake was interrupted or a child terminated: %d : %s - stopping all childs ...", errno, strerror( errno ) ); |
753 |
Fatal( "dmake was interrupted or a child terminated. " |
|
|
754 |
"Stopping all childs ..." ); |
505 |
} |
755 |
} |
506 |
} else { |
756 |
} else { |
507 |
if( pid != -1 ) { |
757 |
/* The child we were waiting for is missing or no child is |
|
|
758 |
* left to wait for. */ |
759 |
if( pid != (DMHANDLE)-1 ) { |
508 |
/* If we know the pid disable the pq entry. */ |
760 |
/* If we know the pid disable the pq entry. */ |
509 |
if( _procs[pqid].pr_valid ) { |
761 |
if( _procs[pqid].pr_valid ) { |
510 |
_procs[pqid].pr_valid = 0; |
762 |
_procs[pqid].pr_valid = 0; |
Lines 564-574
Link Here
|
564 |
if( _procs != NIL(PR) ) { |
816 |
if( _procs != NIL(PR) ) { |
565 |
for( i=0; i<Max_proc; i++ ) |
817 |
for( i=0; i<Max_proc; i++ ) |
566 |
if( _procs[i].pr_valid ) { |
818 |
if( _procs[i].pr_valid ) { |
|
|
819 |
#if !defined(USE_CREATEPROCESS) |
567 |
if( (ret = kill(_procs[i].pr_pid, SIGTERM)) ) { |
820 |
if( (ret = kill(_procs[i].pr_pid, SIGTERM)) ) { |
568 |
fprintf(stderr, "Killing of pid %d from pq[%d] failed with: %s - %d ret: %d\n", |
821 |
fprintf(stderr, "Killing of pid %d from pq[%d] failed with: %s - %d ret: %d\n", |
569 |
_procs[i].pr_pid, i, |
822 |
_procs[i].pr_pid, i, |
570 |
strerror(errno), SIGTERM, ret ); |
823 |
strerror(errno), SIGTERM, ret ); |
571 |
} |
824 |
} |
|
|
825 |
#else |
826 |
TerminateProcess(_procs[i].pr_pid, 1); |
827 |
#endif |
572 |
} |
828 |
} |
573 |
} |
829 |
} |
574 |
} |
830 |
} |
Lines 584-590
Link Here
|
584 |
If wfc (wait for completion) is TRUE the function calls |
840 |
If wfc (wait for completion) is TRUE the function calls |
585 |
Wait_for_child to wait for the whole process queue to be finished. |
841 |
Wait_for_child to wait for the whole process queue to be finished. |
586 |
*/ |
842 |
*/ |
587 |
int pid; |
843 |
TPID pid; |
588 |
CELLPTR target; |
844 |
CELLPTR target; |
589 |
int ignore; |
845 |
int ignore; |
590 |
int last; |
846 |
int last; |
Lines 599-604
Link Here
|
599 |
if( _procs == NIL(PR) ) { |
855 |
if( _procs == NIL(PR) ) { |
600 |
_procs_size = Max_proc; |
856 |
_procs_size = Max_proc; |
601 |
TALLOC( _procs, Max_proc, PR ); |
857 |
TALLOC( _procs, Max_proc, PR ); |
|
|
858 |
#if defined(USE_CREATEPROCESS) |
859 |
TALLOC( _wpList, Max_proc, HANDLE ); |
860 |
|
861 |
/* Signed int values are cast to DMHANDLE in various places, use this |
862 |
* sanity check to verify that DMHANDLE is large enough. */ |
863 |
if( sizeof(int) > sizeof(DMHANDLE) ) |
864 |
Fatal( "Internal Error: Check type of DMHANDLE!" ); |
865 |
#endif |
602 |
} |
866 |
} |
603 |
else { |
867 |
else { |
604 |
Fatal( "MAXPROCESS changed from `%d' to `%d' after a command was executed!", _procs_size, Max_proc ); |
868 |
Fatal( "MAXPROCESS changed from `%d' to `%d' after a command was executed!", _procs_size, Max_proc ); |
Lines 624-630
Link Here
|
624 |
pp = _procs+i; |
888 |
pp = _procs+i; |
625 |
|
889 |
|
626 |
pp->pr_valid = 1; |
890 |
pp->pr_valid = 1; |
627 |
pp->pr_pid = pid; |
891 |
pp->pr_pid = pid.pid; |
|
|
892 |
pp->pr_tid = pid.tid; |
628 |
pp->pr_target = target; |
893 |
pp->pr_target = target; |
629 |
pp->pr_ignore = ignore; |
894 |
pp->pr_ignore = ignore; |
630 |
pp->pr_last = last; |
895 |
pp->pr_last = last; |
Lines 636-646
Link Here
|
636 |
|
901 |
|
637 |
_proc_cnt++; |
902 |
_proc_cnt++; |
638 |
|
903 |
|
639 |
if( pid != -1 ) { |
904 |
if( pid.pid != (DMHANDLE)-1 ) { |
640 |
/* Wait for each recipe to finish if wfc is TRUE. This |
905 |
/* Wait for each recipe to finish if wfc is TRUE. This |
641 |
* basically forces sequential execution. */ |
906 |
* basically forces sequential execution. */ |
642 |
if( wfc ) |
907 |
if( wfc ) { |
643 |
Wait_for_child( FALSE, i ); |
908 |
Wait_for_child( FALSE, i ); |
|
|
909 |
} |
644 |
|
910 |
|
645 |
return -1; |
911 |
return -1; |
646 |
} else |
912 |
} else |
Lines 657-671
Link Here
|
657 |
process and for cid < 1 -cid is used as the process array index of the |
923 |
process and for cid < 1 -cid is used as the process array index of the |
658 |
internal command. |
924 |
internal command. |
659 |
*/ |
925 |
*/ |
660 |
int cid; |
926 |
DMHANDLE cid; |
661 |
int status; |
927 |
int status; |
662 |
{ |
928 |
{ |
663 |
register int i; |
929 |
register int i; |
664 |
char *dir; |
930 |
char *dir; |
665 |
|
931 |
|
666 |
if(cid < 1) { |
932 |
if((int)cid < 1) { /* Force int. */ |
667 |
/* internal command */ |
933 |
/* internal command */ |
668 |
i = -cid; |
934 |
i = -((int)cid); |
669 |
} |
935 |
} |
670 |
else { |
936 |
else { |
671 |
for( i=0; i<Max_proc; i++ ) |
937 |
for( i=0; i<Max_proc; i++ ) |
Lines 718-724
Link Here
|
718 |
|
984 |
|
719 |
/* If all process queues are used wait for the next process to |
985 |
/* If all process queues are used wait for the next process to |
720 |
* finish. Is this really needed here? */ |
986 |
* finish. Is this really needed here? */ |
721 |
if( _proc_cnt == Max_proc ) Wait_for_child( FALSE, -1 ); |
987 |
if( _proc_cnt == Max_proc ) { |
|
|
988 |
Wait_for_child( FALSE, -1 ); |
989 |
} |
722 |
} |
990 |
} |
723 |
else { |
991 |
else { |
724 |
/* empty the queue on abort. */ |
992 |
/* empty the queue on abort. */ |