| version 1.7, 2001/12/04 17:17:52 |
version 1.8, 2001/12/20 00:26:52 |
|
|
| * license: GNU General Public License |
* license: GNU General Public License |
| * |
* |
| * $Log$ |
* $Log$ |
| |
* Revision 1.8 2001/12/20 00:26:52 jombik9 |
| |
* Various Makefile & code improvements. |
| |
* wait() implementation - no error is reported on ctrl+d now |
| |
* |
| * Revision 1.7 2001/12/04 17:17:52 jombik9 |
* Revision 1.7 2001/12/04 17:17:52 jombik9 |
| * n_link sychronizations |
* n_link sychronizations |
| * |
* |
|
|
| # include "menu.h" |
# include "menu.h" |
| #endif |
#endif |
| |
|
| |
#define MAX_EBADF_COUNT (100) |
| |
|
| /* Global pointer to argv[0] (program name). */ |
/* Global pointer to argv[0] (program name). */ |
| char *argv0; |
char *argv0; |
| |
|
| Line 91 void exit_fnc(void) |
|
| Line 97 void exit_fnc(void) |
|
| msg_print("exit_fnc(): ep shutting down, sending all process SIGTERM...\n"); |
msg_print("exit_fnc(): ep shutting down, sending all process SIGTERM...\n"); |
| kill(0, SIGTERM); |
kill(0, SIGTERM); |
| */ |
*/ |
| |
#if DEBUG |
| |
msg_debug_print("exit_fnc(): %s terminating\n", argv0); |
| |
#endif |
| |
|
| msg_print("exit_fnc(): %s terminating\n", argv0); |
|
| free(argv0); |
free(argv0); |
| |
|
| #if MENU |
#if MENU |
| Line 106 main(argc, argv) |
|
| Line 114 main(argc, argv) |
|
| char **argv; |
char **argv; |
| { |
{ |
| register int i, k; |
register int i, k; |
| |
register int ret; |
| |
register int ebadf_count; |
| PROCTABLE ptbl; |
PROCTABLE ptbl; |
| fd_set fds; |
fd_set fds; |
| |
|
| Line 140 main(argc, argv) |
|
| Line 150 main(argc, argv) |
|
| |
|
| if (proctable_add_std_process(&ptbl) < 0 || proctable_update(ptbl) < 0) { |
if (proctable_add_std_process(&ptbl) < 0 || proctable_update(ptbl) < 0) { |
| msg_error_print("failure during operations with process table\n", |
msg_error_print("failure during operations with process table\n", |
| argv[0]); |
argv[0]); |
| return 1; |
return 1; |
| } |
} |
| #if DEBUG |
#if DEBUG |
| Line 190 main(argc, argv) |
|
| Line 200 main(argc, argv) |
|
| |
|
| /* Main loop. */ |
/* Main loop. */ |
| while (1) { |
while (1) { |
| /* Set fds. */ |
|
| FD_ZERO(&fds); |
|
| FD_SET(0, &fds); |
|
| for (i = 0; ptbl[i] != NULL; i++) |
|
| for (k = (i?1:0); k < (i?N_FD:1); k++) |
|
| if (1 || ptbl[i]->fd[k].n_link != 0) |
|
| FD_SET(ptbl[i]->fd[k].pipe[0], &fds); |
|
| |
|
| switch (select(FD_SETSIZE, &fds, NULL, NULL, NULL)) { |
ebadf_count = 0; |
| case -1: |
|
| #if DEBUG |
while (1) { |
| msg_debug_print("FD_SETSIZE = %d\n", FD_SETSIZE); |
|
| #endif |
/* Set fds. */ |
| |
FD_ZERO(&fds); |
| |
FD_SET(0, &fds); |
| |
for (i = 0; ptbl[i] != NULL; i++) |
| |
for (k = (i ? 1 : 0); k < (i ? N_FD : 1); k++) |
| |
if (0 || ptbl[i]->fd[k].n_link != 0) |
| |
FD_SET(ptbl[i]->fd[k].pipe[0], &fds); |
| |
|
| |
ret = select(FD_SETSIZE, &fds, NULL, NULL, NULL); |
| |
if (ret >= 0) |
| |
break; |
| |
|
| |
if (errno != EBADF || ebadf_count > MAX_EBADF_COUNT) { |
| msg_error_print("select() failure: %s\n", strerror(errno)); |
msg_error_print("select() failure: %s\n", strerror(errno)); |
| return errno; |
return errno; |
| break; |
} |
| |
else { |
| |
register int size; |
| |
|
| |
int status; |
| |
int pid; |
| |
int idx; |
| |
|
| |
pid = waitpid(-1, &status, WNOHANG); |
| |
|
| |
if (pid > 0) { |
| |
idx = proctable_get_process_index_by_pid(ptbl, pid); |
| |
if (proctable_remove_process(&ptbl, idx) < 0) { |
| |
msg_error_print("error during removing process from proctable\n"); |
| |
exit(1); |
| |
} |
| |
} |
| |
|
| |
if ((size = proctable_get_size(ptbl)) < 2) |
| |
return 0; |
| |
#if DEBUG |
| |
msg_debug_print("proctable_get_size() = %d\n", size); |
| |
#endif |
| |
ebadf_count++; |
| |
} |
| |
} |
| |
|
| default: |
|
| #if MENU |
#if MENU |
| if (FD_ISSET(0, &fds)) { |
if (FD_ISSET(0, &fds)) { |
| int c; |
int c; |
| c = getch(); |
c = getch(); |
| switch (c) { |
switch (c) { |
| case '\033': // ESC |
case '\033': // ESC |
| case KEY_F(9): |
case KEY_F(9): |
| menu_main(&ptbl); |
menu_main(&ptbl); |
| touchwin(stdscr); |
touchwin(stdscr); |
| refresh(); |
refresh(); |
| break; |
break; |
| case 12: // ^L |
case 12: // ^L |
| touchwin(stdscr); |
touchwin(stdscr); |
| refresh(); |
refresh(); |
| break; |
break; |
| default: |
default: |
| break; |
break; |
| |
|
| } |
} |
| } |
} |
| #endif /* #if MENU */ |
#endif /* #if MENU */ |
| |
|
| /* Read and transfer data. */ |
/* Read and transfer data. */ |
| proctable_read(&ptbl, &fds); |
proctable_read(&ptbl, &fds); |
| |
|
| /* Check if processes still running. */ |
/* Check if processes still running. */ |
| proctable_wait(&ptbl); |
proctable_wait(&ptbl); |
| |
|
| /* msg_debug_print("switch(select()) = default\n"); */ |
/* msg_debug_print("switch(select()) = default\n"); */ |
| |
|
| break; |
|
| } |
|
| } |
} |
| |
|
| |
|