+2007-05-07 Martin Hunt <hunt@redhat.com>
+ Patch from David Smith
+ * mainloop.c (stp_main_loop): Properly handle write()
+ return value. Fixes build problem with some compilers.
+
2007-04-10 Martin Hunt <hunt@redhat.com>
* relay.c (close_relayfs): Give threads some time to
int stp_main_loop(void)
{
- int nb;
+ ssize_t nb;
void *data;
int type;
FILE *ofp = stdout;
nb = read(control_channel, recvbuf, sizeof(recvbuf));
if (nb <= 0) {
perror("recv");
- fprintf(stderr, "WARNING: unexpected EOF. nb=%d\n", nb);
+ fprintf(stderr, "WARNING: unexpected EOF. nb=%ld\n", (long)nb);
continue;
}
switch (type) {
#ifdef STP_OLD_TRANSPORT
case STP_REALTIME_DATA:
- write(out_fd[0], data, nb - sizeof(int));
+ {
+ ssize_t bw = write(out_fd[0], data, nb - sizeof(int));
+ if (bw >= 0 && bw != (nb - (ssize_t)sizeof(int))) {
+ nb = nb - bw;
+ bw = write(out_fd[0], data, nb - sizeof(int));
+ }
+ if (bw != (nb - (ssize_t)sizeof(int))) {
+ perror("write");
+ fprintf(stderr,
+ "ERROR: write error. nb=%ld\n", (long)nb);
+ cleanup_and_exit(0);
+ }
break;
+ }
#endif
case STP_OOB_DATA:
fputs ((char *)data, stderr);
if (rc > max_rd)
max_rd = rc;
- if (write(out_fd[cpu], buf, rc) < 0) {
+ if (write(out_fd[cpu], buf, rc) != rc) {
fprintf(stderr, "Couldn't write to output fd %d for cpu %d, exiting: errcode = %d: %s\n",
out_fd[cpu], cpu, errno, strerror(errno));
pthread_exit(NULL);