# HG changeset patch # User Yoshiki Yazawa # Date 1239976355 -32400 # Node ID b03685d25fee135cfd7a9b8d7801da322c760ef2 # Parent 3228f5cde349d6456be5249f6a51094c590b7eae recpt1 now shows error explanation when write() fails. diff -r 3228f5cde349 -r b03685d25fee recpt1/recpt1.c --- a/recpt1/recpt1.c Thu Apr 16 22:18:58 2009 +0900 +++ b/recpt1/recpt1.c Fri Apr 17 22:52:35 2009 +0900 @@ -208,6 +208,7 @@ while(1) { ssize_t wc = 0; + int file_err = 0; qbuf = dequeue(p_queue); /* no entry in the queue */ if(qbuf == NULL) { @@ -235,10 +236,10 @@ int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK; wc = write(wfd, buf.data + offset, ws); if(wc < 0) { - if(errno == EPIPE) - pthread_kill(signal_thread, SIGPIPE); - else - pthread_kill(signal_thread, SIGUSR2); + perror("write"); + file_err = 1; + pthread_kill(signal_thread, + errno == EPIPE ? SIGPIPE : SIGUSR2); break; } size_remain -= wc; @@ -266,7 +267,7 @@ free(qbuf); /* normal exit */ - if((f_exit) && (!p_queue->num_used)) { + if(f_exit && !p_queue->num_used && !file_err) { buf = sbuf; /* default */ @@ -281,10 +282,10 @@ if(!fileless) { wc = write(wfd, buf.data, buf.size); if(wc < 0) { - if(errno == EPIPE) - pthread_kill(signal_thread, SIGPIPE); - else - pthread_kill(signal_thread, SIGUSR2); + perror("write"); + file_err = 1; + pthread_kill(signal_thread, + errno == EPIPE ? SIGPIPE : SIGUSR2); } } @@ -476,7 +477,7 @@ cleanup(sdata); break; case SIGUSR2: /* error */ - fprintf(stderr, "\nSomething is wrong. cleaning up...\n"); + fprintf(stderr, "Detected an error. cleaning up...\n"); cleanup(sdata); break; }