diff --git a/ChangeLog b/ChangeLog index 1acbae00f2..f6826bf348 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-06-17 Sven Neumann + + * plug-ins/script-fu/script-fu-server.c (read_from_client): merged + fix for bug #85573 from stable branch. We should port this stuff + to use GIOChannels. + 2002-06-17 Michael Natterer Separated tool_options creation from tool registration so we diff --git a/plug-ins/script-fu/script-fu-server.c b/plug-ins/script-fu/script-fu-server.c index 5aaf9181a7..c581bc956b 100644 --- a/plug-ins/script-fu/script-fu-server.c +++ b/plug-ins/script-fu/script-fu-server.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -431,17 +432,23 @@ read_from_client (gint filedes) gint nbytes; gint i; - for (i = 0; i < COMMAND_HEADER; i++) + for (i = 0; i < COMMAND_HEADER;) { - if ((nbytes = read (filedes, buffer + i, 1)) < 0) - { - /* Read error. */ - perror ("read"); - return 0; - } - else if (nbytes == 0) - /* End-of-file. */ - return -1; + nbytes = read (filedes, buffer + i, COMMAND_HEADER - i); + + if (nbytes < 0) + { + if (errno == EINTR) + continue; + + server_log ("Error reading command header.\n"); + return -1; + } + + if (nbytes == 0) + return -1; /* EOF */ + + i += nbytes; } if (buffer[MAGIC_BYTE] != MAGIC) @@ -453,13 +460,23 @@ read_from_client (gint filedes) command_len = (buffer [CMD_LEN_H_BYTE] << 8) | buffer [CMD_LEN_L_BYTE]; command = g_new (gchar, command_len + 1); - for (i = 0; i < command_len; i++) - if (read (filedes, command + i, 1) == 0) - { - server_log ("Error reading command. Read %d out of %d bytes.\n", - i, command_len); - return -1; - } + for (i = 0; i < command_len;) + { + nbytes = read (filedes, command + i, command_len - i); + + if (nbytes <= 0) + { + if (nbytes < 0 && errno == EINTR) + continue; + + server_log ("Error reading command. Read %d out of %d bytes.\n", + i, command_len); + g_free (command); + return -1; + } + + i += nbytes; + } command[command_len] = '\0'; cmd = g_new (SFCommand, 1);