| version 1.2, 2001/09/21 19:44:51 |
version 1.3, 2001/09/21 19:54:45 |
|
|
| /* |
/* |
| * $Log$ |
* $Log$ |
| |
* Revision 1.3 2001/09/21 19:54:45 host8 |
| |
* Cosmetics changes in *.c |
| |
* |
| * Revision 1.2 2001/09/21 19:44:51 host8 |
* Revision 1.2 2001/09/21 19:44:51 host8 |
| * Added $Log$ keyword substitution |
* Added $Log$ |
| |
* Added Revision 1.3 2001/09/21 19:54:45 host8 |
| |
* Added Cosmetics changes in *.c |
| |
* Added keyword substitution |
| * |
* |
| */ |
*/ |
| #ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
| Line 45 proctable_get_size(ptbl) |
|
| Line 51 proctable_get_size(ptbl) |
|
| } |
} |
| |
|
| |
|
| PROCTABLE |
PROCTABLE |
| proctable_get_from_cmdline(argc, argv) |
proctable_get_from_cmdline(argc, argv) |
| int argc; |
int argc; |
| char **argv; |
char **argv; |
| Line 54 proctable_get_from_cmdline(argc, argv) |
|
| Line 60 proctable_get_from_cmdline(argc, argv) |
|
| } |
} |
| |
|
| |
|
| PROCTABLE |
PROCTABLE |
| proctable_get_from_array(size, array) |
proctable_get_from_array(size, array) |
| int size; |
int size; |
| char** array; |
char** array; |
| Line 74 proctable_get_from_array(size, array) |
|
| Line 80 proctable_get_from_array(size, array) |
|
| while (begin_proc_id < size) { |
while (begin_proc_id < size) { |
| |
|
| /* Process table is a list of process ended with NULL. */ |
/* Process table is a list of process ended with NULL. */ |
| ptbl = (PROCTABLE) realloc(ptbl, |
ptbl = (PROCTABLE) realloc(ptbl, |
| (n_proc + 2) * sizeof(struct process *)); |
(n_proc + 2) * sizeof(struct process *)); |
| if (ptbl == NULL) { |
if (ptbl == NULL) { |
| msg_error_print("realloc() failure\n"); |
msg_error_print("realloc() failure\n"); |
| Line 104 proctable_get_from_array(size, array) |
|
| Line 110 proctable_get_from_array(size, array) |
|
| return NULL; |
return NULL; |
| } |
} |
| |
|
| if (process_init_by_array(ptbl[n_proc], |
if (process_init_by_array(ptbl[n_proc], |
| end_proc_id - begin_proc_id, |
end_proc_id - begin_proc_id, |
| array + begin_proc_id)) ; |
array + begin_proc_id)) ; |
| else { |
else { |
| proctable_destroy(&ptbl); |
proctable_destroy(&ptbl); |
| Line 119 proctable_get_from_array(size, array) |
|
| Line 125 proctable_get_from_array(size, array) |
|
| return ptbl; |
return ptbl; |
| } |
} |
| |
|
| void |
void |
| proctable_destroy(p_ptbl) |
proctable_destroy(p_ptbl) |
| PROCTABLE *p_ptbl; |
PROCTABLE *p_ptbl; |
| { |
{ |
| Line 148 proctable_get_process_index_by_pid(ptbl, |
|
| Line 154 proctable_get_process_index_by_pid(ptbl, |
|
| if (ptbl[i]->pid == pid) |
if (ptbl[i]->pid == pid) |
| return i; |
return i; |
| |
|
| return -1; |
return -1; |
| } |
} |
| |
|
| |
|
| Line 196 proctable_update(ptbl) |
|
| Line 202 proctable_update(ptbl) |
|
| register int i, j, k; |
register int i, j, k; |
| struct proclink link; |
struct proclink link; |
| |
|
| for(i = 0; ptbl[i] != NULL; i++) { |
for (i = 0; ptbl[i] != NULL; i++) { |
| link.proc_id = i; |
link.proc_id = i; |
| for (k = 0; k < N_FD; k++) { |
for (k = 0; k < N_FD; k++) { |
| link.fd_id = k; |
link.fd_id = k; |
| for (j = 0; j < ptbl[i]->fd[k].n_link; j++) { |
for (j = 0; j < ptbl[i]->fd[k].n_link; j++) { |
| |
|
| /* Invalid link? */ |
/* Invalid link? */ |
| if (ptbl[i]->fd[k].link[j].proc_id |
if (ptbl[i]->fd[k].link[j].proc_id |
| >= proctable_get_size(ptbl)) { |
>= proctable_get_size(ptbl)) { |
| msg_error_print("invalid process number -- %d\n", |
msg_error_print("invalid process number -- %d\n", |
| ptbl[i]->fd[k].link[j].proc_id); |
ptbl[i]->fd[k].link[j].proc_id); |
| Line 211 proctable_update(ptbl) |
|
| Line 217 proctable_update(ptbl) |
|
| } |
} |
| |
|
| /* Selflink? */ |
/* Selflink? */ |
| if(i == ptbl[i]->fd[k].link[j].proc_id) { |
if (i == ptbl[i]->fd[k].link[j].proc_id) { |
| msg_error_print("cannot self link -- [%d].%s -> [%d].%s\n", |
msg_error_print("cannot self link -- [%d].%s -> [%d].%s\n", |
| i, fd_str[0][k], |
i, fd_str[0][k], |
| ptbl[i]->fd[k].link[j].proc_id, |
ptbl[i]->fd[k].link[j].proc_id, |
| Line 236 proctable_update(ptbl) |
|
| Line 242 proctable_update(ptbl) |
|
| if (i == 0) { |
if (i == 0) { |
| if (ptbl[i]->fd[k].link[j].fd_id == 0) |
if (ptbl[i]->fd[k].link[j].fd_id == 0) |
| break; |
break; |
| } |
} |
| else |
else |
| if (ptbl[i]->fd[k].link[j].fd_id == 0) { |
if (ptbl[i]->fd[k].link[j].fd_id == 0) { |
| if (ptbl[i]->fd[k].link[j].proc_id == 0) |
if (ptbl[i]->fd[k].link[j].proc_id == 0) |
| break; |
break; |
| } |
} |
| else |
else |
| if (ptbl[i]->fd[k].link[j].proc_id != 0) |
if (ptbl[i]->fd[k].link[j].proc_id != 0) |
| break; |
break; |
| } |
} |
| else { |
else { |
| if (i == 0) { |
if (i == 0) { |
| if (ptbl[i]->fd[k].link[j].fd_id != 0) |
if (ptbl[i]->fd[k].link[j].fd_id != 0) |
| break; |
break; |
| } |
} |
| else |
else |
| if (ptbl[i]->fd[k].link[j].fd_id != 0) { |
if (ptbl[i]->fd[k].link[j].fd_id != 0) { |
| if (ptbl[i]->fd[k].link[j].proc_id == 0) |
if (ptbl[i]->fd[k].link[j].proc_id == 0) |
| break; |
break; |
| } |
} |
| else |
else |
| if (ptbl[i]->fd[k].link[j].proc_id != 0) |
if (ptbl[i]->fd[k].link[j].proc_id != 0) |
| break; |
break; |
| Line 278 proctable_update(ptbl) |
|
| Line 284 proctable_update(ptbl) |
|
| fd[ptbl[i]->fd[k].link[j].fd_id], &link); |
fd[ptbl[i]->fd[k].link[j].fd_id], &link); |
| } |
} |
| } |
} |
| } |
} |
| |
|
| return 0; |
return 0; |
| } |
} |
| Line 296 proctable_create_pipes(ptbl) |
|
| Line 302 proctable_create_pipes(ptbl) |
|
| if (i == 0) { |
if (i == 0) { |
| /* Set the standart (basic) descriptors. */ |
/* Set the standart (basic) descriptors. */ |
| ptbl[0]->fd[k].pipe[0] = ptbl[0]->fd[k].pipe[1] = k; |
ptbl[0]->fd[k].pipe[0] = ptbl[0]->fd[k].pipe[1] = k; |
| } |
} |
| else { |
else { |
| #if DEBUG |
#if DEBUG |
| msg_debug_print("creating pipe ptbl[%d]->fd[%d].pipe", |
msg_debug_print("creating pipe ptbl[%d]->fd[%d].pipe", |
| Line 310 proctable_create_pipes(ptbl) |
|
| Line 316 proctable_create_pipes(ptbl) |
|
| return -1; |
return -1; |
| } |
} |
| |
|
| #if DEBUG |
#if DEBUG |
| msg_print(" = (%d, %d)\n", |
msg_print(" = (%d, %d)\n", |
| ptbl[i]->fd[k].pipe[0], ptbl[i]->fd[k].pipe[1]); |
ptbl[i]->fd[k].pipe[0], ptbl[i]->fd[k].pipe[1]); |
| #endif |
#endif |
| } |
} |
| } |
} |
| Line 323 proctable_create_pipes(ptbl) |
|
| Line 329 proctable_create_pipes(ptbl) |
|
| } |
} |
| |
|
| |
|
| int |
int |
| proctable_exec(ptbl) |
proctable_exec(ptbl) |
| PROCTABLE ptbl; |
PROCTABLE ptbl; |
| { |
{ |
| Line 333 proctable_exec(ptbl) |
|
| Line 339 proctable_exec(ptbl) |
|
| switch (ptbl[i]->pid = fork()) { |
switch (ptbl[i]->pid = fork()) { |
| |
|
| /* Parent process. */ |
/* Parent process. */ |
| default: |
default: |
| break; |
break; |
| |
|
| /* Error. */ |
/* Error. */ |
| Line 341 proctable_exec(ptbl) |
|
| Line 347 proctable_exec(ptbl) |
|
| return -1; |
return -1; |
| |
|
| /* Child process. */ |
/* Child process. */ |
| case 0: |
case 0: |
| for (k = 0; k < N_FD; k++) |
for (k = 0; k < N_FD; k++) |
| if (ptbl[i]->fd[k].n_link != 0) { |
if (ptbl[i]->fd[k].n_link != 0) { |
| close(k); |
close(k); |
| Line 382 proctable_exec(ptbl) |
|
| Line 388 proctable_exec(ptbl) |
|
| } |
} |
| |
|
| |
|
| void |
void |
| proctable_close_2nd_sides_of_pipes(ptbl) |
proctable_close_2nd_sides_of_pipes(ptbl) |
| PROCTABLE ptbl; |
PROCTABLE ptbl; |
| { |
{ |
| register int i; |
register int i; |
| Line 402 proctable_remove_process(p_ptbl, index) |
|
| Line 408 proctable_remove_process(p_ptbl, index) |
|
| #if 0 |
#if 0 |
| register int proctable_size; |
register int proctable_size; |
| |
|
| /* |
/* |
| * We need to save value of process table size. |
* We need to save value of process table size. |
| */ |
*/ |
| proctable_size = proctable_get_size(*p_ptbl); |
proctable_size = proctable_get_size(*p_ptbl); |
| Line 411 proctable_remove_process(p_ptbl, index) |
|
| Line 417 proctable_remove_process(p_ptbl, index) |
|
| ///////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////// |
| // Pri odstraneni procesu je nutne: |
// Pri odstraneni procesu je nutne: |
| // - odstranit process z tabulky PROCTABLE a posunut vsetky za nim |
// - odstranit process z tabulky PROCTABLE a posunut vsetky za nim |
| // - prepisat vsetky linky v PROCTABLE |
// - prepisat vsetky linky v PROCTABLE |
| // - zrusit vsetky linky odkazujuce na dany process |
// - zrusit vsetky linky odkazujuce na dany process |
| // |
// |
| // Nepto [3/4/2001] |
// Nepto [3/4/2001] |
| Line 440 proctable_remove_process(p_ptbl, index) |
|
| Line 446 proctable_remove_process(p_ptbl, index) |
|
| /* Process table is a list of process ended with NULL. */ |
/* Process table is a list of process ended with NULL. */ |
| /* Resizing process table: '-1' is for size down by 1 */ |
/* Resizing process table: '-1' is for size down by 1 */ |
| /* '+1' cause we already go down by 1 */ |
/* '+1' cause we already go down by 1 */ |
| /* see the for() above */ |
/* see the for () above */ |
| /* '+1' is for ending NULL */ |
/* '+1' is for ending NULL */ |
| /* So the final is '+1'. */ |
/* So the final is '+1'. */ |
| |
|
| *p_ptbl = (PROCTABLE) realloc(*p_ptbl, |
*p_ptbl = (PROCTABLE) realloc(*p_ptbl, |
| (proctable_get_size(*p_ptbl) + 1) * sizeof(struct process *)); |
(proctable_get_size(*p_ptbl) + 1) * sizeof(struct process *)); |
| |
|
| if (*p_ptbl == NULL) { |
if (*p_ptbl == NULL) { |
| Line 471 proctable_print(ptbl) |
|
| Line 477 proctable_print(ptbl) |
|
| msg_print(" %s = (%d, %d)\n", fd_str[0][k], |
msg_print(" %s = (%d, %d)\n", fd_str[0][k], |
| ptbl[i]->fd[k].pipe[0], ptbl[i]->fd[k].pipe[1]); |
ptbl[i]->fd[k].pipe[0], ptbl[i]->fd[k].pipe[1]); |
| for (j = 0; j < ptbl[i]->fd[k].n_link; j++) |
for (j = 0; j < ptbl[i]->fd[k].n_link; j++) |
| msg_print(" [%d].%s %s [%d].%s\n", |
msg_print(" [%d].%s %s [%d].%s\n", |
| i, fd_str[0][k], |
i, fd_str[0][k], |
| ((i&&k) || (!i&&!k)) ? "->" : "<-", |
((i&&k) || (!i&&!k)) ? "->" : "<-", |
| ptbl[i]->fd[k].link[j].proc_id, |
ptbl[i]->fd[k].link[j].proc_id, |
| fd_str[0][ptbl[i]->fd[k].link[j].fd_id]); |
fd_str[0][ptbl[i]->fd[k].link[j].fd_id]); |
| Line 497 proctable_read(p_ptbl, p_fds) |
|
| Line 503 proctable_read(p_ptbl, p_fds) |
|
| datasize = read((*p_ptbl)[i]->fd[k].pipe[0], |
datasize = read((*p_ptbl)[i]->fd[k].pipe[0], |
| buf, BUFSIZE); |
buf, BUFSIZE); |
| |
|
| if (datasize == 0) |
if (datasize == 0) |
| close((*p_ptbl)[i]->fd[k].pipe[0]); |
close((*p_ptbl)[i]->fd[k].pipe[0]); |
| |
|
| if (datasize < 0) { |
if (datasize < 0) { |
| Line 515 proctable_read(p_ptbl, p_fds) |
|
| Line 521 proctable_read(p_ptbl, p_fds) |
|
| register int fd_write; |
register int fd_write; |
| register int proc_idx; |
register int proc_idx; |
| |
|
| proc_idx = (*p_ptbl)[i]->fd[k].link[j].proc_id; |
proc_idx = (*p_ptbl)[i]->fd[k].link[j].proc_id; |
| |
|
| fd_write = (*p_ptbl)[proc_idx]-> |
fd_write = (*p_ptbl)[proc_idx]-> |
| fd[(*p_ptbl)[i]->fd[k].link[j].fd_id].pipe[1]; |
fd[(*p_ptbl)[i]->fd[k].link[j].fd_id].pipe[1]; |
| Line 524 proctable_read(p_ptbl, p_fds) |
|
| Line 530 proctable_read(p_ptbl, p_fds) |
|
| struct proclink p1, p2; |
struct proclink p1, p2; |
| |
|
| p1.proc_id = i; |
p1.proc_id = i; |
| p1.fd_id = k; |
p1.fd_id = k; |
| p2.proc_id = (*p_ptbl)[i]->fd[k].link[j].proc_id; |
p2.proc_id = (*p_ptbl)[i]->fd[k].link[j].proc_id; |
| p2.fd_id = (*p_ptbl)[i]->fd[k].link[j].fd_id; |
p2.fd_id = (*p_ptbl)[i]->fd[k].link[j].fd_id; |
| |
|
| Line 542 proctable_read(p_ptbl, p_fds) |
|
| Line 548 proctable_read(p_ptbl, p_fds) |
|
| fd[p2.fd_id].pipe[1]); |
fd[p2.fd_id].pipe[1]); |
| |
|
| } |
} |
| else { |
else { |
| switch (write(fd_write, buf, datasize)) { |
switch (write(fd_write, buf, datasize)) { |
| case -1: |
case -1: |
| #if DEBUG |
#if DEBUG |
| msg_debug_print("proctable_read(): " |
msg_debug_print("proctable_read(): " |
| "write() failed: %s\n", |
"write() failed: %s\n", |
| strerror(errno)); |
strerror(errno)); |
| #endif |
#endif |
| break; |
break; |
| case 0: |
case 0: |
| #if DEBUG |
#if DEBUG |
| msg_debug_print("proctable_read(): " |
msg_debug_print("proctable_read(): " |
| "write() returns 0: %s\n", |
"write() returns 0: %s\n", |
| strerror(errno)); |
strerror(errno)); |
| #endif |
#endif |
| break; |
break; |
| Line 564 proctable_read(p_ptbl, p_fds) |
|
| Line 570 proctable_read(p_ptbl, p_fds) |
|
| } |
} |
| } |
} |
| } /* if (FD_ISSET()) */ |
} /* if (FD_ISSET()) */ |
| else |
else |
| datasize = 1; |
datasize = 1; |
| |
|
| if (datasize == 0) |
if (datasize == 0) |
| Line 586 proctable_wait(p_ptbl) |
|
| Line 592 proctable_wait(p_ptbl) |
|
| for (i = 0; (*p_ptbl)[i] != NULL; i++) { |
for (i = 0; (*p_ptbl)[i] != NULL; i++) { |
| |
|
| proc_n_link = 0; |
proc_n_link = 0; |
| for (k = 0; k < N_FD; k++) |
for (k = 0; k < N_FD; k++) |
| proc_n_link += (*p_ptbl)[i]->fd[k].n_link; |
proc_n_link += (*p_ptbl)[i]->fd[k].n_link; |
| |
|
| if (proc_n_link == 0) { |
if (proc_n_link == 0) { |
| Line 594 proctable_wait(p_ptbl) |
|
| Line 600 proctable_wait(p_ptbl) |
|
| /* Set up the wait() call. */ |
/* Set up the wait() call. */ |
| f_wait_call = 1; |
f_wait_call = 1; |
| |
|
| /* Don't need to browse the process table more. */ |
/* Don't need to browse the process table more. */ |
| break; |
break; |
| } |
} |
| } |
} |