#include "ustd.h"
#include "localerr.h"
#include "ustcomm.h"
+#include "share.h"
/* return value: 0 = subbuffer is finished, it won't produce data anymore
* 1 = got subbuffer successfully
/* Whether a request to end the program was received. */
sig_atomic_t terminate_req = 0;
-int test_sigpipe(void)
-{
- sigset_t sigset;
- int result;
-
- result = sigemptyset(&sigset);
- if(result == -1) {
- PERROR("sigemptyset");
- return -1;
- }
- result = sigaddset(&sigset, SIGPIPE);
- if(result == -1) {
- PERROR("sigaddset");
- return -1;
- }
-
- result = sigtimedwait(&sigset, NULL, &(struct timespec){0,0});
- if(result == -1 && errno == EAGAIN) {
- /* no signal received */
- return 0;
- }
- else if(result == -1) {
- PERROR("sigtimedwait");
- return -1;
- }
- else if(result == SIGPIPE) {
- /* received sigpipe */
- return 1;
- }
- else {
- assert(0);
- }
-}
-
int get_subbuffer(struct buffer_info *buf)
{
char *send_msg=NULL;
asprintf(&send_msg, "get_subbuffer %s", buf->name);
result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
- if(test_sigpipe()) {
- WARN("process %d destroyed before we could connect to it", buf->pid);
- retval = GET_SUBBUF_DONE;
+ if((result == -1 && errno == EPIPE) || result == 0) {
+ DBG("app died while being traced");
+ retval = GET_SUBBUF_DIED;
goto end;
}
else if(result < 0) {
retval = -1;
goto end;
}
- else if(result == 0) {
- DBG("app died while being traced");
- retval = GET_SUBBUF_DIED;
- goto end;
- }
result = sscanf(received_msg, "%as %ld", &rep_code, &buf->consumed_old);
if(result != 2 && result != 1) {
return retval;
}
-/* This write is patient because it restarts if it was incomplete.
- */
-
-ssize_t patient_write(int fd, const void *buf, size_t count)
-{
- const char *bufc = (const char *) buf;
- int result;
-
- for(;;) {
- result = write(fd, bufc, count);
- if(result <= 0) {
- return result;
- }
- count -= result;
- bufc += result;
-
- if(count == 0) {
- break;
- }
- }
-
- return bufc-(const char *)buf;
-}
-
void decrement_active_buffers(void *arg)
{
pthread_mutex_lock(&active_buffers_mutex);
}
/* put the subbuffer */
+ /* FIXME: we actually should unput the buffer before consuming... */
result = put_subbuffer(buf);
if(result == -1) {
ERR("unknown error putting subbuffer (channel=%s)", buf->name);
WARN("application died while putting subbuffer");
/* FIXME: probably need to skip the first subbuffer in finish_consuming_dead_subbuffer */
finish_consuming_dead_subbuffer(buf);
+ break;
}
else if(result == PUT_SUBBUF_OK) {
}