| version 1.12, 2002/02/11 16:17:55 |
version 1.13, 2002/02/12 00:34:22 |
| Line 458 proctable_close_2nd_sides_of_pipes(ptbl) |
|
| Line 458 proctable_close_2nd_sides_of_pipes(ptbl) |
|
| } |
} |
| |
|
| int |
int |
| proctable_remove_process(p_ptbl, index) |
proctable_remove_process(p_ptbl, proc_id) |
| PROCTABLE *p_ptbl; |
PROCTABLE *p_ptbl; |
| const int index; |
const int proc_id; |
| { |
{ |
| register int i, j, k; |
register int i, j, k; |
| |
|
| Line 475 proctable_remove_process(p_ptbl, index) |
|
| Line 475 proctable_remove_process(p_ptbl, index) |
|
| |
|
| #if DEBUG |
#if DEBUG |
| msg_debug_print("proctable_remove_process(%p [%p], %d)\n", |
msg_debug_print("proctable_remove_process(%p [%p], %d)\n", |
| p_ptbl, *p_ptbl, index); |
p_ptbl, *p_ptbl, proc_id); |
| #endif |
#endif |
| |
|
| for (i = 0; (*p_ptbl)[i] != NULL; i++) { |
for (i = 0; (*p_ptbl)[i] != NULL; i++) { |
| Line 484 proctable_remove_process(p_ptbl, index) |
|
| Line 484 proctable_remove_process(p_ptbl, index) |
|
| msg_debug_print(" process %d fd %d n_link %d\n", |
msg_debug_print(" process %d fd %d n_link %d\n", |
| i, k, (*p_ptbl)[i]->fd[k].n_link); |
i, k, (*p_ptbl)[i]->fd[k].n_link); |
| #endif |
#endif |
| for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; j++) { |
for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; ) { |
| /*msg_debug_print("XXX: %p =? %p\n", |
/*msg_debug_print("XXX: %p =? %p\n", |
| &(*p_ptbl)[i]->fd[k], &((*p_ptbl)[i]->fd[k]));*/ |
&(*p_ptbl)[i]->fd[k], &((*p_ptbl)[i]->fd[k]));*/ |
| |
|
| if ((*p_ptbl)[i]->fd[k].link[j].proc_id > index) |
if ((*p_ptbl)[i]->fd[k].link[j].proc_id == proc_id) { |
| (*p_ptbl)[i]->fd[k].link[j].proc_id--; |
fd_remove_proclink_by_index(&(*p_ptbl)[i]->fd[k], j); |
| else |
} |
| if ((*p_ptbl)[i]->fd[k].link[j].proc_id == index) { |
else { |
| fd_remove_proclink_by_index(&(*p_ptbl)[i]->fd[k], j); |
if ((*p_ptbl)[i]->fd[k].link[j].proc_id > proc_id) |
| |
(*p_ptbl)[i]->fd[k].link[j].proc_id--; |
| } |
j++; |
| |
} |
| } |
} |
| } |
} |
| } |
} |
| |
|
| process_destroy((*p_ptbl)[index]); |
process_destroy((*p_ptbl)[proc_id]); |
| |
|
| for (i = index; (*p_ptbl)[i] != NULL; i++) { |
for (i = proc_id; (*p_ptbl)[i] != NULL; i++) { |
| (*p_ptbl)[i] = (*p_ptbl)[i + 1]; |
(*p_ptbl)[i] = (*p_ptbl)[i + 1]; |
| } |
} |
| |
|
| Line 706 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| Line 707 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| #endif |
#endif |
| |
|
| if (datasize == 0) { |
if (datasize == 0) { |
| |
/* TODO: multi reads from one fd doesn't work!!! */ |
| close((*p_ptbl)[i]->fd[k].pipe[0]); |
close((*p_ptbl)[i]->fd[k].pipe[0]); |
| #if DEBUG |
#if DEBUG |
| msg_debug_print("proctable_read(): close(%d)\n", |
msg_debug_print("proctable_read(): close(%d)\n", |
| Line 741 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| Line 743 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| i, k); |
i, k); |
| fd_remove_proclink2(&(((*p_ptbl)[i])->fd[k]), |
fd_remove_proclink2(&(((*p_ptbl)[i])->fd[k]), |
| proc_id, fd_id); |
proc_id, fd_id); |
| #if 0 |
|
| if (((*p_ptbl)[proc_id])->fd[fd_id].n_link == 0) { |
|
| my_close(fd_write); |
|
| /* FIXME: not needed probably */ |
|
| my_close((*p_ptbl)[proc_id]->fd[fd_id].pipe[0]); |
|
| } |
|
| #endif |
|
| } |
} |
| else { |
else { |
| #if 0 && DEBUG |
#if 0 && DEBUG |
| Line 797 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| Line 792 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| proctable_wait(p_ptbl) |
proctable_wait(p_ptbl) |
| PROCTABLE *p_ptbl; |
PROCTABLE *p_ptbl; |
| { |
{ |
| register int i, k, proc_n_link, f_wait_call = 0; |
|
| int pid = 0; |
int pid = 0; |
| |
int status; |
| #if 0 |
|
| for (i = 0; (*p_ptbl)[i] != NULL; i++) { |
|
| if (! i) |
|
| continue; |
|
| |
|
| proc_n_link = 0; |
|
| for (k = 0; k < N_FD; k++) |
|
| proc_n_link += (*p_ptbl)[i]->fd[k].n_link; |
|
| |
|
| if (proc_n_link == 0) { |
|
| |
|
| /* Set up the wait() call. */ |
|
| f_wait_call = 1; |
|
| |
|
| #if DEBUG |
#if DEBUG |
| msg_debug_print("proctable_wait(): candidate index = %d\n", i); |
msg_debug_print("proctable_wait(): f_wait_call == 1, calling wait()\n"); |
| #endif |
#endif |
| |
/* |
| |
* Parameters in waitpid: |
| |
* -1 == wait for any child process |
| |
* WNOHANG == return immediately if no child has exited. |
| |
*/ |
| |
pid = waitpid(-1, &status, WNOHANG); |
| |
|
| /* Don't need to browse the process table more. */ |
switch (pid) { |
| break; |
case -1: |
| } |
|
| } |
|
| #endif |
|
| |
|
| if (1 || f_wait_call != 0) { |
|
| int status; |
|
| |
|
| #if DEBUG |
|
| msg_debug_print("proctable_wait(): f_wait_call == 1, calling wait()\n"); |
|
| #endif |
|
| /* |
|
| * Parameters in waitpid: |
|
| * -1 == wait for any child process |
|
| * WNOHANG == return immediately if no child has exited. |
|
| */ |
|
| pid = waitpid(-1, &status, WNOHANG); |
|
| |
|
| switch (pid) { |
|
| case -1: |
|
| #if 0 |
#if 0 |
| msg_error_print("proctable_wait(): " |
msg_error_print("proctable_wait(): " |
| "waitpid() failure: %s\n", strerror(errno)); |
"waitpid() failure: %s\n", strerror(errno)); |
| #endif |
#endif |
| break; |
break; |
| |
|
| case 0: |
case 0: |
| #if DEBUG |
#if DEBUG |
| msg_warn_print("proctable_wait(): " |
msg_warn_print("proctable_wait(): " |
| "waitpid() warning: no child available\n"); |
"waitpid() warning: no child available\n"); |
| #endif |
#endif |
| |
|
| pid = 1; |
/* We will check if there is a process which should be |
| break; |
* terminated. If it is, we will return 1 and than main |
| |
* program will call us again after select() timeout. |
| |
*/ |
| |
{ |
| |
register int i, k, proc_n_link = 1; |
| |
|
| default: |
for (i = 1; (*p_ptbl)[i] != NULL; i++) { |
| { |
|
| register int index; |
|
| |
|
| index = proctable_get_process_index_by_pid(*p_ptbl, pid); |
|
| #if DEBUG |
|
| msg_debug_print("proctable_wait(): " |
|
| "pid = %d, index = %d\n", |
|
| pid, index); |
|
| |
|
| msg_debug_print("proctable_wait(): " |
|
| "proctable_get_size() = %d\n", |
|
| proctable_get_size(*p_ptbl)); |
|
| #endif |
|
| msg_print("[%d] ", pid); |
|
| |
|
| if (WIFEXITED(status)) { |
|
| msg_print("Exit"); |
|
| if (WEXITSTATUS(status)) |
|
| msg_print(" %d", WEXITSTATUS(status)); |
|
| } |
|
| else if (WIFSIGNALED(status)) { |
|
| register int sig_n = WTERMSIG(status); |
|
| |
|
| switch (sig_n) { |
for (proc_n_link = 0, k = 0; k < N_FD; k++) |
| case SIGKILL: |
proc_n_link += (*p_ptbl)[i]->fd[k].n_link; |
| msg_print("Killed"); |
|
| break; |
|
| case SIGTERM: |
|
| msg_print("Terminated"); |
|
| break; |
|
| case SIGSEGV: |
|
| msg_print("Segmentation fault"); |
|
| break; |
|
| default: |
|
| msg_print("Received signal %d", sig_n); |
|
| break; |
|
| }; |
|
| } |
|
| else { |
|
| msg_print("Aborted", pid); |
|
| } |
|
| |
|
| msg_print("\t\t\t\t"); |
if (proc_n_link == 0) { |
| msg_array_print((*p_ptbl)[index]->argv); |
#if DEBUG |
| msg_print("\n"); |
msg_debug_print("proctable_wait(): candidate index = %d\n", i); |
| #if DEBUG |
|
| msg_debug_print("proctable_wait(): " |
|
| "removing process from process table\n"); |
|
| #endif |
|
| proctable_remove_process(p_ptbl, index); |
|
| #if DEBUG |
|
| msg_debug_print("proctable_wait(): " |
|
| "proctable_get_size() = %d\n", |
|
| proctable_get_size(*p_ptbl)); |
|
| #endif |
#endif |
| |
/* Don't need to browse the process table more. */ |
| |
break; |
| |
} |
| } |
} |
| |
|
| break; |
if (proc_n_link == 0) |
| } /* switch (pid) */ |
pid = 1; |
| } |
} |
| else { |
break; |
| #if 0 && DEBUG |
|
| |
|
| pid = waitpid(-1, NULL, WNOHANG); |
default: |
| |
{ |
| |
register int index; |
| |
|
| |
index = proctable_get_process_index_by_pid(*p_ptbl, pid); |
| |
#if DEBUG |
| |
msg_debug_print("proctable_wait(): " |
| |
"pid = %d, index = %d\n", |
| |
pid, index); |
| |
|
| |
msg_debug_print("proctable_wait(): " |
| |
"proctable_get_size() = %d\n", |
| |
proctable_get_size(*p_ptbl)); |
| |
#endif |
| |
msg_print("[%d] ", pid); |
| |
|
| |
if (WIFEXITED(status)) { |
| |
msg_print("Exit"); |
| |
if (WEXITSTATUS(status)) |
| |
msg_print(" %d", WEXITSTATUS(status)); |
| |
} |
| |
else if (WIFSIGNALED(status)) { |
| |
register int sig_n = WTERMSIG(status); |
| |
|
| switch (pid) { |
switch (sig_n) { |
| case -1: |
case SIGKILL: |
| msg_debug_print("proctable_wait(): no candicate, " |
msg_print("Killed"); |
| "but error occured\n"); |
break; |
| pid = 0; |
case SIGTERM: |
| break; |
msg_print("Terminated"); |
| case 0: |
break; |
| msg_debug_print("proctable_wait(): no candicate\n"); |
case SIGSEGV: |
| break; |
msg_print("Segmentation fault"); |
| default: |
break; |
| msg_debug_print("proctable_wait(): no candicate, " |
default: |
| "but process with id %d removed\n", pid); |
msg_print("Received signal %d", sig_n); |
| break; |
break; |
| }; |
}; |
| |
} |
| |
else { |
| |
msg_print("Aborted", pid); |
| |
} |
| |
|
| |
msg_print("\t\t\t\t"); |
| |
msg_array_print((*p_ptbl)[index]->argv); |
| |
msg_print("\n"); |
| |
#if DEBUG |
| |
msg_debug_print("proctable_wait(): " |
| |
"removing process from process table\n"); |
| |
#endif |
| |
proctable_remove_process(p_ptbl, index); |
| |
#if DEBUG |
| |
msg_debug_print("proctable_wait(): " |
| |
"proctable_get_size() = %d\n", |
| |
proctable_get_size(*p_ptbl)); |
| #endif |
#endif |
| } |
} |
| |
|
| |
break; |
| |
} /* switch (pid) */ |
| |
|
| return pid; |
return pid; |
| } |
} |