| version 1.17, 2002/02/28 17:50:38 |
version 1.18, 2002/04/09 21:16:45 |
|
|
| #include "proctable.h" |
#include "proctable.h" |
| #include "process.h" |
#include "process.h" |
| #include "message.h" |
#include "message.h" |
| |
#include "conf.h" |
| |
|
| extern char *fd_str[][N_FD]; |
static char buf[BUFSIZE]; |
| extern char **environ; |
|
| |
|
| int |
int |
| proctable_get_size(ptbl) |
proctable_get_size(ptbl) |
| Line 396 proctable_exec(ptbl) |
|
| Line 396 proctable_exec(ptbl) |
|
| * errno will be set to indicate the error. |
* errno will be set to indicate the error. |
| */ |
*/ |
| |
|
| //msg_error_print("can't exec: %s\n", strerror(errno)); |
/* msg_error_print("can't exec: %s\n", strerror(errno)); */ |
| |
|
| exit(errno); |
exit(errno); |
| } |
} |
| Line 521 proctable_print(ptbl) |
|
| Line 521 proctable_print(ptbl) |
|
| } |
} |
| |
|
| int |
int |
| proctable_read(p_ptbl, p_rfds, p_efds) |
proctable_read(p_ptbl, p_rfds, p_wfds, p_efds) |
| PROCTABLE *p_ptbl; |
PROCTABLE *p_ptbl; |
| fd_set *p_rfds; |
fd_set *p_rfds; |
| |
fd_set *p_wfds; |
| fd_set *p_efds; |
fd_set *p_efds; |
| { |
{ |
| register int i, k, datasize = 1; |
register int i, k, datasize = 1; |
| char buf[BUFSIZE]; |
|
| |
|
| for (i = 0; (*p_ptbl)[i] != NULL; i++) { |
for (i = 0; (*p_ptbl)[i] != NULL; i++) { |
| for (k = 0; k < N_FD; k++) { |
for (k = 0; k < N_FD; k++) { |
| Line 550 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| Line 550 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| datasize = read((*p_ptbl)[i]->fd[k].pipe[0], |
datasize = read((*p_ptbl)[i]->fd[k].pipe[0], |
| buf, BUFSIZE); |
buf, BUFSIZE); |
| |
|
| #if 0 && DEBUG |
#if DEBUG |
| msg_debug_print("proctable_read(): descriptor change:" |
msg_debug_print("proctable_read(): descriptor change:" |
| " process %d, fd %d, datasize %d\n", |
" process %d, fd %d, datasize %d\n", |
| i, k, datasize); |
i, k, datasize); |
| Line 576 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| Line 576 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| exit(1); |
exit(1); |
| } |
} |
| |
|
| for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; j++) { |
if (datasize == 0) { |
| register int proc_id, fd_id; |
/* datasize is 0, we are going to remove all proclinks |
| register int fd_write; |
from/to this filedescriptor */ |
| |
while ((*p_ptbl)[i]->fd[k].n_link > 0) { |
| proc_id = (*p_ptbl)[i]->fd[k].link[j].proc_id; |
register int proc_id, fd_id; |
| fd_id = (*p_ptbl)[i]->fd[k].link[j].fd_id; |
|
| |
/* 0 means the first proclink; |
| fd_write = (*p_ptbl)[proc_id]->fd[fd_id].pipe[1]; |
we want remove them all */ |
| |
proc_id = (*p_ptbl)[i]->fd[k].link[0].proc_id; |
| |
fd_id = (*p_ptbl)[i]->fd[k].link[0].fd_id; |
| |
|
| if (datasize == 0) { |
|
| /* Process 1: id: i, fd: k */ |
/* Process 1: id: i, fd: k */ |
| /* Process 2: id: proc_id, fd: fd_id */ |
/* Process 2: id: proc_id, fd: fd_id */ |
| |
|
| Line 594 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| Line 595 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| fd_remove_proclink2(&(((*p_ptbl)[i])->fd[k]), |
fd_remove_proclink2(&(((*p_ptbl)[i])->fd[k]), |
| proc_id, fd_id); |
proc_id, fd_id); |
| } |
} |
| else { |
} |
| |
else { |
| |
/* datasize is not null, we are going to transfer |
| |
datasize bytes to linked filedescriptors */ |
| |
|
| |
for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; j++) { |
| |
register int fd_write; |
| |
register int proc_id, fd_id; |
| |
|
| |
proc_id = (*p_ptbl)[i]->fd[k].link[j].proc_id; |
| |
fd_id = (*p_ptbl)[i]->fd[k].link[j].fd_id; |
| |
fd_write = (*p_ptbl)[proc_id]->fd[fd_id].pipe[1]; |
| #if 0 && DEBUG |
#if 0 && DEBUG |
| msg_debug_print("proctable_read(): descriptor write:" |
msg_debug_print("proctable_read(): descriptor write:" |
| " process %d, fd %d, datasize %d\n", |
" process %d, fd %d, datasize %d\n", |
| proc_idx, fd_write, datasize); |
proc_idx, fd_write, datasize); |
| #endif |
#endif |
| |
|
| switch (write(fd_write, buf, datasize)) { |
switch (write(fd_write, buf, datasize)) { |
| case -1: |
case -1: |
| #if DEBUG |
#if DEBUG |
| Line 707 proctable_wait(p_ptbl) |
|
| Line 718 proctable_wait(p_ptbl) |
|
| "proctable_get_size() = %d\n", |
"proctable_get_size() = %d\n", |
| proctable_get_size(*p_ptbl)); |
proctable_get_size(*p_ptbl)); |
| #endif |
#endif |
| msg_print("[%d] ", pid); |
|
| |
|
| if (WIFEXITED(status)) { |
if (! cfg.silent) { |
| msg_print("Exit"); |
msg_print("[%d] ", pid); |
| if (WEXITSTATUS(status)) |
|
| msg_print(" %d", WEXITSTATUS(status)); |
if (WIFEXITED(status)) { |
| } |
msg_print("Exit"); |
| else if (WIFSIGNALED(status)) { |
if (WEXITSTATUS(status)) |
| register int sig_n = WTERMSIG(status); |
msg_print(" %d", WEXITSTATUS(status)); |
| |
} |
| switch (sig_n) { |
else if (WIFSIGNALED(status)) { |
| case SIGKILL: |
register int sig_n = WTERMSIG(status); |
| msg_print("Killed"); |
|
| break; |
switch (sig_n) { |
| case SIGTERM: |
case SIGKILL: |
| msg_print("Terminated"); |
msg_print("Killed"); |
| break; |
break; |
| case SIGSEGV: |
case SIGTERM: |
| msg_print("Segmentation fault"); |
msg_print("Terminated"); |
| break; |
break; |
| default: |
case SIGSEGV: |
| msg_print("Received signal %d", sig_n); |
msg_print("Segmentation fault"); |
| break; |
break; |
| }; |
default: |
| } |
msg_print("Received signal %d", sig_n); |
| else { |
break; |
| msg_print("Aborted", pid); |
}; |
| } |
} |
| |
else { |
| |
msg_print("Aborted", pid); |
| |
} |
| |
|
| msg_print("\t\t\t\t"); |
msg_print("\t\t\t\t"); |
| msg_array_print((*p_ptbl)[index]->argv); |
msg_array_print((*p_ptbl)[index]->argv); |
| msg_print("\n"); |
msg_print("\n"); |
| |
} /* if (! cfg.silent) */ |
| #if DEBUG |
#if DEBUG |
| msg_debug_print("proctable_wait(): " |
msg_debug_print("proctable_wait(): " |
| "removing process from process table\n"); |
"removing process from process table\n"); |