From ff3e10e0e01911305efebb3459189ca9321bd54d Mon Sep 17 00:00:00 2001 From: hunt Date: Mon, 7 May 2007 20:08:32 +0000 Subject: [PATCH] 2007-05-07 Martin Hunt Patch from David Smith * mainloop.c (stp_main_loop): Properly handle write() return value. Fixes build problem with some compilers. --- runtime/staprun/ChangeLog | 5 +++++ runtime/staprun/Makefile | 2 +- runtime/staprun/mainloop.c | 18 +++++++++++++++--- runtime/staprun/relay.c | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/runtime/staprun/ChangeLog b/runtime/staprun/ChangeLog index db2140203..12bba523c 100644 --- a/runtime/staprun/ChangeLog +++ b/runtime/staprun/ChangeLog @@ -1,3 +1,8 @@ +2007-05-07 Martin Hunt + 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 * relay.c (close_relayfs): Give threads some time to diff --git a/runtime/staprun/Makefile b/runtime/staprun/Makefile index b0329d3e6..097aead3e 100644 --- a/runtime/staprun/Makefile +++ b/runtime/staprun/Makefile @@ -1,4 +1,4 @@ -CFLAGS = -Wall -std=gnu99 -D_GNU_SOURCE -fexceptions -Wall -Werror -Wshadow -Wunused +CFLAGS = -Wall -std=gnu99 -D_GNU_SOURCE -fexceptions -Wall -Werror -Wshadow -Wunused -Wp,-D_FORTIFY_SOURCE=2 all: staprun stap_merge diff --git a/runtime/staprun/mainloop.c b/runtime/staprun/mainloop.c index 720f9ec52..6a9b227da 100644 --- a/runtime/staprun/mainloop.c +++ b/runtime/staprun/mainloop.c @@ -271,7 +271,7 @@ static char recvbuf[8192]; int stp_main_loop(void) { - int nb; + ssize_t nb; void *data; int type; FILE *ofp = stdout; @@ -290,7 +290,7 @@ int stp_main_loop(void) 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; } @@ -300,8 +300,20 @@ int stp_main_loop(void) 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); diff --git a/runtime/staprun/relay.c b/runtime/staprun/relay.c index 5015cbefe..82c5ccc46 100644 --- a/runtime/staprun/relay.c +++ b/runtime/staprun/relay.c @@ -64,7 +64,7 @@ static void *reader_thread(void *data) 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); -- 2.43.5