#include "header.h" extern pid_t pid_sop; extern int signal_pipe[2]; extern pid_t pid_channel; extern pid_t pid_player; extern GtkWidget *button_channel; extern GtkWidget *label_player; //----------------------------------------------------- ////handle signal child void pipe_signals(int signal) { if (write(signal_pipe[1], &signal, sizeof(int)) != sizeof(int)) { fprintf(stderr, "unix signal %d lost\n", signal); } } //----------------------------------------------------- void processSignal(int result, int status) { if (result == pid_sop) //if the value of pid_sop has been updated first, this condition won't be met. { pid_sop = -2; /////reset to default value /////////////display quit message // gtk_entry_set_text (GTK_ENTRY (entry_status), ""); } else if (result == pid_channel) { pid_channel = -2; /////reset to default value gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (button_channel), FALSE); } else if (result == pid_player) { GdkColor color; gdk_color_parse("black", &color); gtk_widget_modify_fg(label_player, GTK_STATE_NORMAL, &color); pid_player = -2; } } //----------------------------------------------------- gboolean handle_io_pipe(GIOChannel * source, GIOCondition cond, gpointer d) { GError *error = NULL; /* for error handling */ char buf[64]; GIOStatus status; /* save the reading status */ gsize bytes_read; /* save the number of chars read */ int waitstat; int waitresult; if ((status = g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, &error)) == G_IO_STATUS_NORMAL && bytes_read > 0) { ///////////// while (1) { if ((waitresult = waitpid(WAIT_ANY, &waitstat, WNOHANG | WUNTRACED)) <= 0) break; processSignal(waitresult, waitstat); } ///////////// } return (TRUE); /* keep the event source */ }