summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--runtime/staprun/ChangeLog5
-rw-r--r--runtime/staprun/Makefile2
-rw-r--r--runtime/staprun/mainloop.c18
-rw-r--r--runtime/staprun/relay.c2
4 files changed, 22 insertions, 5 deletions
diff --git a/runtime/staprun/ChangeLog b/runtime/staprun/ChangeLog
index db214020..12bba523 100644
--- a/runtime/staprun/ChangeLog
+++ b/runtime/staprun/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/runtime/staprun/Makefile b/runtime/staprun/Makefile
index b0329d3e..097aead3 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 720f9ec5..6a9b227d 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 5015cbef..82c5ccc4 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);