/******************************************************************************* ** ** Function select_read ** ** Description check if fd is ready for reading and listen for termination ** signal. need to use select in order to avoid collision ** between read and close on the same fd ** ** Returns -1: termination ** >=0: numbers of bytes read back from fd ** *******************************************************************************/ static int select_read(int fd, uint8_t *pbuf, int len) { fd_set input; int n = 0, ret = -1; char reason = 0; while (userial_running) { /* Initialize the input fd set */ FD_ZERO(&input); if (rx_flow_on == TRUE) { FD_SET(fd, &input); } int fd_max = create_signal_fds(&input); fd_max = fd_max > fd ? fd_max : fd; /* Do the select */ n = select(fd_max+1, &input, NULL, NULL, NULL); if(is_signaled(&input)) { reason = reset_signal(); if (reason == USERIAL_RX_EXIT) { USERIALDBG("RX termination"); return -1; } else if (reason == USERIAL_RX_FLOW_OFF) { USERIALDBG("RX flow OFF"); rx_flow_on = FALSE; } else if (reason == USERIAL_RX_FLOW_ON) { USERIALDBG("RX flow ON"); rx_flow_on = TRUE; } } if (n > 0) { /* We might have input */ if (FD_ISSET(fd, &input)) { ret = read(fd, pbuf, (size_t)len); if (0 == ret) ALOGW( "read() returned 0!" ); return ret; } } else if (n < 0) ALOGW( "select() Failed"); else if (n == 0) ALOGW( "Got a select() TIMEOUT"); } return ret; }
/* * We got the hangup signal. * Re-read the configuration files. */ static void sig_hup(int sig) { sig = sig; /* -Wunused */ reset_signal(SIGHUP, sig_hup); radius_signal_self(RADIUS_SIGNAL_SELF_HUP); }
static int pause_me(char *args) { // glctx_t *gcp = &glctx; pause(); reset_signal(); return CMD_SUCCESS; }
extern void activate_signal_handling (void) { /* Set handler if not set */ if (! sig_handled) { (void) signal(SIGINT, signal_handler); (void) signal(SIGTERM, signal_handler); (void) signal(SIGCHLD, signal_handler); (void) signal(SIGDUMMY, signal_handler); reset_signal(); sig_handled = TRUE; } }
/* Reset default unix behaviour */ extern int reset_default_signals (void) { int res; res = get_signal(); reset_signal(); if (sig_handled) { (void) signal(SIGINT, SIG_DFL); (void) signal(SIGTERM, SIG_DFL); (void) signal(SIGCHLD, SIG_DFL); (void) signal(SIGDUMMY, SIG_DFL); sig_handled = FALSE; } return res; }
/* * We got the hangup signal. * Re-read the configuration files. */ static void sig_hup(UNUSED int sig) { reset_signal(SIGHUP, sig_hup); radius_signal_self(RADIUS_SIGNAL_SELF_HUP); }
int segment_location(char *name, range_t * range) { glctx_t *gcp = &glctx; segment_t *segp; char *apage, *end; off_t offset; size_t length, maxlength; int pgid, i; bool need_nl; segp = segment_get(name); if (segp == NULL) { fprintf(stderr, "%s: no such segment: %s\n", gcp->program_name, name); return SEG_ERR; } if (segp->seg_start == MAP_FAILED) { fprintf(stderr, "%s: segment %s not mapped\n", gcp->program_name, name); return SEG_ERR; } offset = round_down_to_pagesize(range->offset); if (offset >= segp->seg_length) { fprintf(stderr, "%s: offset %ld is past end of segment %s\n", gcp->program_name, offset, name); return SEG_ERR; } apage = segp->seg_start + offset; maxlength = segp->seg_length - offset; length = range->length; if (length) length = round_up_to_pagesize(length); /* * note: we silently truncate to max length [end of segment] */ if (length == 0 || length > maxlength) length = maxlength; end = apage + length; pgid = offset / gcp->pagesize; show_one_segment(segp, false); /* show mapping, no header */ printf("page offset "); for (i = 0; i < PG_PER_LINE; ++i) printf(" +%02d", i); printf("\n"); if (pgid & PPL_MASK) { /* * start partial line */ int pgid2 = pgid & ~PPL_MASK; printf("%12x: ", pgid2); while (pgid2 < pgid) { printf(" "); ++pgid2; } need_nl = true; } else need_nl = false; for (; apage < end; apage += gcp->pagesize, ++pgid) { int node; node = get_node(apage); if (node < 0) { fprintf(stderr, "\n%s: " "failed to get node for segment %s, offset 0x%x\n", gcp->program_name, name, SEG_OFFSET(segp, apage)); return SEG_ERR; } if ((pgid & PPL_MASK) == 0) { if (need_nl) printf("\n"); printf("%12x: ", pgid); /* start a new line */ need_nl = true; } printf(" %3d", node); if (signalled(gcp)) { reset_signal(); break; } } printf("\n"); return SEG_OK; }
/******************************************************************************* ** ** Function userial_evt_read_thread ** ** Description The reading thread on EVT and ACL_IN channels ** ** Returns void * ** *******************************************************************************/ static void *userial_read_thread(void *arg) { fd_set input; int n; char reason = 0; USERIALDBG("Entering userial_read_thread()"); rx_flow_on = TRUE; userial_running = 1; raise_priority_a2dp(TASK_HIGH_USERIAL_READ); while (userial_running) { /* Initialize the input fd set */ FD_ZERO(&input); if (rx_flow_on == TRUE) { FD_SET(userial_cb.fd[CH_EVT], &input); FD_SET(userial_cb.fd[CH_ACL_IN], &input); } int fd_max = create_signal_fds(&input); fd_max = (fd_max>userial_cb.fd[CH_EVT]) ? fd_max : userial_cb.fd[CH_EVT]; fd_max = (fd_max>userial_cb.fd[CH_ACL_IN]) ? fd_max : userial_cb.fd[CH_ACL_IN]; /* Do the select */ n = 0; n = select(fd_max+1, &input, NULL, NULL, NULL); if(is_signaled(&input)) { reason = reset_signal(); if (reason == USERIAL_RX_EXIT) { ALOGI("exiting userial_read_thread"); userial_running = 0; break; } else if (reason == USERIAL_RX_FLOW_OFF) { USERIALDBG("RX flow OFF"); rx_flow_on = FALSE; } else if (reason == USERIAL_RX_FLOW_ON) { USERIALDBG("RX flow ON"); rx_flow_on = TRUE; } } if (n > 0) { /* We might have input */ if (FD_ISSET(userial_cb.fd[CH_EVT], &input)) { hci_mct_receive_evt_msg(); } if (FD_ISSET(userial_cb.fd[CH_ACL_IN], &input)) { hci_mct_receive_acl_msg(); } } else if (n < 0) ALOGW( "select() Failed"); else if (n == 0) ALOGW( "Got a select() TIMEOUT"); } /* while */ userial_running = 0; USERIALDBG("Leaving userial_evt_read_thread()"); pthread_exit(NULL); return NULL; // Compiler friendly }