diff -wur orig/wmdctrl-0.4.0/source/wmdctrl.c wmdctrl-0.4.0/source/wmdctrl.c --- orig/wmdctrl-0.4.0/source/wmdctrl.c Mon Oct 25 16:59:20 1999 +++ wmdctrl-0.4.0/source/wmdctrl.c Wed Mar 22 09:55:48 2000 @@ -25,6 +25,9 @@ #include #include +#ifndef NO_FLB_FIX +#include +#endif #include #include #include @@ -54,6 +57,26 @@ #include "wmdctrl-master.xpm" #include "wmdctrl-mask.xbm" +#ifndef NO_FLB_FIX +/* Get rid of zombies */ +void +sigchld_handler (int signum) +{ + int pid, status, serrno; + serrno = errno; + while (1) { + pid = waitpid (WAIT_ANY, &status, WNOHANG); + if (pid < 0) { + perror ("waitpid"); + break; + } + if (pid == 0) + break; + } + errno = serrno; +} +#endif + /************************************************************************/ /* main function */ /* */ @@ -64,20 +87,29 @@ /* o closes the fifo */ /************************************************************************/ +#ifndef NO_FLB_FIX +int using_tcp = 0; + +char launch_command[1024]; +char hostname[100]; +char port[10]; +char command_fifo_name[100]; +#endif int main(int argc, char *argv[]) { FILE *monitor_file; int command_fd; - char launch_command[1024]; - - char command_fifo_name[100]; - char filename[100]; - +#ifdef NO_FLB_FIX int using_tcp = 0; + + char launch_command[1024]; char hostname[100]; char port[10]; + char command_fifo_name[100]; +#endif + char filename[100]; /* variables for getopt */ char opt; @@ -157,6 +189,10 @@ AddMouseRegion(BUTTON_BLOCK, 38, 49, 48, 58); AddMouseRegion(BUTTON_LAUNCH,49, 49, 58, 58); +#ifndef NO_FLB_FIX + /* Setup signal handler */ + signal(SIGCHLD,sigchld_handler); +#endif /* The main loop */ dctrl_loop(command_fd, monitor_file, launch_command); @@ -251,6 +287,35 @@ return s; } +#ifndef NO_FLB_FIX +/* + Reconnects! +*/ +void reconnect(int* command_fd, FILE** monitor_file) +{ + char filename[100]; + + fclose(*monitor_file); + if (using_tcp) { + if ((*command_fd = open_socket(hostname, atoi(port))) == -1) { + exit(1); + } + if ((*monitor_file = fdopen(*command_fd, "r")) == NULL) { + perror("fdopen failed:"); + exit(-1); + } + send_command("monitor 0x0600017f wmdctrl\n", *command_fd); + } else { + if ((*command_fd = open(command_fifo_name, O_WRONLY|O_NONBLOCK)) == -1) { + perror("open failed:"); + exit(1); + } + sprintf(filename, "/tmp/wmdctrl.%d", getpid()); + *monitor_file = make_fifo(filename, *command_fd); + } +} +#endif + /************************************************************************ * FUNCTION : make_fifo() * AUTHOR : Tim Coleman @@ -266,6 +331,9 @@ FILE *make_fifo(char *filename, int command_fd) { int fp; +#ifndef NO_FLB_FIX + int flags; +#endif FILE *monitor_fd; char command[100]; @@ -278,9 +346,17 @@ /* Make the fifo */ mkfifo(filename, 0600); monitor_fd = fopen(filename, "r+"); +#ifndef NO_FLB_FIX + fcntl(fileno(monitor_fd),F_GETFL,&flags); + fcntl(fileno(monitor_fd),F_SETFL,flags|O_NONBLOCK); + setvbuf(monitor_fd,NULL,_IONBF,0); +#endif sprintf(command, "monitor 0x0600017f %s\n", filename); send_command(command, command_fd); +#if 0 /* ndef NO_FLB_FIX */ + unlink(filename); +#endif return monitor_fd; } @@ -413,6 +489,11 @@ DrawRXBar(rx_load5); DrawTXBar(tx_load5); } +#ifndef NO_FLB_FIX + else if (IS_MESSAGE(foo)) { + fgets(foo, LINE_WIDTH, monitor_file); + } +#endif RedrawWindowXY(xpm_X, xpm_Y); @@ -465,7 +546,11 @@ break; case BUTTON_LAUNCH: buttonChange(BUTTON_LAUNCH, DOWN); +#ifndef NO_FLB_FIX + if (fork() == 0) { +#else if (fork() > 0) { +#endif for (i = 0; i < strlen(launch_command); i++) { if (launch_command[i] == '\t') { launch_command[i] = ' '; @@ -493,6 +578,10 @@ } } break; +#ifndef NO_FLB_FIX + default: + reconnect(&command_fd,&monitor_file); +#endif } break; case ButtonRelease: @@ -511,7 +600,17 @@ return; } } +#ifdef NO_FLB_FIX usleep(150000); +#else + { + fd_set set; + FD_ZERO(&set); + FD_SET(ConnectionNumber(display),&set); + FD_SET(fileno(monitor_file),&set); + select(FD_SETSIZE,&set,NULL,NULL,NULL); + } +#endif fgets(foo, LINE_WIDTH, monitor_file); } }