]> sourceware.org Git - systemtap.git/commitdiff
2007-05-07 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Mon, 7 May 2007 20:08:32 +0000 (20:08 +0000)
committerhunt <hunt>
Mon, 7 May 2007 20:08:32 +0000 (20:08 +0000)
Patch from David Smith
* mainloop.c (stp_main_loop): Properly handle write()
return value. Fixes build problem with some compilers.

runtime/staprun/ChangeLog
runtime/staprun/Makefile
runtime/staprun/mainloop.c
runtime/staprun/relay.c

index db2140203549f04e93b8caf65bc09069b7e01c86..12bba523ccb2102557f562054a2773f8b80481f0 100644 (file)
@@ -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 
index b0329d3e66c1f913deb37675fc2cd55fa18fc958..097aead3e150ade90071ee992a0f4341a1ae4b83 100644 (file)
@@ -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
 
index 720f9ec5225bd0679445a90bd931d19abd4e758d..6a9b227dac757e57eea700bedcbfb67be2a8c214 100644 (file)
@@ -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);
index 5015cbefee2521e215f8eabf458fa85e00b0a1ea..82c5ccc46648eb17a22521e0f2278fc5137a4343 100644 (file)
@@ -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);
This page took 0.0386 seconds and 5 git commands to generate.