| version 1.13, 2002/02/12 00:34:22 |
version 1.14, 2002/02/19 14:35:37 |
| Line 71 PROCTABLE proctable_create(const int siz |
|
| Line 71 PROCTABLE proctable_create(const int siz |
|
| return ptbl; |
return ptbl; |
| } |
} |
| |
|
| PROCTABLE |
|
| proctable_get_from_cmdline(argc, argv) |
|
| int argc; |
|
| char **argv; |
|
| { |
|
| return proctable_get_from_array(argc - 1, argv + 1); |
|
| } |
|
| |
|
| |
|
| PROCTABLE |
|
| proctable_get_from_array(size, array) |
|
| int size; |
|
| char** array; |
|
| { |
|
| PROCTABLE ptbl; |
|
| register int n_proc; |
|
| register int begin_proc_id, end_proc_id; |
|
| |
|
| n_proc = 0; |
|
| begin_proc_id = 0; |
|
| ptbl = NULL; |
|
| |
|
| #if DEBUG |
|
| msg_debug_print("proctable_get_from_array(): size = %d\n", size); |
|
| #endif |
|
| |
|
| while (begin_proc_id < size) { |
|
| |
|
| /* Process table is a list of process ended with NULL. */ |
|
| ptbl = (PROCTABLE) realloc(ptbl, |
|
| (n_proc + 2) * sizeof(struct process *)); |
|
| if (ptbl == NULL) { |
|
| msg_error_print("realloc() failure\n"); |
|
| return NULL; |
|
| } |
|
| |
|
| ptbl[n_proc + 1] = NULL; |
|
| ptbl[n_proc] = (struct process *) malloc(sizeof(struct process)); |
|
| if (ptbl[n_proc] == NULL) { |
|
| msg_error_print("malloc() failure\n"); |
|
| proctable_destroy(&ptbl); |
|
| return NULL; |
|
| } |
|
| |
|
| end_proc_id = begin_proc_id; |
|
| while (end_proc_id != size && strcmp(array[end_proc_id], "--") != 0) |
|
| end_proc_id++; |
|
| |
|
| #if DEBUG |
|
| msg_debug_print("proctable_get_from_array(): " |
|
| "begin:end = %d:%d\n", begin_proc_id, end_proc_id); |
|
| #endif |
|
| |
|
| if (end_proc_id - begin_proc_id == 0) { |
|
| msg_error_print("bad placed '--'\n"); |
|
| proctable_destroy(&ptbl); |
|
| return NULL; |
|
| } |
|
| |
|
| if (process_init_by_array(ptbl[n_proc], |
|
| end_proc_id - begin_proc_id, |
|
| array + begin_proc_id)) ; |
|
| else { |
|
| proctable_destroy(&ptbl); |
|
| return NULL; |
|
| } |
|
| |
|
| begin_proc_id = end_proc_id + 1; |
|
| n_proc++; |
|
| } |
|
| |
|
| return ptbl; |
|
| } |
|
| |
|
| void |
void |
| proctable_destroy(p_ptbl) |
proctable_destroy(p_ptbl) |
| PROCTABLE *p_ptbl; |
PROCTABLE *p_ptbl; |
| Line 212 proctable_add_std_process(p_ptbl) |
|
| Line 138 proctable_add_std_process(p_ptbl) |
|
| } |
} |
| |
|
| for (; i >= 0; i--) |
for (; i >= 0; i--) |
| (*p_ptbl)[i+1] = (*p_ptbl)[i]; |
(*p_ptbl)[i + 1] = (*p_ptbl)[i]; |
| |
|
| (*p_ptbl)[0] = (struct process *) malloc(sizeof(struct process)); |
(*p_ptbl)[0] = (struct process *) malloc(sizeof(struct process)); |
| |
|
| Line 441 proctable_exec(ptbl) |
|
| Line 367 proctable_exec(ptbl) |
|
| } |
} |
| } |
} |
| |
|
| /* All fork() were OK. */ |
/* |
| /* Returning successfully. */ |
* All fork()-s were OK. |
| |
* Returning successfully. |
| |
*/ |
| |
|
| return 0; |
return 0; |
| } |
} |
| |
|
| Line 556 proctable_print(ptbl) |
|
| Line 485 proctable_print(ptbl) |
|
| } |
} |
| } |
} |
| |
|
| |
|
| int |
|
| proctable_read_old(p_ptbl, p_fds) |
|
| PROCTABLE *p_ptbl; |
|
| fd_set *p_fds; |
|
| { |
|
| register int i, k, datasize = 1; |
|
| char buf[BUFSIZE]; |
|
| |
|
| for (i = 0; (*p_ptbl)[i] != NULL; i++) { |
|
| for (k = (i ? 1 : 0); k < (i ? N_FD : 1); k++) { |
|
| if (FD_ISSET((*p_ptbl)[i]->fd[k].pipe[0], p_fds)) { |
|
| register int j; |
|
| |
|
| datasize = read((*p_ptbl)[i]->fd[k].pipe[0], |
|
| buf, BUFSIZE); |
|
| |
|
| #if 0 && DEBUG |
|
| msg_debug_print("proctable_read(): descriptor change:" |
|
| " process %d, fd %d, datasize %d\n", |
|
| i, k, datasize); |
|
| #endif |
|
| |
|
| if (datasize == 0) { |
|
| close((*p_ptbl)[i]->fd[k].pipe[0]); |
|
| #if DEBUG |
|
| msg_debug_print("proctable_read(): close(%d)\n", |
|
| (*p_ptbl)[i]->fd[k].pipe[0]); |
|
| #endif |
|
| } |
|
| |
|
| if (datasize < 0) { |
|
| #if DEBUG |
|
| msg_debug_print("proctable_read(): " |
|
| "read() failure, %d returned\n", |
|
| datasize); |
|
| #endif |
|
| msg_errno_print(); |
|
| msg_print("Terminating..."); |
|
| exit(1); |
|
| } |
|
| |
|
| for (j = 0; j < (*p_ptbl)[i]->fd[k].n_link; j++) { |
|
| register int fd_write; |
|
| register int proc_idx; |
|
| |
|
| proc_idx = (*p_ptbl)[i]->fd[k].link[j].proc_id; |
|
| |
|
| fd_write = (*p_ptbl)[proc_idx]-> |
|
| fd[(*p_ptbl)[i]->fd[k].link[j].fd_id].pipe[1]; |
|
| |
|
| if (datasize == 0) { |
|
| struct proclink p1, p2; |
|
| |
|
| p1.proc_id = i; |
|
| p1.fd_id = k; |
|
| p2.proc_id = (*p_ptbl)[i]->fd[k].link[j].proc_id; |
|
| p2.fd_id = (*p_ptbl)[i]->fd[k].link[j].fd_id; |
|
| |
|
| fd_remove_proclink( |
|
| &(((*p_ptbl)[p2.proc_id])->fd[p2.fd_id]), &p1); |
|
| fd_remove_proclink( |
|
| &(((*p_ptbl)[p1.proc_id])->fd[p1.fd_id]), &p2); |
|
| |
|
| if (((*p_ptbl)[p2.proc_id])->fd[p2.fd_id].n_link == 0) |
|
| /*my_*/close(((*p_ptbl)[p2.proc_id])-> |
|
| fd[p2.fd_id].pipe[1]); |
|
| |
|
| if (((*p_ptbl)[p2.proc_id])->fd[p2.fd_id].n_link == 0) |
|
| /*my_*/close(((*p_ptbl)[p2.proc_id])-> |
|
| fd[p2.fd_id].pipe[1]); |
|
| |
|
| } |
|
| else { |
|
| #if 0 && DEBUG |
|
| msg_debug_print("proctable_read(): descriptor write:" |
|
| " process %d, fd %d, datasize %d\n", |
|
| proc_idx, fd_write, datasize); |
|
| #endif |
|
| |
|
| switch (write(fd_write, buf, datasize)) { |
|
| case -1: |
|
| #if DEBUG |
|
| msg_debug_print("proctable_read(): " |
|
| "write() failed: %s\n", |
|
| strerror(errno)); |
|
| #endif |
|
| break; |
|
| case 0: |
|
| #if DEBUG |
|
| msg_debug_print("proctable_read(): " |
|
| "write() returns 0: %s\n", |
|
| strerror(errno)); |
|
| #endif |
|
| break; |
|
| default: |
|
| break; |
|
| } |
|
| } |
|
| } |
|
| } /* if (FD_ISSET()) */ |
|
| else |
|
| datasize = 1; |
|
| |
|
| if (datasize == 0) |
|
| break; |
|
| } |
|
| if (datasize == 0) |
|
| break; |
|
| } |
|
| |
|
| return 0; |
|
| } |
|
| |
|
| int |
int |
| proctable_read(p_ptbl, p_rfds, p_efds) |
proctable_read(p_ptbl, p_rfds, p_efds) |
| PROCTABLE *p_ptbl; |
PROCTABLE *p_ptbl; |
| Line 782 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| Line 597 proctable_read(p_ptbl, p_rfds, p_efds) |
|
| break; |
break; |
| } |
} |
| |
|
| //msg_debug_print("datasize on exit %d\n", datasize); |
|
| |
|
| /* Returns 0 if process was removed, 1 elsewhere. */ |
/* Returns 0 if process was removed, 1 elsewhere. */ |
| return datasize; |
return datasize; |
| } |
} |
| Line 799 proctable_wait(p_ptbl) |
|
| Line 612 proctable_wait(p_ptbl) |
|
| msg_debug_print("proctable_wait(): f_wait_call == 1, calling wait()\n"); |
msg_debug_print("proctable_wait(): f_wait_call == 1, calling wait()\n"); |
| #endif |
#endif |
| /* |
/* |
| * Parameters in waitpid: |
* Parameters in waitpid(): |
| * -1 == wait for any child process |
* 1. Value -1 means wait for any child process |
| * WNOHANG == return immediately if no child has exited. |
* 2. Constant WNOHANG means return immediately if no child has exited. |
| */ |
*/ |
| pid = waitpid(-1, &status, WNOHANG); |
pid = waitpid(-1, &status, WNOHANG); |
| |
|