Skip to content

Commit

Permalink
fixed missing cleanup of the gnuchess daemon on windows.
Browse files Browse the repository at this point in the history
On the corner case, the parsing code is ugly and there is a crash
case that I tried to avoid.
  • Loading branch information
Bruno Coudoin committed Jan 31, 2010
1 parent b12d73b commit 293c5de
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/chess_computer-activity/chess.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,15 @@ static void pause_board (gboolean pause)

void gnuchess_died(int signum)
{
gnuchess_pid = 0;
gc_dialog(_("Error: The external program gnuchess died unexpectedly"), gc_board_stop);
gc_dialog(_("Error: The external program gnuchess died unexpectedly"),
gc_board_stop);
}

/*
*/
static void start_board (GcomprisBoard *agcomprisBoard)
{

gnuchess_pid = 0;
gchar **gnuchess_pathptr = gnuchess_path;
gchar *gnuchess_bin = NULL;

Expand Down Expand Up @@ -1058,9 +1057,6 @@ static void
engine_local_destroy (GPid gnuchess_pid)
{

if(!gnuchess_pid)
return;

g_warning("engine_local_destroy () \n");
write_child (write_chan, "quit\n");

Expand All @@ -1073,8 +1069,7 @@ engine_local_destroy (GPid gnuchess_pid)
g_io_channel_close (write_chan);
g_io_channel_unref (write_chan);

if(gnuchess_pid)
g_spawn_close_pid(gnuchess_pid);
g_spawn_close_pid(gnuchess_pid);
}

/** We got data back from gnuchess, we parse them here
Expand Down Expand Up @@ -1155,7 +1150,11 @@ engine_local_cb (GIOChannel *source,
/* parse for NUMBER ... MOVE */
if (isdigit (*buf))
{
if ((p = strstr (buf, "...")))
if ((p = strstr (buf, "...")) && (strlen(p) == 4) )
{
return TRUE;
}
else if ((p = strstr (buf, "...")))
{
Square from, to;

Expand Down Expand Up @@ -1234,8 +1233,8 @@ engine_local_err_cb (GIOChannel *source,
GIOCondition condition,
gpointer data)
{
gnuchess_pid = 0;
gc_dialog(_("Error: The external program gnuchess died unexpectingly"), gc_board_stop);
gc_dialog(_("Error: The external program gnuchess died unexpectingly"),
gc_board_stop);
return FALSE;
}

Expand Down Expand Up @@ -1270,7 +1269,7 @@ start_child (char *cmd,

}

g_warning("gnuchess subprocess is started");
g_warning("gnuchess subprocess is started (%d)", *Child_Process);

*read_chan = g_io_channel_unix_new (Child_Out);
*write_chan = g_io_channel_unix_new (Child_In);
Expand Down

0 comments on commit 293c5de

Please sign in to comment.