static void sock_finalise(RCL_Instance instance) { int sockfd; sockfd = (long)RCL_GetDriverData(instance); SCH_RemoveInputFileHandler(sockfd); close(sockfd); }
void RTC_Linux_Finalise(void) { if (timeout_running) { SCH_RemoveTimeout(timeout_id); timeout_running = 0; } /* Remove input file handler */ if (fd >= 0) { SCH_RemoveInputFileHandler(fd); close(fd); /* Save the RTC data */ (void) RTC_Linux_WriteParameters(); } }
void RTC_Linux_Finalise(void) { SCH_RemoveTimeout(timeout_id); timeout_id = 0; /* Remove input file handler */ if (fd >= 0) { SCH_RemoveInputFileHandler(fd); close(fd); /* Save the RTC data */ (void) RTC_Linux_WriteParameters(); } Free(rtc_sec); Free(rtc_trim); Free(system_times); }
static void read_from_device(void *any) { int status; unsigned long data; struct timeval sys_time; struct rtc_time rtc_raw; struct tm rtc_tm; time_t rtc_t; int error = 0; status = read(fd, &data, sizeof(data)); if (status < 0) { /* This looks like a bad error : the file descriptor was indicating it was * ready to read but we couldn't read anything. Give up. */ LOG(LOGS_ERR, LOGF_RtcLinux, "Could not read flags %s : %s", CNF_GetRtcDevice(), strerror(errno)); SCH_RemoveInputFileHandler(fd); switch_interrupts(0); /* Likely to raise error too, but just to be sure... */ close(fd); fd = -1; return; } if (skip_interrupts > 0) { /* Wait for the next interrupt, this one may be bogus */ skip_interrupts--; return; } if ((data & RTC_UF) == RTC_UF) { /* Update interrupt detected */ /* Read RTC time, sandwiched between two polls of the system clock so we can bound any error. */ SCH_GetLastEventTime(&sys_time, NULL, NULL); status = ioctl(fd, RTC_RD_TIME, &rtc_raw); if (status < 0) { LOG(LOGS_ERR, LOGF_RtcLinux, "Could not read time from %s : %s", CNF_GetRtcDevice(), strerror(errno)); error = 1; goto turn_off_interrupt; } /* Convert RTC time into a struct timeval */ rtc_tm.tm_sec = rtc_raw.tm_sec; rtc_tm.tm_min = rtc_raw.tm_min; rtc_tm.tm_hour = rtc_raw.tm_hour; rtc_tm.tm_mday = rtc_raw.tm_mday; rtc_tm.tm_mon = rtc_raw.tm_mon; rtc_tm.tm_year = rtc_raw.tm_year; rtc_t = t_from_rtc(&rtc_tm); if (rtc_t == (time_t)(-1)) { error = 1; goto turn_off_interrupt; } process_reading(rtc_t, &sys_time); if (n_samples < 4) { measurement_period = LOWEST_MEASUREMENT_PERIOD; } else if (n_samples < 6) { measurement_period = LOWEST_MEASUREMENT_PERIOD << 1; } else if (n_samples < 10) { measurement_period = LOWEST_MEASUREMENT_PERIOD << 2; } else if (n_samples < 14) { measurement_period = LOWEST_MEASUREMENT_PERIOD << 3; } else { measurement_period = LOWEST_MEASUREMENT_PERIOD << 4; } } turn_off_interrupt: switch (operating_mode) { case OM_INITIAL: if (error) { DEBUG_LOG(LOGF_RtcLinux, "Could not complete initial step due to errors"); operating_mode = OM_NORMAL; (after_init_hook)(after_init_hook_arg); switch_interrupts(0); timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL); } break; case OM_AFTERTRIM: if (error) { DEBUG_LOG(LOGF_RtcLinux, "Could not complete after trim relock due to errors"); operating_mode = OM_NORMAL; switch_interrupts(0); timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL); } break; case OM_NORMAL: switch_interrupts(0); timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL); break; default: assert(0); break; } }