-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;
- char *received_msg;
- char *rep_code;
- int retval;
- int result;
-
- asprintf(&send_msg, "get_subbuffer %s", buf->name);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
- free(send_msg);
- if(test_sigpipe()) {
- WARN("process %d destroyed before we could connect to it", buf->pid);
- return GET_SUBBUF_DONE;
- }
- else if(result < 0) {
- ERR("get_subbuffer: ustcomm_send_request failed");
- return -1;
- }
- else if(result == 0) {
- DBG("app died while being traced");
- return GET_SUBBUF_DIED;
- }
-
- result = sscanf(received_msg, "%as %ld", &rep_code, &buf->consumed_old);
- if(result != 2 && result != 1) {
- ERR("unable to parse response to get_subbuffer");
- return -1;
- }
-
- DBG("received msg is %s", received_msg);
-
- if(!strcmp(rep_code, "OK")) {
- DBG("got subbuffer %s", buf->name);
- retval = GET_SUBBUF_OK;
- }
- else if(nth_token_is(received_msg, "END", 0) == 1) {
- return GET_SUBBUF_DONE;
- }
- else {
- DBG("error getting subbuffer %s", buf->name);
- retval = -1;
- }