void ArcnetIO::recv ( uint8_t* msg ) { socklen_t saLength = sizeof(sa_); // Do some setup for select() timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = SELECT_TIMEOUT; fd_set socks; // Socket file descriptors we want to wake up for, using select() FD_ZERO(&socks); FD_SET(socket_,&socks); int readsocks = -1; TRY_STD_FUNC( (readsocks = select(socket_+1, &socks, NULL, NULL, &timeout)) ); if ( readsocks == 0 ) { // Not normally an error but indicates nothing ready to read. Throw an error? THROW_ERROR( "Nothing ready to read. But how?" ); } // If we get this far, we have a valid socket that is ready for reading. ualarm( ALARM_TIMEOUT, 0 ); // Start alarm timer if ( recvfrom(socket_, msg, Message::max_msg_length, 0, &sa_, &saLength) < 0 ) { if (errno == EINTR) { THROW_ERROR("PA-10 seems unresponsive. Is it turned on?"); } else { ualarm(0, 0); THROW_ERROR(strerror(errno)); } } else { // reset alarm ualarm(0, 0); } }
void segvhandler(int signum, siginfo_t *info, void *extra){ if( signum == SIGSEGV){ alarm(0); /* just in case */ ualarm(0, 0); ptr = (void *)(((int)info->si_addr) & myhandler.mask); if( myhandler.encrNumAddrs < myhandler.encr_size ){ myhandler.encrNumAddrs++; encrHandler[myhandler.encrNumAddrs].addrs = ptr; encrHandler[myhandler.encrNumAddrs].del = 1; encrHandler[myhandler.encrNumAddrs].decr = 1; } decr(encrHandler[myhandler.encrNumAddrs].addrs, pagesize); alarm(0); ualarm(0,0); ualarm(TIMERVAL, TIMERVAL); } return; }
/* * cfree() * Frees a pointer * * Precondition: freeptr: pointer to be freed * Postcondtion: freeptr is freed by calling * munmap() */ extern C_LINKAGE void free( void *freeptr ){ ualarm(0,0); alarm(0); /* Don't think this is needed... */ sigset_t newmask, oldmask; sigemptyset( &newmask ); sigaddset( &newmask, SIGALRM ); if ( sigprocmask( SIG_BLOCK, &newmask, &oldmask ) < 0 ) crash( "SIG_BLOCK error" ); lock(); if( freeptr ){ if( myhandler.totalNumAddrs == 0 ) crash("free before first malloc!"); int i, j; ptr = freeptr; ptr2 = freeptr; /* search for pointer in memory handler */ for( i = 0; i < myhandler.total_size; i++ ){ if( memSlots[i].addrs == freeptr ){ /* if found set delete to true and * erase page info from encryption handler */ memSlots[i].del = 1; zero(ptr); /* If the buffer is more than one page, * we have to erase each page from the * encryption handler */ for( j = 0; j < memSlots[i].size; j += pagesize ){ if( (ptr + pagesize) <= (ptr2 + memSlots[i].size) ){ ptr += pagesize; zero(ptr); } } /* Erase the page */ munmap(freeptr, memSlots[i].size); break; } } if( i == myhandler.total_size ) crash("address not from malloc!"); } unlock(); if( sigprocmask( SIG_SETMASK, &oldmask, NULL ) < 0 ) crash( "SIG_SETMASK error" ); ualarm(TIMERVAL, 0); return; }
void *POSIX_Init( void *argument ) { int status; useconds_t result; struct sigaction act; sigset_t mask; TEST_BEGIN(); /* set the time of day, and print our buffer in multiple ways */ set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); /* get id of this thread */ Init_id = pthread_self(); printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id ); Signal_occurred = 0; Signal_count = 0; /* Validate ualarm is ignored if signal not caught */ act.sa_handler = Signal_handler; act.sa_flags = 0; sigaction( SIGALRM, &act, NULL ); puts( "Init: ualarm in 1 us" ); sleep(3); result = ualarm(1,0); rtems_test_assert( result == 0 ); status = sleep(10); rtems_test_assert( status == 0 ); /* unblock Signal and see if it happened */ status = sigemptyset( &mask ); rtems_test_assert( !status ); status = sigaddset( &mask, SIGALRM ); rtems_test_assert( !status ); puts( "Init: Unblock SIGALRM" ); status = sigprocmask( SIG_UNBLOCK, &mask, NULL ); rtems_test_assert( !status ); status = sleep(10); /* stop ularm */ puts( "Init: clear ualarm with 0,0" ); result = ualarm(0,0); status = sleep(10); TEST_END(); rtems_test_exit(0); return NULL; /* just so the compiler thinks we returned something */ }
static int sun_discard_playing(void) { void (* orig_alarm_handler)(); orig_alarm_handler = signal(SIGALRM, null_proc); ualarm(10000, 10000); close_output(); ualarm(0, 0); signal(SIGALRM, orig_alarm_handler); return open_output(); }
/* * Test that masked signals with a default action of terminate process * do NOT terminate the process. */ int main (int argc, char *argv[]) { sigset_t mask; int sig; int r; /* any two (or more) command line args should cause the program to die */ if (argc > 2) { printf("trigger sigalrm[1] [test should die]\n"); ualarm(100000, 0); CHECKe(sleep(1)); } /* mask sigalrm */ CHECKe(sigemptyset(&mask)); CHECKe(sigaddset(&mask, SIGALRM)); CHECKr(pthread_sigmask(SIG_BLOCK, &mask, NULL)); /* make sure pthread_sigmask() returns the right value on failure */ r = pthread_sigmask(-1, &mask, NULL); ASSERTe(r, == EINVAL); /* now trigger sigalrm and wait for it */ printf("trigger sigalrm[2] [masked, test should not die]\n"); ualarm(100000, 0); CHECKe(sleep(1)); /* sigwait for sigalrm, it should be pending. If it is not the test will hang. */ CHECKr(sigwait(&mask, &sig)); ASSERT(sig == SIGALRM); /* make sure sigwait didn't muck with the mask by triggering sigalrm, again */ printf("trigger sigalrm[3] after sigwait [masked, test should not die]\n"); ualarm(100000, 0); CHECKe(sleep(1)); /* any single command line arg will run this code wich unmasks the signal and then makes sure the program terminates when sigalrm is triggered. */ if (argc > 1) { printf("trigger sigalrm[4] [unmasked, test should die]\n"); CHECKr(pthread_sigmask(SIG_UNBLOCK, &mask, NULL)); ualarm(100000, 0); CHECKe(sleep(1)); } SUCCEED; }
int main() { puts("-- 1 (should block) --"); struct sigaction newAction; newAction.sa_handler = (sighandler_t)sigHandler; newAction.sa_mask = 0; newAction.sa_flags = SA_ONESHOT | SA_ONSTACK | SA_RESTART; #if defined(__BEOS__) || defined(__ANTARES__) newAction.sa_userdata = (void*)kUserDataMagic; #endif sigaction(SIGALRM, &newAction, NULL); ualarm(10000, 0); wait_for_key(); puts("-- 2 (does not block, should call handler twice) --"); newAction.sa_flags = 0; sigaction(SIGALRM, &newAction, NULL); ualarm(0, 50000); wait_for_key(); wait_for_key(); ualarm(0, 0); puts("-- 3 (alternate stack, should block) --"); #if defined(__BEOS__) && !defined(__ANTARES__) set_signal_stack(sAlternateStack, SIGSTKSZ); #else stack_t newStack; newStack.ss_sp = sAlternateStack; newStack.ss_size = SIGSTKSZ; newStack.ss_flags = 0; if (sigaltstack(&newStack, NULL) != 0) fprintf(stderr, "sigaltstack() failed: %s\n", strerror(errno)); #endif newAction.sa_flags = SA_RESTART | SA_ONSTACK; sigaction(SIGALRM, &newAction, NULL); ualarm(10000, 0); wait_for_key(); puts("-- end --"); return 0; }
/* * Relinquishes control of the CPU to the first thread in the ready queue (if one exists) */ void t_yield() { ualarm(0,0); if(ready_0 || ready_1){ int pri = enq(running); deq(); if(pri == 0){ swapcontext(rear_0->thread_context, running->thread_context); }else swapcontext(rear_1->thread_context, running->thread_context); }else{ ualarm(1,0); } }
static void sig_alrm(int signo) { write(socket_fd, send_buffer, MAXLINE); fprintf(stdout, "[Sender] Resend %d %d.\n", count, send_buffer[SPP+1]); ualarm(usec, 0); return; }
static int Jim_AlarmCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { int ret; if (argc != 2) { Jim_WrongNumArgs(interp, 1, argv, "seconds"); return JIM_ERR; } else { #ifdef HAVE_UALARM double t; ret = Jim_GetDouble(interp, argv[1], &t); if (ret == JIM_OK) { if (t < 1) { ualarm(t * 1e6, 0); } else { alarm(t); } } #else long t; ret = Jim_GetLong(interp, argv[1], &t); if (ret == JIM_OK) { alarm(t); } #endif } return ret; }
void alarm_handler(int sig) { // prepare for next ualarm(10000, 0);//10 ms actor* pActor = NULL; while (!pRunQueue.empty()) { // get an actor front the actor queue pActor = pRunQueue.front(); pRunQueue.pop_front(); if (!pActor->finished()) break; } if (!pActor) { printf("Actor queue empty.\n"); return; } // do a "context switch" //if (pRunningActor) // pRunningActor->yeild(); if (pRunningActor) pRunQueue.push_back(pRunningActor); pRunningActor = pActor; pRunningActor->resume(); }
void init_hw(void){ signal(14, sighandler); ualarm( PROC_TIME, PROC_TIME ); }
void give_me_a_break(int signo) { char c = 't'; if (signo == SIGALRM) if (write(ctx->time_machine[1], &c, 1) < 0) ualarm(1000, 0); }
void set_up() /* * init structure and other stuff */ { void ball_move(int); the_ball.y_pos = Y_INIT; the_ball.x_pos = X_INIT; the_ball.y_ttg = the_ball.y_ttm = Y_TTM ; the_ball.x_ttg = the_ball.x_ttm = X_TTM ; the_ball.y_dir = 1 ; the_ball.x_dir = 1 ; the_ball.symbol = DFL_SYMBOL ; int delay = 10000; initscr(); noecho(); cbreak(); signal( SIGINT , SIG_IGN ); mvaddch( the_ball.y_pos, the_ball.x_pos, the_ball.symbol ); refresh(); signal( SIGALRM, ball_move ); ualarm(delay,delay); }
void uplink_alarm_init(unsigned long delta) { spawnflag = 0; pthread_mutex_init(&alarm_mutex, NULL); /* Set a function to handle the SIGALRM signal */ signal(SIGALRM, uplink_alarm_handle); /* Start a new alarm every delta microseconds */ ualarm(delta, delta); }
void sigalarm_reset() { #ifdef linux #define TIMEOUT (997*1000) #else #define TIMEOUT (2451*1000) #endif ualarm(TIMEOUT, TIMEOUT); got_sigalarm = 0; }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ int main (int ac, char *av[]) { char input[1024],*ptr; // mmcd로 connect한다. if (rmi_initial(ac,av) < 0) return -1; // login name과 password를 입력 받아 mmcd와 login 절차를 수행한다. rmi_login2mmcd (); // 주기적으로 interrupt에 의해 MMCD로부터의 수신 데이터를 확인한다. signal (SIGALRM, rmi_receiveResult); ualarm (50000, 0); while (1) { fprintf(stderr,"\n [%s] ", prompt); // log-out을 하지않고 alt-f4등으로 강제 종료로 인해 tty가 사라지면 blocking 되지 않고 무한루프로 빠짐. // ttyname(0) 추가 while (fgets(input, sizeof(input), stdin) == NULL) if(ttyname(0) == NULL) return 0; // 앞쪽 white-space를 지운다. ptr = input; for (; isspace(*ptr); ptr++); // 맨끝 \n을 지운다. input[strlen(input)-1] = 0; // 그냥 Enter를 입력한 경우 if (!strlen(ptr)) { //fprintf(stderr,"\n[%s] ", prompt); continue; } // 자신이 직접 처리해야 하는 command인 경우 if (rmi_isBuiltInCmd(ptr)) { //fprintf(stderr,"\n[%s] ", prompt); continue; } // mmcd로 명령어를 보낸다. // #if 0 /* jhnoh : 030815 */ rmi_send2mmcd(ptr, RMI_REQID_GENERAL_CMD, -1); #else rmi_send2mmcd(ptr, -1, 0); #endif fprintf(stderr,"\n [%s] ", prompt); } return 0; } //----- End of main -----//
/* Ensure not to exit(default action) when timer runs out. */ static void sig_alarm(int signo) { if(advertiseValid != 0) advertiseValid -= 200000; signal(SIGALRM, sig_alarm); ualarm(200000, 0); }
/* * Function : ssd_start_scan * Description : start spectral scan * Input params : pointer to ssd_info_t * Return : void * */ void ssd_start_scan(ssd_info_t *pinfo) { system("spectraltool priority 1"); system("spectraltool startscan"); if (!pinfo->config.classify) alarm(SSD_ALARAM_VAL); else ualarm(SSD_USEC_ALARM_VAL, 0); }
void test( void ) { useconds_t useconds; useconds_t interval; useconds_t result; useconds = 10; interval = 10; result = ualarm( useconds, interval ); }
void handle_alarm(int ignored) { //printf("enter alarm handler\n"); if(bindFlag == 0) return; if(preNum != newestNum) sendDataAck(sock, &clntAddr); preNum = newestNum; ualarm(RTT,0); return; }
/* * realloc() * * Precondition: size: size of buffer to allocate * newSize: new size of allocated buffer * Postcondition: pointer to reallocated buffer is * returned */ extern C_LINKAGE void *realloc(void *oldBuff, size_t newSize){ ualarm(0,0); alarm(0); /* I don't think this part is needed... */ sigset_t newmask, oldmask; sigemptyset( &newmask ); sigaddset( &newmask, SIGALRM ); if ( sigprocmask( SIG_BLOCK, &newmask, &oldmask ) < 0 ) crash( "SIG_BLOCK error" ); void *newBuff = malloc( newSize ); if (mprotect(newBuff, newSize, PROT_READ | PROT_WRITE) != 0) crash("mprotect REALLOC"); lock(); int i, size; if( oldBuff ){ /* Look for buffer address in memory handler * and get size */ for( i = 0; i < myhandler.total_size; i++ ){ if( oldBuff == memSlots[i].addrs ){ size = memSlots[i].size; break; } } if( i >= myhandler.total_size ) crash("address not from malloc!"); if( newSize < size ) size = newSize; if( size > 0 ) memcpy( newBuff, oldBuff, size ); free( oldBuff ); if( size < newSize ) memset(&(((char *)newBuff)[size]), 0, newSize - size); } unlock(); if( sigprocmask( SIG_SETMASK, &oldmask, NULL ) < 0 ) crash( "SIG_SETMASK error" ); return newBuff; }
void yeild() { // prepare for next sigset_t sigs, oldset; sigfillset(&sigs); sigprocmask(SIG_SETMASK, &sigs, &oldset); ualarm(10000, 0);//10 ms sigprocmask(SIG_SETMASK, &oldset, NULL); assert(swapcontext(&my_context_, &uctx_main) == 0); }
static void timer_trigger(evquick_timer *t, unsigned long long now, unsigned long long expire) { evquick_timer_instance tev, *first; tev.ev_timer = t; tev.expire = expire; heap_insert(ctx->timers, &tev); first = heap_first(ctx->timers); if (first) { unsigned long long interval; if (now >= first->expire) { ualarm(1000, 0); return; } interval = first->expire - now; if (interval >= 1000) alarm((unsigned)(interval / 1000)); else ualarm((useconds_t)(1000 * (first->expire - now)), 0); } }
/* Monitors an interface (or capture file) for WPS data in beacon packets or probe responses */ void monitor(char *bssid, int passive, int source, int channel, int mode) { struct sigaction act; struct itimerval timer; struct pcap_pkthdr header; static int header_printed; const u_char *packet = NULL; memset(&act, 0, sizeof(struct sigaction)); memset(&timer, 0, sizeof(struct itimerval)); /* If we aren't reading from a pcap file, set the interface channel */ if(source == INTERFACE) { /* * If a channel has been specified, set the interface to that channel. * Else, set a recurring 1 second timer that will call sigalrm() and switch to * a new channel. */ if(channel > 0) { change_channel(channel); } else { act.sa_handler = sigalrm_handler; sigaction (SIGALRM, &act, 0); ualarm(CHANNEL_INTERVAL, CHANNEL_INTERVAL); change_channel(1); } } if(!header_printed) { if (o_file_p == 0) { cprintf(INFO, "BSSID Channel RSSI WPS Version WPS Locked ESSID\n"); cprintf(INFO, "--------------------------------------------------------------------------------------\n"); header_printed = 1; } } while((packet = next_packet(&header))) { parse_wps_settings(packet, &header, bssid, passive, mode, source); #ifndef __APPLE__ memset((void *) packet, 0, header.len); #endif } return; }
static void spectral_alarm_handler(int sig) { //Fri Feb 5 16:44:47 PST 2010 - In classify mode, this will be used to send interspersed data for both channels if (!global_is_classify) { SPECTRAL_DPRINTF(ATH_DEBUG_SPECTRAL1,"%s curr_freq=%d\n",__func__, global_current_freq); } else { global_num_alarms++; SPECTRAL_DPRINTF(ATH_DEBUG_SPECTRAL1,"%s CLASSIFY scan curr_freq=%d\n",__func__, global_current_freq); SPECTRAL_DPRINTF(ATH_DEBUG_SPECTRAL1,"%s %d total_channel_switches=%d\n", __func__, __LINE__, total_channel_switches); ualarm(200000, 0); } }
void zprof_alarm_set(void) { int i; _SRCSAMPL_ZPROF = (int *) _zmalloc(_SRCSAMPL_NUM*sizeof(int), "zprof samples"); for (i=0; i<_SRCSAMPL_NUM; i++) _SRCSAMPL_ZPROF[i] = 0; _ZPROF_ALARM_TIMING = 10; signal(SIGALRM, zprof_alarm_handler); ualarm(_ZPROF_ALARM_TIMING, 0); }
int test( void ) { useconds_t useconds; useconds_t interval; useconds_t result; useconds = 10; interval = 10; result = ualarm( useconds, interval ); return (result == 0) ? 0 : -1; }
void main() { signal( SIGINT , hook ); signal( SIGALRM , ahook ); ualarm( 1000 * 100 ); for( ;; ){ sleep( 1 ); } }
smartgets(int *count, int fd) #endif { const char *result; data = fd; signal(SIGALRM, check_fd); ualarm(500000, 500000); result = setjmp(pppdead) ? NULL : #ifdef HAVE_LIBEDIT el_gets(e, count); #else readline(prompt); if (result != NULL) *count = strlen(result); #endif ualarm(0,0); signal(SIGALRM, SIG_DFL); data = -1; return result; }