/* * Converts a datetimestruct in UTC to a datetimestruct in local time, * also returning the timezone offset applied. * * Returns 0 on success, -1 on failure. */ static int convert_datetimestruct_utc_to_local(pandas_datetimestruct *out_dts_local, const pandas_datetimestruct *dts_utc, int *out_timezone_offset) { NPY_TIME_T rawtime = 0, localrawtime; struct tm tm_; npy_int64 year_correction = 0; /* Make a copy of the input 'dts' to modify */ *out_dts_local = *dts_utc; /* HACK: Use a year < 2038 for later years for small time_t */ if (sizeof(NPY_TIME_T) == 4 && out_dts_local->year >= 2038) { if (is_leapyear(out_dts_local->year)) { /* 2036 is a leap year */ year_correction = out_dts_local->year - 2036; out_dts_local->year -= year_correction; } else { /* 2037 is not a leap year */ year_correction = out_dts_local->year - 2037; out_dts_local->year -= year_correction; } } /* * Convert everything in 'dts' to a time_t, to minutes precision. * This is POSIX time, which skips leap-seconds, but because * we drop the seconds value from the pandas_datetimestruct, everything * is ok for this operation. */ rawtime = (time_t)get_datetimestruct_days(out_dts_local) * 24 * 60 * 60; rawtime += dts_utc->hour * 60 * 60; rawtime += dts_utc->min * 60; /* localtime converts a 'time_t' into a local 'struct tm' */ if (get_localtime(&rawtime, &tm_) < 0) { return -1; } /* Copy back all the values except seconds */ out_dts_local->min = tm_.tm_min; out_dts_local->hour = tm_.tm_hour; out_dts_local->day = tm_.tm_mday; out_dts_local->month = tm_.tm_mon + 1; out_dts_local->year = tm_.tm_year + 1900; /* Extract the timezone offset that was applied */ rawtime /= 60; localrawtime = (time_t)get_datetimestruct_days(out_dts_local) * 24 * 60; localrawtime += out_dts_local->hour * 60; localrawtime += out_dts_local->min; *out_timezone_offset = localrawtime - rawtime; /* Reapply the year 2038 year correction HACK */ out_dts_local->year += year_correction; return 0; }
//------------------------------------------------------------------- static void gui_read_draw_clock() { static struct tm *ttm; ttm = get_localtime(); sprintf(buffer, "%2u:%02u", ttm->tm_hour, ttm->tm_min); draw_string(camera_screen.disp_right-17*FONT_WIDTH, 0, buffer, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); }
//------------------------------------------------------------------- static void gui_read_draw_clock() { static struct tm *ttm; ttm = get_localtime(); sprintf(buffer, "%2u:%02u", ttm->tm_hour, ttm->tm_min); draw_txt_string((camera_screen.width-camera_screen.ts_button_border)/FONT_WIDTH-2-1-1-9-2-5, 0, buffer, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); }
/* * send a log for the session when we have enough info about it */ void tcp_sess_log(struct session *s) { char pn[INET6_ADDRSTRLEN + strlen(":65535")]; struct proxy *fe = s->fe; struct proxy *be = s->be; struct proxy *prx_log; int tolog, level, err; char *svid; struct tm tm; /* if we don't want to log normal traffic, return now */ err = (s->flags & (SN_ERR_MASK | SN_REDISP)) || (s->conn_retries != be->conn_retries); if (!err && (fe->options2 & PR_O2_NOLOGNORM)) return; if (s->cli_addr.ss_family == AF_INET) inet_ntop(AF_INET, (const void *)&((struct sockaddr_in *)&s->cli_addr)->sin_addr, pn, sizeof(pn)); else inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6 *)(&s->cli_addr))->sin6_addr, pn, sizeof(pn)); get_localtime(s->logs.tv_accept.tv_sec, &tm); if (fe->logfac1 < 0 && fe->logfac2 < 0) return; prx_log = fe; tolog = fe->to_log; svid = (tolog & LW_SVID) ? (s->srv != NULL) ? s->srv->id : "<NOSRV>" : "-"; level = LOG_INFO; if (err && (fe->options2 & PR_O2_LOGERRORS)) level = LOG_ERR; send_log(prx_log, level, "%s:%d [%02d/%s/%04d:%02d:%02d:%02d.%03d]" " %s %s/%s %ld/%ld/%s%ld %s%lld" " %c%c %d/%d/%d/%d/%s%u %ld/%ld\n", pn, (s->cli_addr.ss_family == AF_INET) ? ntohs(((struct sockaddr_in *)&s->cli_addr)->sin_port) : ntohs(((struct sockaddr_in6 *)&s->cli_addr)->sin6_port), tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)s->logs.tv_accept.tv_usec/1000, fe->id, be->id, svid, (s->logs.t_queue >= 0) ? s->logs.t_queue : -1, (s->logs.t_connect >= 0) ? s->logs.t_connect - s->logs.t_queue : -1, (tolog & LW_BYTES) ? "" : "+", s->logs.t_close, (tolog & LW_BYTES) ? "" : "+", s->logs.bytes_out, sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT], sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT], actconn, fe->feconn, be->beconn, s->srv ? s->srv->cur_sess : 0, (s->flags & SN_REDISP)?"+":"", (s->conn_retries>0)?(be->conn_retries - s->conn_retries):be->conn_retries, s->logs.srv_queue_size, s->logs.prx_queue_size); s->logs.logwait = 0; }
int pce_log (const char * volatile buf, ...) { char d_buffer_2[PCE_PSTR_MAX]; if (!(get_msg_type ((char*) buf) & STDLOG_LVL)) { return 0; } va_list al; va_start(al, buf); if (NULL != fd_log_pce) { struct tm tmd; struct tm *tm = get_localtime (&tmd); snprintf (d_buffer_2, PCE_PSTR_MAX, "[%.2u/%.2u/%.2u %.2u:%.2u:%.2u] [%d] %s", tm->tm_mday, tm->tm_mon + 1, (tm->tm_year + 1900) % 100, tm->tm_hour, tm->tm_min, tm->tm_sec, getpid (), buf); char wl_buffer[PCE_PSTR_MAX]; vsnprintf (wl_buffer, PCE_PSTR_MAX, d_buffer_2, al); w_log_p (wl_buffer); } va_end(al); return 0; }
//------------------------------------------------------------------- static void calendar_goto_today() { struct tm *ttm; ttm = get_localtime(); cal_year = 1900+ttm->tm_year; cal_month = ttm->tm_mon; }
void rtc_init(struct domain *d) { RTCState *s = domain_vrtc(d); spin_lock_init(&s->lock); init_timer(&s->update_timer, rtc_update_timer, s, smp_processor_id()); init_timer(&s->update_timer2, rtc_update_timer2, s, smp_processor_id()); init_timer(&s->alarm_timer, rtc_alarm_cb, s, smp_processor_id()); register_portio_handler(d, RTC_PORT(0), 2, handle_rtc_io); rtc_reset(d); spin_lock(&s->lock); s->hw.cmos_data[RTC_REG_A] = RTC_REF_CLCK_32KHZ | 6; /* ~1kHz */ s->hw.cmos_data[RTC_REG_B] = RTC_24H; s->hw.cmos_data[RTC_REG_C] = 0; s->hw.cmos_data[RTC_REG_D] = RTC_VRT; s->current_tm = gmtime(get_localtime(d)); s->start_time = NOW(); rtc_copy_date(s); check_update_timer(s); spin_unlock(&s->lock); }
/* Reload the hardware state from a saved domain */ static int rtc_load(struct domain *d, hvm_domain_context_t *h) { RTCState *s = domain_vrtc(d); if ( !has_vrtc(d) ) return -ENODEV; spin_lock(&s->lock); /* Restore the registers */ if ( hvm_load_entry(RTC, h, &s->hw) != 0 ) { spin_unlock(&s->lock); return -EINVAL; } /* Reset the wall-clock time. In normal running, this runs with host * time, so let's keep doing that. */ s->current_tm = gmtime(get_localtime(d)); rtc_copy_date(s); /* Reset the periodic interrupt timer based on the registers */ rtc_timer_update(s); check_update_timer(s); alarm_timer_update(s); spin_unlock(&s->lock); return 0; }
void rtc_update_clock(struct domain *d) { RTCState *s = domain_vrtc(d); spin_lock(&s->lock); s->current_tm = gmtime(get_localtime(d)); spin_unlock(&s->lock); }
/* flag any data within [lt_min,lt_max] */ size_t swarm_filter_lt(const double lt_min, const double lt_max, satdata_mag *data) { size_t i; size_t nlt = 0; solarpos_workspace *work_sp = solarpos_alloc(); for (i = 0; i < data->n; ++i) { time_t unix_time; /* ignore already flagged data to improve speed */ if (data->flags[i]) continue; unix_time = satdata_epoch2timet(data->t[i]); /* * at high latitudes, calculate solar zenith angle for a better * measure of darkness/sunlight than local time */ if (fabs(data->latitude[i]) > MAX_LATITUDE) { double lat = data->latitude[i] * M_PI / 180.0; double lon = wrappi(data->longitude[i] * M_PI / 180.0); double zenith; solarpos_calc_zenith(unix_time, lat, lon, &zenith, work_sp); zenith *= 180.0 / M_PI; assert(zenith >= 0.0); /* small zenith angle means sunlight so flag it */ if (zenith < MAX_ZENITH) { ++nlt; data->flags[i] |= SATDATA_FLG_LT; } } else { double lt = get_localtime(unix_time, data->longitude[i] * M_PI / 180.0); if (lt >= lt_min && lt <= lt_max) { ++nlt; data->flags[i] |= SATDATA_FLG_LT; } } } solarpos_free(work_sp); return nlt; }
static uint32_t rtc_ioport_read(RTCState *s, uint32_t addr) { int ret; struct domain *d = vrtc_domain(s); if ( (addr & 1) == 0 ) return 0xff; spin_lock(&s->lock); switch ( s->hw.cmos_index ) { case RTC_SECONDS: case RTC_MINUTES: case RTC_HOURS: case RTC_DAY_OF_WEEK: case RTC_DAY_OF_MONTH: case RTC_MONTH: case RTC_YEAR: /* if not in set mode, adjust cmos before reading*/ if (!(s->hw.cmos_data[RTC_REG_B] & RTC_SET)) { s->current_tm = gmtime(get_localtime(d)); rtc_copy_date(s); } ret = s->hw.cmos_data[s->hw.cmos_index]; break; case RTC_REG_A: ret = s->hw.cmos_data[s->hw.cmos_index]; if ((s->use_timer == 0) && update_in_progress(s)) ret |= RTC_UIP; break; case RTC_REG_C: check_for_pf_ticks(s); ret = s->hw.cmos_data[s->hw.cmos_index]; s->hw.cmos_data[RTC_REG_C] = 0x00; if ( ret & RTC_IRQF ) hvm_isa_irq_deassert(d, RTC_IRQ); check_update_timer(s); alarm_timer_update(s); s->pt_dead_ticks = 0; break; default: ret = s->hw.cmos_data[s->hw.cmos_index]; break; } spin_unlock(&s->lock); return ret; }
static void md_save_calls_history(){ char buf[200], fn[30]; char big[MD_INFO_BUF_SIZE]; int big_ln; int calls,i, ln, fd; static struct utimbuf t; static struct tm *ttm; if( (motion_detector.parameters & MD_MAKE_DEBUG_LOG_FILE) == 0 ){ return; } strcpy(fn,"A/MD_INFO.TXT");//,BUILD_NUMBER,motion_detector.pixels_step); fd = open(fn, O_WRONLY|O_CREAT, 0777); if( fd>=0) { console_add_line("Writing info file..."); lseek(fd,0,SEEK_END); ttm = get_localtime(); big_ln=sprintf(big, "\r\n--- %04u-%02u-%02u %02u:%02u:%02u\r\n" "CHDK Ver: %s [ #%s ]\r\nBuild Date: %s %s\r\nCamera: %s [ %s ]\r\n" "[%dx%d], threshold: %d, interval: %d, pixels step: %d\r\n" "region: [%d,%d-%d,%d], region type: %d\r\n" "wait interval: %d, parameters: %d, calls: %d, detected cells: %d\r\n", 1900+ttm->tm_year, ttm->tm_mon+1, ttm->tm_mday, ttm->tm_hour, ttm->tm_min, ttm->tm_sec, camera_info.chdk_ver, camera_info.build_number, camera_info.build_date, camera_info.build_time, camera_info.platform, camera_info.platformsub, motion_detector.columns, motion_detector.rows, motion_detector.threshold, motion_detector.measure_interval, motion_detector.pixels_step, motion_detector.clipping_region_column1, motion_detector.clipping_region_row1, motion_detector.clipping_region_column2, motion_detector.clipping_region_row2, motion_detector.clipping_region_mode, motion_detector.msecs_before_trigger, motion_detector.parameters, motion_detector.comp_calls_cnt, motion_detector.detected_cells ); calls = ( motion_detector.comp_calls_cnt < MD_REC_CALLS_CNT) ?motion_detector.comp_calls_cnt: MD_REC_CALLS_CNT; for(i=0;i<calls;i++){ ln=sprintf(buf,"[%d] - %d\r\n",i,motion_detector.comp_calls[i]); if(big_ln+ln>MD_INFO_BUF_SIZE){ write(fd,big,big_ln); big_ln=0; } memcpy(big+big_ln,buf,ln+1); big_ln+=ln; } write(fd,big,big_ln); close(fd); t.actime = t.modtime = time(NULL); utime(fn, &t); } }
//------------------------------------------------------------------- void gui_calendar_draw() { int x, y; static char str[32]; int w, d, i; static struct tm *ttm; if (need_redraw == 2) gui_calendar_initial_draw(); ttm = get_localtime(); sprintf(str, " %2u %s %04u %2u:%02u:%02u ", ttm->tm_mday, lang_str(months[ttm->tm_mon]), 1900+ttm->tm_year, ttm->tm_hour, ttm->tm_min, ttm->tm_sec); draw_string(camera_screen.disp_left+FONT_WIDTH*8, 0, str, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); if (need_redraw) { need_redraw = 0; i = strlen(lang_str(months[cal_month])); x = cal_x + (cal_w-FONT_WIDTH*2-FONT_WIDTH*4-FONT_WIDTH*2-i*FONT_WIDTH)/2; y = cal_y + 4; draw_rectangle(cal_x+FONT_WIDTH, y, cal_x+cal_w-FONT_WIDTH-FONT_WIDTH*4-FONT_WIDTH, y+FONT_HEIGHT, MAKE_COLOR(BG_COLOR(TITLE_COLOR), BG_COLOR(TITLE_COLOR)), RECT_BORDER0|DRAW_FILLED); draw_string(x+FONT_WIDTH, y, lang_str(months[cal_month]), TITLE_COLOR); sprintf(str, "%04d", cal_year); draw_string(cal_x+cal_w-FONT_WIDTH*2-FONT_WIDTH*4, y, str, TITLE_COLOR); d = calendar_days_in_month(cal_month+1, cal_year); w = calendar_day_of_week(1, cal_month+1, cal_year); y += FONT_HEIGHT+4+4; y += FONT_HEIGHT+4; for (x=0; x<w; ++x) { draw_string(cal_x+x*FONT_WIDTH*4, y, " ", (x<5)?CALENDAR_COLOR:WEEKEND_COLOR); } for (i=1; i<=d; ++i) { sprintf(str, " %2d ", i); draw_string(cal_x+x*FONT_WIDTH*4, y, str, (x<5)?CALENDAR_COLOR:WEEKEND_COLOR); if (++x>6) { x=0; y += FONT_HEIGHT+4; } } for (; y<cal_y+cal_h; y += FONT_HEIGHT+4, x=0) { for (; x<7; ++x) { draw_string(cal_x+x*FONT_WIDTH*4, y, " ", (x<5)?CALENDAR_COLOR:WEEKEND_COLOR); } } } }
void gui_osd_draw_clock(int x, int y, twoColors cl, int is_osd_edit) { if (conf.show_clock || is_osd_edit) { static char *ampm[2][3] = { { " AM", "A", " "}, { " PM", "P", "." } }; struct tm *ttm = get_localtime(); int w = 0; // Extra width from AM/PM indicator and seconds (if displayed) if ((FG_COLOR(cl) == 0) && (BG_COLOR(cl) == 0)) cl = user_color(conf.osd_color); if ((camera_info.state.is_shutter_half_press == 0) || (conf.clock_halfpress == 0) || is_osd_edit) { unsigned int hour = (ttm->tm_hour); char *ampm_ind = ""; // AM / PM indicator if (conf.clock_format == CLOCK_FORMAT_12) { ampm_ind = ampm[hour/12][conf.clock_indicator]; //(hour >= 12) ? pm : am; w = strlen(ampm_ind); if (hour == 0) hour = 12; else if (hour > 12) hour = hour - 12; } if ((conf.show_clock != CLOCK_WITHOUT_SEC) || is_osd_edit) { sprintf(osd_buf, "%2u:%02u:%02u%s", hour, ttm->tm_min, ttm->tm_sec, ampm_ind); w += 3; } else { sprintf(osd_buf, "%2u:%02u%s", hour, ttm->tm_min, ampm_ind); } if (x) // for gui_4wins.c draw_string(x, y, osd_buf, cl); else draw_osd_string(conf.clock_pos, 0, 0, osd_buf, cl, conf.clock_scale); } else if (camera_info.state.is_shutter_half_press && (conf.clock_halfpress == 1)) { sprintf(osd_buf, "%02u", ttm->tm_sec); if (conf.clock_pos.x >= 4*FONT_WIDTH) w = 3; draw_osd_string(conf.clock_pos, w*FONT_WIDTH, 0, osd_buf, cl, conf.clock_scale); } } }
/* * Displays the message on stderr with the date and pid. */ void Warning(const char *fmt, ...) { va_list argp; struct tm tm; if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) { va_start(argp, fmt); get_localtime(date.tv_sec, &tm); fprintf(stderr, "[WARNING] %03d/%02d%02d%02d (%d) : ", tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid()); vfprintf(stderr, fmt, argp); fflush(stderr); va_end(argp); } }
/* *************************************************************************** * Get date and time and take into account <ENV_TIME_DEFTM> variable. * * IN: * @d_off Day offset (number of days to go back in the past). * * OUT: * @rectime Current date and time. * * RETURNS: * Value of time in seconds since the Epoch. *************************************************************************** */ time_t get_time(struct tm *rectime, int d_off) { static int utc = 0; char *e; if (!utc) { /* Read environment variable value once */ if ((e = getenv(ENV_TIME_DEFTM)) != NULL) { utc = !strcmp(e, K_UTC); } utc++; } if (utc == 2) return get_gmtime(rectime, d_off); else return get_localtime(rectime, d_off); }
static void schedule_timestamp(server_conf_t *conf) { /* Schedules a timer for writing timestamps to the console logfiles. */ time_t t; struct tm tm; struct timeval tv; int numCompleted; assert(conf->tStampMinutes > 0); t = conf->tStampNext; get_localtime(&t, &tm); /* * If this is the first scheduled timestamp, compute the expiration time * assuming timestamps have been scheduled regularly since midnight. * Otherwise, base it off of the previous timestamp. */ if (!conf->tStampNext) { numCompleted = ((tm.tm_hour * 60) + tm.tm_min) / conf->tStampMinutes; tm.tm_min = (numCompleted + 1) * conf->tStampMinutes; tm.tm_hour = 0; } else { tm.tm_min += conf->tStampMinutes; } tm.tm_sec = 0; if ((t = mktime(&tm)) == ((time_t) -1)) { log_err(errno, "Unable to determine time of next logfile timestamp"); } tv.tv_sec = t; tv.tv_usec = 0; conf->tStampNext = t; /* The timer id is not saved because this timer will never be canceled. */ if (tpoll_timeout_absolute (tp_global, (callback_f) timestamp_logfiles, conf, &tv) < 0) { log_err(0, "Unable to create timer for timestamping logfiles"); } return; }
size_t track_flag_lt(const double lt_min, const double lt_max, size_t *ndata_flagged, satdata_mag *data, track_workspace *w) { size_t i; size_t nflagged = 0; /* number of points flagged */ size_t ntrack_flagged = 0; /* number of entire tracks flagged for UT */ double a, b; if (data->n == 0) return 0; b = fmod(lt_max - lt_min, 24.0); if (b < 0.0) b += 24.0; for (i = 0; i < w->n; ++i) { track_data *tptr = &(w->tracks[i]); time_t t = satdata_epoch2timet(tptr->t_eq); double lt = get_localtime(t, tptr->lon_eq * M_PI / 180.0); a = fmod(lt - lt_min, 24.0); if (a < 0.0) a += 24.0; if (a > b) { nflagged += track_flag_track(i, TRACK_FLG_LT, data, w); ++ntrack_flagged; } } fprintf(stderr, "track_flag_lt: flagged %zu/%zu (%.1f%%) tracks due to LT\n", ntrack_flagged, w->n, (double) ntrack_flagged / (double) w->n * 100.0); if (ndata_flagged) *ndata_flagged = nflagged; return ntrack_flagged; } /* track_flag_lt() */
/* *************************************************************************** * Main loop: Read stats from the relevant sources and display them. * * IN: * @count Number of lines of stats to print. * @rectime Current date and time. *************************************************************************** */ void rw_io_stat_loop(long int count, struct tm *rectime) { int curr = 1; /* Don't buffer data if redirected to a pipe */ setbuf(stdout, NULL); do { if (cpu_nr > 1) { /* * Read system uptime (only for SMP machines). * Init uptime0. So if /proc/uptime cannot fill it, * this will be done by /proc/stat. */ uptime0[curr] = 0; read_uptime(&(uptime0[curr])); } /* Read CIFS stats */ read_cifs_stat(curr); /* Get time */ get_localtime(rectime); /* Print results */ write_stats(curr, rectime); if (count > 0) { count--; } if (count) { curr ^= 1; pause(); } } while (count); }
void shut_down(int sig) { // Close up shop printf("\n"); printf("Closing files and freeing memory..."); // Only show this if timestamps are enabled if (config.showtime && (outfile != NULL)) fprintf(outfile,"[%s] Scan ended.\n", get_localtime()); // Don't try to close a file that doesn't exist, kernel gets mad if (outfile != NULL) fclose(outfile); // UDP cleanup if (config.udponly) { // Send message if configured if (config.hangup) send_udp_msg("Disconnect\n"); // Close socket close(config.udp_socket); } // Always close these free(results); close(config.bt_socket); // Delete PID file unlink(PID_FILE); printf("Done!\n"); // Log shutdown to syslog syslog(LOG_INFO, "Shutdown OK."); exit(sig); }
/* prepare the trash with a log prefix for session <sess>. It only works with * embryonic sessions based on a real connection. This function requires that * at sess->origin points to the incoming connection. */ static void session_prepare_log_prefix(struct session *sess) { struct tm tm; char pn[INET6_ADDRSTRLEN]; int ret; char *end; struct connection *cli_conn = __objt_conn(sess->origin); ret = addr_to_str(&cli_conn->addr.from, pn, sizeof(pn)); if (ret <= 0) chunk_printf(&trash, "unknown ["); else if (ret == AF_UNIX) chunk_printf(&trash, "%s:%d [", pn, sess->listener->luid); else chunk_printf(&trash, "%s:%d [", pn, get_host_port(&cli_conn->addr.from)); get_localtime(sess->accept_date.tv_sec, &tm); end = date2str_log(trash.str + trash.len, &tm, &(sess->accept_date), trash.size - trash.len); trash.len = end - trash.str; if (sess->listener->name) chunk_appendf(&trash, "] %s/%s", sess->fe->id, sess->listener->name); else chunk_appendf(&trash, "] %s/%d", sess->fe->id, sess->listener->luid); }
/* *************************************************************************** * Main entry to the iostat program. *************************************************************************** */ int main(int argc, char **argv) { int it = 0; int opt = 1; int i, report_set = FALSE; long count = 1; struct utsname header; struct io_dlist *st_dev_list_i; struct tm rectime; char *t, *persist_devname, *devname; #ifdef USE_NLS /* Init National Language Support */ init_nls(); #endif /* Get HZ */ get_HZ(); /* Allocate structures for device list */ if (argc > 1) { salloc_dev_list(argc - 1 + count_csvalues(argc, argv)); } /* Process args... */ while (opt < argc) { /* -p option used individually. See below for grouped use */ if (!strcmp(argv[opt], "-p")) { flags |= I_D_PARTITIONS; if (argv[++opt] && (strspn(argv[opt], DIGITS) != strlen(argv[opt])) && (strncmp(argv[opt], "-", 1))) { flags |= I_D_UNFILTERED; for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) { if (!strcmp(t, K_ALL)) { flags |= I_D_PART_ALL; } else { devname = device_name(t); if (DISPLAY_PERSIST_NAME_I(flags)) { /* Get device persistent name */ persist_devname = get_pretty_name_from_persistent(devname); if (persist_devname != NULL) { devname = persist_devname; } } /* Store device name */ i = update_dev_list(&dlist_idx, devname); st_dev_list_i = st_dev_list + i; st_dev_list_i->disp_part = TRUE; } } opt++; } else { flags |= I_D_PART_ALL; } } else if (!strcmp(argv[opt], "-g")) { /* * Option -g: Stats for a group of devices. * group_name contains the last group name entered on * the command line. If we define an additional one, save * the previous one in the list. We do that this way because we * want the group name to appear in the list _after_ all * the devices included in that group. The last group name * will be saved in the list later, in presave_device_list() function. */ if (group_nr > 0) { update_dev_list(&dlist_idx, group_name); } if (argv[++opt]) { /* * MAX_NAME_LEN - 2: one char for the heading space, * and one for the trailing '\0'. */ snprintf(group_name, MAX_NAME_LEN, " %-.*s", MAX_NAME_LEN - 2, argv[opt++]); } else { usage(argv[0]); } group_nr++; } else if (!strcmp(argv[opt], "-j")) { if (argv[++opt]) { if (strnlen(argv[opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1) { usage(argv[0]); } strncpy(persistent_name_type, argv[opt], MAX_FILE_LEN - 1); persistent_name_type[MAX_FILE_LEN - 1] = '\0'; strtolower(persistent_name_type); /* Check that this is a valid type of persistent device name */ if (!get_persistent_type_dir(persistent_name_type)) { fprintf(stderr, _("Invalid type of persistent device name\n")); exit(1); } /* * Persistent names are usually long: Display * them as human readable by default. */ flags |= I_D_PERSIST_NAME + I_D_HUMAN_READ; opt++; } else { usage(argv[0]); } } #ifdef DEBUG else if (!strcmp(argv[opt], "--debuginfo")) { flags |= I_D_DEBUG; opt++; } #endif else if (!strncmp(argv[opt], "-", 1)) { for (i = 1; *(argv[opt] + i); i++) { switch (*(argv[opt] + i)) { case 'c': /* Display cpu usage */ flags |= I_D_CPU; report_set = TRUE; break; case 'd': /* Display disk utilization */ flags |= I_D_DISK; report_set = TRUE; break; case 'h': /* * Display device utilization report * in a human readable format. */ flags |= I_D_HUMAN_READ; break; case 'k': if (DISPLAY_MEGABYTES(flags)) { usage(argv[0]); } /* Display stats in kB/s */ flags |= I_D_KILOBYTES; break; case 'm': if (DISPLAY_KILOBYTES(flags)) { usage(argv[0]); } /* Display stats in MB/s */ flags |= I_D_MEGABYTES; break; case 'N': /* Display device mapper logical name */ flags |= I_D_DEVMAP_NAME; break; case 'p': /* If option -p is grouped then it cannot take an arg */ flags |= I_D_PARTITIONS + I_D_PART_ALL; break; case 'T': /* Display stats only for the groups */ flags |= I_D_GROUP_TOTAL_ONLY; break; case 't': /* Display timestamp */ flags |= I_D_TIMESTAMP; break; case 'x': /* Display extended stats */ flags |= I_D_EXTENDED; break; case 'y': /* Don't display stats since system restart */ flags |= I_D_OMIT_SINCE_BOOT; break; case 'z': /* Omit output for devices with no activity */ flags |= I_D_ZERO_OMIT; break; case 'V': /* Print version number and exit */ print_version(); break; default: usage(argv[0]); } } opt++; } else if (!isdigit(argv[opt][0])) { /* * By default iostat doesn't display unused devices. * If some devices are explictly entered on the command line * then don't apply this rule any more. */ flags |= I_D_UNFILTERED; if (strcmp(argv[opt], K_ALL)) { /* Store device name entered on the command line */ devname = device_name(argv[opt++]); if (DISPLAY_PERSIST_NAME_I(flags)) { persist_devname = get_pretty_name_from_persistent(devname); if (persist_devname != NULL) { devname = persist_devname; } } update_dev_list(&dlist_idx, devname); } else { opt++; } } else if (!it) { interval = atol(argv[opt++]); if (interval < 0) { usage(argv[0]); } count = -1; it = 1; } else if (it > 0) { count = atol(argv[opt++]); if ((count < 1) || !interval) { usage(argv[0]); } it = -1; } else { usage(argv[0]); } } if (!interval) { count = 1; } /* Default: Display CPU and DISK reports */ if (!report_set) { flags |= I_D_CPU + I_D_DISK; } /* * Also display DISK reports if options -p, -x or a device has been entered * on the command line. */ if (DISPLAY_PARTITIONS(flags) || DISPLAY_EXTENDED(flags) || DISPLAY_UNFILTERED(flags)) { flags |= I_D_DISK; } /* Option -T can only be used with option -g */ if (DISPLAY_GROUP_TOTAL_ONLY(flags) && !group_nr) { usage(argv[0]); } /* Select disk output unit (kB/s or blocks/s) */ set_disk_output_unit(); /* Ignore device list if '-p ALL' entered on the command line */ if (DISPLAY_PART_ALL(flags)) { dlist_idx = 0; } if (DISPLAY_DEVMAP_NAME(flags)) { dm_major = get_devmap_major(); } /* Init structures according to machine architecture */ io_sys_init(); if (group_nr > 0) { /* * If groups of devices have been defined * then save devices and groups in the list. */ presave_device_list(); } get_localtime(&rectime, 0); /* Get system name, release number and hostname */ uname(&header); if (print_gal_header(&rectime, header.sysname, header.release, header.nodename, header.machine, cpu_nr)) { flags |= I_D_ISO; } printf("\n"); /* Set a handler for SIGALRM */ memset(&alrm_act, 0, sizeof(alrm_act)); alrm_act.sa_handler = alarm_handler; sigaction(SIGALRM, &alrm_act, NULL); alarm(interval); /* Main loop */ rw_io_stat_loop(count, &rectime); /* Free structures */ io_sys_free(); sfree_dev_list(); return 0; }
/* *************************************************************************** * Main loop: Read I/O stats from the relevant sources and display them. * * IN: * @count Number of lines of stats to print. * @rectime Current date and time. *************************************************************************** */ void rw_io_stat_loop(long int count, struct tm *rectime) { int curr = 1; int skip = 0; /* Should we skip first report? */ if (DISPLAY_OMIT_SINCE_BOOT(flags) && interval > 0) { skip = 1; } /* Don't buffer data if redirected to a pipe */ setbuf(stdout, NULL); do { if (cpu_nr > 1) { /* * Read system uptime (only for SMP machines). * Init uptime0. So if /proc/uptime cannot fill it, * this will be done by /proc/stat. */ uptime0[curr] = 0; read_uptime(&(uptime0[curr])); } /* * Read stats for CPU "all" and 0. * Note that stats for CPU 0 are not used per se. It only makes * read_stat_cpu() fill uptime0. */ read_stat_cpu(st_cpu[curr], 2, &(uptime[curr]), &(uptime0[curr])); if (dlist_idx) { /* * A device or partition name was explicitly entered * on the command line, with or without -p option * (but not -p ALL). */ if (HAS_DISKSTATS(flags) && !DISPLAY_PARTITIONS(flags)) { read_diskstats_stat(curr); } else if (HAS_SYSFS(flags)) { read_sysfs_dlist_stat(curr); } } else { /* * No devices nor partitions entered on the command line * (for example if -p ALL was used). */ if (HAS_DISKSTATS(flags)) { read_diskstats_stat(curr); } else if (HAS_SYSFS(flags)) { read_sysfs_stat(curr); } } /* Compute device groups stats */ if (group_nr > 0) { compute_device_groups_stats(curr); } /* Get time */ get_localtime(rectime, 0); /* Check whether we should skip first report */ if (!skip) { /* Print results */ write_stats(curr, rectime); if (count > 0) { count--; } } else { skip = 0; } if (count) { curr ^= 1; pause(); } } while (count); }
/* * This function sends a syslog message to both log servers of a proxy, * or to global log servers if the proxy is NULL. * It also tries not to waste too much time computing the message header. * It doesn't care about errors nor does it report them. */ void send_log(struct proxy *p, int level, const char *message, ...) { static int logfdunix = -1; /* syslog to AF_UNIX socket */ static int logfdinet = -1; /* syslog to AF_INET socket */ static long tvsec = -1; /* to force the string to be initialized */ va_list argp; static char logmsg[MAX_SYSLOG_LEN]; static char *dataptr = NULL; int fac_level; int hdr_len, data_len; struct logsrv *logsrvs[2]; int facilities[2], loglevel[2], minlvl[2]; int nblogger; int nbloggers = 0; char *log_ptr; if (level < 0 || progname == NULL || message == NULL) return; if (unlikely(date.tv_sec != tvsec || dataptr == NULL)) { /* this string is rebuild only once a second */ struct tm tm; tvsec = date.tv_sec; get_localtime(tvsec, &tm); hdr_len = snprintf(logmsg, sizeof(logmsg), "<<<<>%s %2d %02d:%02d:%02d %s[%d]: ", monthname[tm.tm_mon], tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, progname, pid); /* WARNING: depending upon implementations, snprintf may return * either -1 or the number of bytes that would be needed to store * the total message. In both cases, we must adjust it. */ if (hdr_len < 0 || hdr_len > sizeof(logmsg)) hdr_len = sizeof(logmsg); dataptr = logmsg + hdr_len; } va_start(argp, message); /* * FIXME: we take a huge performance hit here. We might have to replace * vsnprintf() for a hard-coded log writer. */ data_len = vsnprintf(dataptr, logmsg + sizeof(logmsg) - dataptr, message, argp); if (data_len < 0 || data_len > (logmsg + sizeof(logmsg) - dataptr)) data_len = logmsg + sizeof(logmsg) - dataptr; va_end(argp); dataptr[data_len - 1] = '\n'; /* force a break on ultra-long lines */ if (p == NULL) { if (global.logfac1 >= 0) { logsrvs[nbloggers] = &global.logsrv1; facilities[nbloggers] = global.logfac1; loglevel[nbloggers] = global.loglev1; minlvl[nbloggers] = global.minlvl1; nbloggers++; } if (global.logfac2 >= 0) { logsrvs[nbloggers] = &global.logsrv2; facilities[nbloggers] = global.logfac2; loglevel[nbloggers] = global.loglev2; minlvl[nbloggers] = global.minlvl2; nbloggers++; } } else { if (p->logfac1 >= 0) { logsrvs[nbloggers] = &p->logsrv1; facilities[nbloggers] = p->logfac1; loglevel[nbloggers] = p->loglev1; minlvl[nbloggers] = p->minlvl1; nbloggers++; } if (p->logfac2 >= 0) { logsrvs[nbloggers] = &p->logsrv2; facilities[nbloggers] = p->logfac2; loglevel[nbloggers] = p->loglev2; minlvl[nbloggers] = p->minlvl2; nbloggers++; } } /* Lazily set up syslog sockets for protocol families of configured * syslog servers. */ for (nblogger = 0; nblogger < nbloggers; nblogger++) { const struct logsrv *logsrv = logsrvs[nblogger]; int proto, *plogfd; if (logsrv->u.addr.sa_family == AF_UNIX) { proto = 0; plogfd = &logfdunix; } else { /* sa_family == AF_INET */ proto = IPPROTO_UDP; plogfd = &logfdinet; } if (*plogfd >= 0) { /* socket already created. */ continue; } if ((*plogfd = socket(logsrv->u.addr.sa_family, SOCK_DGRAM, proto)) < 0) { Alert("socket for logger #%d failed: %s (errno=%d)\n", nblogger + 1, strerror(errno), errno); return; } /* we don't want to receive anything on this socket */ setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero)); /* does nothing under Linux, maybe needed for others */ shutdown(*plogfd, SHUT_RD); } /* Send log messages to syslog server. */ for (nblogger = 0; nblogger < nbloggers; nblogger++) { const struct logsrv *logsrv = logsrvs[nblogger]; int *plogfd = logsrv->u.addr.sa_family == AF_UNIX ? &logfdunix : &logfdinet; int sent; /* we can filter the level of the messages that are sent to each logger */ if (level > loglevel[nblogger]) continue; /* For each target, we may have a different facility. * We can also have a different log level for each message. * This induces variations in the message header length. * Since we don't want to recompute it each time, nor copy it every * time, we only change the facility in the pre-computed header, * and we change the pointer to the header accordingly. */ fac_level = (facilities[nblogger] << 3) + MAX(level, minlvl[nblogger]); log_ptr = logmsg + 3; /* last digit of the log level */ do { *log_ptr = '0' + fac_level % 10; fac_level /= 10; log_ptr--; } while (fac_level && log_ptr > logmsg); *log_ptr = '<'; /* the total syslog message now starts at logptr, for dataptr+data_len-logptr */ sent = sendto(*plogfd, log_ptr, dataptr + data_len - log_ptr, MSG_DONTWAIT | MSG_NOSIGNAL, &logsrv->u.addr, logsrv_addrlen(logsrv)); if (sent < 0) { Alert("sendto logger #%d failed: %s (errno=%d)\n", nblogger, strerror(errno), errno); } } }
static int rtc_ioport_write(void *opaque, uint32_t addr, uint32_t data) { RTCState *s = opaque; struct domain *d = vrtc_domain(s); uint32_t orig; spin_lock(&s->lock); if ( (addr & 1) == 0 ) { data &= 0x7f; s->hw.cmos_index = data; spin_unlock(&s->lock); return (data < RTC_CMOS_SIZE); } if ( s->hw.cmos_index >= RTC_CMOS_SIZE ) { spin_unlock(&s->lock); return 0; } orig = s->hw.cmos_data[s->hw.cmos_index]; switch ( s->hw.cmos_index ) { case RTC_SECONDS_ALARM: case RTC_MINUTES_ALARM: case RTC_HOURS_ALARM: s->hw.cmos_data[s->hw.cmos_index] = data; alarm_timer_update(s); break; case RTC_SECONDS: case RTC_MINUTES: case RTC_HOURS: case RTC_DAY_OF_WEEK: case RTC_DAY_OF_MONTH: case RTC_MONTH: case RTC_YEAR: s->hw.cmos_data[s->hw.cmos_index] = data; /* if in set mode, do not update the time */ if ( !(s->hw.cmos_data[RTC_REG_B] & RTC_SET) ) rtc_set_time(s); alarm_timer_update(s); break; case RTC_REG_A: /* UIP bit is read only */ s->hw.cmos_data[RTC_REG_A] = (data & ~RTC_UIP) | (orig & RTC_UIP); if ( (data ^ orig) & ~RTC_UIP ) rtc_timer_update(s); break; case RTC_REG_B: if ( data & RTC_SET ) { /* set mode: reset UIP mode */ s->hw.cmos_data[RTC_REG_A] &= ~RTC_UIP; /* adjust cmos before stopping */ if (!(s->hw.cmos_data[RTC_REG_B] & RTC_SET)) { s->current_tm = gmtime(get_localtime(d)); rtc_copy_date(s); } } else { /* if disabling set mode, update the time */ if ( s->hw.cmos_data[RTC_REG_B] & RTC_SET ) rtc_set_time(s); } /* if the interrupt is already set when the interrupt become * enabled, raise an interrupt immediately*/ if ((data & RTC_UIE) && !(s->hw.cmos_data[RTC_REG_B] & RTC_UIE)) if (s->hw.cmos_data[RTC_REG_C] & RTC_UF) { hvm_isa_irq_deassert(d, RTC_IRQ); hvm_isa_irq_assert(d, RTC_IRQ); } s->hw.cmos_data[RTC_REG_B] = data; if ( (data ^ orig) & RTC_PIE ) rtc_timer_update(s); check_update_timer(s); alarm_timer_update(s); break; case RTC_REG_C: case RTC_REG_D: /* cannot write to them */ break; } spin_unlock(&s->lock); return 1; }
size_t track_init(satdata_mag *data, msynth_workspace *msynth_p, track_workspace *w) { size_t nflagged = 0; size_t i = 0, j; w->data = data; while (i < data->n - 1) { int s; double lon_eq, t_eq, lt_eq; size_t sidx, eidx; track_data *tptr; s = satdata_mag_find_track(i, &eidx, data); if (s) { #if TRACK_DEBUG fprintf(stderr, "track_init: no more tracks found in [%zu, %zu]\n", sidx, data->n - 1); #endif break; } /* update index i for next loop */ sidx = i; i = eidx + 1; /* check for equator crossing */ if (data->latitude[sidx] * data->latitude[eidx] < 0.0) { size_t idx; time_t unix_time; /* there is an equator crossing, find time and longitude */ if (data->latitude[eidx] > data->latitude[sidx]) idx = bsearch_double(data->latitude, 0.0, sidx, eidx); else if (data->latitude[eidx] < data->latitude[sidx]) idx = bsearch_desc_double(data->latitude, 0.0, sidx, eidx); /* sanity check we found equator crossing */ assert(data->latitude[idx] * data->latitude[idx + 1] < 0.0); /* interpolate t, but not longitude due to wrapping effects */ t_eq = interp1d(data->latitude[idx], data->latitude[idx + 1], data->t[idx], data->t[idx + 1], 0.0); lon_eq = data->longitude[idx]; /* compute local time */ unix_time = satdata_epoch2timet(t_eq); lt_eq = get_localtime(unix_time, lon_eq * M_PI / 180.0); } else { /* no equator crossing */ #if TRACK_DEBUG fprintf(stderr, "track_init: flagging partial track [%zu, %zu]\n", sidx, eidx); #endif nflagged += track_flag_data(sidx, eidx, data); continue; } /* compute main field along track in data->F_main */ if (msynth_p) track_calc_mf(sidx, eidx, data, msynth_p); /* store this track information */ tptr = &(w->tracks[w->n]); tptr->start_idx = sidx; tptr->end_idx = eidx; tptr->n = eidx - sidx + 1; tptr->t_eq = t_eq; tptr->lon_eq = lon_eq; tptr->lt_eq = lt_eq; tptr->nrms_scal = 0; tptr->nrms_vec = 0; tptr->flags = 0; tptr->k_ext = 0.0; tptr->meanalt = gsl_stats_mean(&(data->altitude[sidx]), 1, tptr->n); /* use index of track center to compute satellite direction */ tptr->satdir = satdata_mag_satdir(sidx + tptr->n / 2, data); for (j = 0; j < 3; ++j) tptr->rms[j] = 0.0; assert(tptr->n > 0); /* compute and store along-track residuals */ tptr->Bx = malloc(tptr->n * sizeof(double)); tptr->By = malloc(tptr->n * sizeof(double)); tptr->Bz = malloc(tptr->n * sizeof(double)); tptr->Bf = malloc(tptr->n * sizeof(double)); track_calc_residuals(tptr, data); if (++(w->n) >= w->ntot) { fprintf(stderr, "track_init: ntot not large enough: %zu\n", w->ntot); return nflagged; } } #if TRACK_DEBUG fprintf(stderr, "track_init: found %zu tracks\n", w->n); #endif return nflagged; } /* track_init() */
static int rtc_ioport_write(void *opaque, uint32_t addr, uint32_t data) { RTCState *s = opaque; struct domain *d = vrtc_domain(s); uint32_t orig; spin_lock(&s->lock); if ( (addr & 1) == 0 ) { data &= 0x7f; s->hw.cmos_index = data; spin_unlock(&s->lock); return (data < RTC_CMOS_SIZE); } if ( s->hw.cmos_index >= RTC_CMOS_SIZE ) { spin_unlock(&s->lock); return 0; } orig = s->hw.cmos_data[s->hw.cmos_index]; switch ( s->hw.cmos_index ) { case RTC_SECONDS_ALARM: case RTC_MINUTES_ALARM: case RTC_HOURS_ALARM: s->hw.cmos_data[s->hw.cmos_index] = data; alarm_timer_update(s); break; case RTC_SECONDS: case RTC_MINUTES: case RTC_HOURS: case RTC_DAY_OF_WEEK: case RTC_DAY_OF_MONTH: case RTC_MONTH: case RTC_YEAR: /* if in set mode, just write the register */ if ( (s->hw.cmos_data[RTC_REG_B] & RTC_SET) ) s->hw.cmos_data[s->hw.cmos_index] = data; else { /* Fetch the current time and update just this field. */ s->current_tm = gmtime(get_localtime(d)); rtc_copy_date(s); s->hw.cmos_data[s->hw.cmos_index] = data; rtc_set_time(s); } alarm_timer_update(s); break; case RTC_REG_A: /* UIP bit is read only */ s->hw.cmos_data[RTC_REG_A] = (data & ~RTC_UIP) | (orig & RTC_UIP); if ( (data ^ orig) & ~RTC_UIP ) rtc_timer_update(s); break; case RTC_REG_B: if ( data & RTC_SET ) { /* set mode: reset UIP mode */ s->hw.cmos_data[RTC_REG_A] &= ~RTC_UIP; /* adjust cmos before stopping */ if (!(orig & RTC_SET)) { s->current_tm = gmtime(get_localtime(d)); rtc_copy_date(s); } } else { /* if disabling set mode, update the time */ if ( orig & RTC_SET ) rtc_set_time(s); } check_for_pf_ticks(s); s->hw.cmos_data[RTC_REG_B] = data; /* * If the interrupt is already set when the interrupt becomes * enabled, raise an interrupt immediately. */ rtc_update_irq(s); if ( (data ^ orig) & RTC_PIE ) { TRACE_0D(TRC_HVM_EMUL_RTC_STOP_TIMER); destroy_periodic_time(&s->pt); s->period = 0; rtc_timer_update(s); } if ( (data ^ orig) & RTC_SET ) check_update_timer(s); if ( (data ^ orig) & (RTC_24H | RTC_DM_BINARY | RTC_SET) ) alarm_timer_update(s); break; case RTC_REG_C: case RTC_REG_D: /* cannot write to them */ break; } spin_unlock(&s->lock); return 1; }
/* handle alarm timer */ static void alarm_timer_update(RTCState *s) { uint64_t next_update_time, next_alarm_sec; uint64_t expire_time; int32_t alarm_sec, alarm_min, alarm_hour, cur_hour, cur_min, cur_sec; int32_t hour, min; struct domain *d = vrtc_domain(s); ASSERT(spin_is_locked(&s->lock)); stop_timer(&s->alarm_timer); if (!(s->hw.cmos_data[RTC_REG_C] & RTC_AF) && !(s->hw.cmos_data[RTC_REG_B] & RTC_SET)) { s->current_tm = gmtime(get_localtime(d)); rtc_copy_date(s); alarm_sec = from_bcd(s, s->hw.cmos_data[RTC_SECONDS_ALARM]); alarm_min = from_bcd(s, s->hw.cmos_data[RTC_MINUTES_ALARM]); alarm_hour = convert_hour(s, s->hw.cmos_data[RTC_HOURS_ALARM]); cur_sec = from_bcd(s, s->hw.cmos_data[RTC_SECONDS]); cur_min = from_bcd(s, s->hw.cmos_data[RTC_MINUTES]); cur_hour = convert_hour(s, s->hw.cmos_data[RTC_HOURS]); next_update_time = USEC_PER_SEC - (get_localtime_us(d) % USEC_PER_SEC); next_update_time = next_update_time * NS_PER_USEC + NOW(); if ((s->hw.cmos_data[RTC_HOURS_ALARM] & 0xc0) == 0xc0) { if ((s->hw.cmos_data[RTC_MINUTES_ALARM] & 0xc0) == 0xc0) { if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec = 1; else if (cur_sec < alarm_sec) next_alarm_sec = alarm_sec - cur_sec; else next_alarm_sec = alarm_sec + SEC_PER_MIN - cur_sec; } else { if (cur_min < alarm_min) { min = alarm_min - cur_min; next_alarm_sec = min * SEC_PER_MIN - cur_sec; if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec += 0; else next_alarm_sec += alarm_sec; } else if (cur_min == alarm_min) { if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec = 1; else if (cur_sec < alarm_sec) next_alarm_sec = alarm_sec - cur_sec; else { min = alarm_min + MIN_PER_HOUR - cur_min; next_alarm_sec = alarm_sec + min * SEC_PER_MIN - cur_sec; } } else { min = alarm_min + MIN_PER_HOUR - cur_min; next_alarm_sec = min * SEC_PER_MIN - cur_sec; if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec += 0; else next_alarm_sec += alarm_sec; } } } else { if (cur_hour < alarm_hour) { hour = alarm_hour - cur_hour; next_alarm_sec = hour * SEC_PER_HOUR - cur_min * SEC_PER_MIN - cur_sec; if ((s->hw.cmos_data[RTC_MINUTES_ALARM] & 0xc0) == 0xc0) { if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec += 0; else next_alarm_sec += alarm_sec; } else { next_alarm_sec += alarm_min * SEC_PER_MIN; if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec += 0; else next_alarm_sec += alarm_sec; } } else if (cur_hour == alarm_hour) { if ((s->hw.cmos_data[RTC_MINUTES_ALARM] & 0xc0) == 0xc0) { if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec = 1; else if (cur_sec < alarm_sec) next_alarm_sec = alarm_sec - cur_sec; else next_alarm_sec = alarm_sec + SEC_PER_MIN - cur_sec; } else if (cur_min < alarm_min) { min = alarm_min - cur_min; next_alarm_sec = min * SEC_PER_MIN - cur_sec; if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec += 0; else next_alarm_sec += alarm_sec; } else if (cur_min == alarm_min) { if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec = 1; else if (cur_sec < alarm_sec) next_alarm_sec = alarm_sec - cur_sec; else { hour = alarm_hour + HOUR_PER_DAY - cur_hour; next_alarm_sec = hour * SEC_PER_HOUR - cur_min * SEC_PER_MIN - cur_sec; next_alarm_sec += alarm_min * SEC_PER_MIN + alarm_sec; } } else { hour = alarm_hour + HOUR_PER_DAY - cur_hour; next_alarm_sec = hour * SEC_PER_HOUR - cur_min * SEC_PER_MIN - cur_sec; next_alarm_sec += alarm_min * SEC_PER_MIN; if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec += 0; else next_alarm_sec += alarm_sec; } } else { hour = alarm_hour + HOUR_PER_DAY - cur_hour; next_alarm_sec = hour * SEC_PER_HOUR - cur_min * SEC_PER_MIN - cur_sec; if ((s->hw.cmos_data[RTC_MINUTES_ALARM] & 0xc0) == 0xc0) { if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec += 0; else next_alarm_sec += alarm_sec; } else { next_alarm_sec += alarm_min * SEC_PER_MIN; if ((s->hw.cmos_data[RTC_SECONDS_ALARM] & 0xc0) == 0xc0) next_alarm_sec += 0; else next_alarm_sec += alarm_sec; } } } expire_time = (next_alarm_sec - 1) * NS_PER_SEC + next_update_time; /* release lock before set timer */ spin_unlock(&s->lock); set_timer(&s->alarm_timer, expire_time); /* fetch lock again */ spin_lock(&s->lock); } }
int track_print_track(const int header, FILE *fp, const track_data *tptr, const satdata_mag *data) { int s = 0; size_t j; if (header) { j = 1; fprintf(fp, "# Field %zu: timestamp (UT seconds since 1970-01-01 00:00:00 UTC)\n", j++); fprintf(fp, "# Field %zu: UT (hours)\n", j++); fprintf(fp, "# Field %zu: local time (hours)\n", j++); fprintf(fp, "# Field %zu: season (doy)\n", j++); fprintf(fp, "# Field %zu: radius (km)\n", j++); fprintf(fp, "# Field %zu: longitude (degrees)\n", j++); fprintf(fp, "# Field %zu: geocentric latitude (degrees)\n", j++); fprintf(fp, "# Field %zu: QD latitude (degrees)\n", j++); fprintf(fp, "# Field %zu: NEC X residual (nT)\n", j++); fprintf(fp, "# Field %zu: NEC Y residual (nT)\n", j++); fprintf(fp, "# Field %zu: NEC Z residual (nT)\n", j++); fprintf(fp, "# Field %zu: F residual (nT)\n", j++); fprintf(fp, "# Field %zu: NEC X measurement (nT)\n", j++); fprintf(fp, "# Field %zu: NEC Y measurement (nT)\n", j++); fprintf(fp, "# Field %zu: NEC Z measurement (nT)\n", j++); fprintf(fp, "# Field %zu: electron density data (cm^{-3})\n", j++); return s; } for (j = 0; j < tptr->n; ++j) { size_t didx = j + tptr->start_idx; time_t unix_time = satdata_epoch2timet(data->t[didx]); double ut = get_ut(unix_time); double lt = get_localtime(unix_time, data->longitude[didx] * M_PI / 180.0); if (SATDATA_BadData(data->flags[didx])) continue; fprintf(fp, "%ld %.2f %.2f %.1f %.2f %.3f %.3f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %.5e\n", unix_time, ut, lt, get_season(unix_time), data->altitude[didx] + data->R, data->longitude[didx], data->latitude[didx], data->qdlat[didx], tptr->Bx[j], tptr->By[j], tptr->Bz[j], tptr->Bf[j], SATDATA_VEC_X(data->B, didx), SATDATA_VEC_Y(data->B, didx), SATDATA_VEC_Z(data->B, didx), data->ne[didx]); } fprintf(fp, "\n\n"); return s; }
/* *************************************************************************** * Main entry to the cifsiostat program. *************************************************************************** */ int main(int argc, char **argv) { int it = 0; int opt = 1; int i; long count = 1; struct utsname header; struct tm rectime; #ifdef USE_NLS /* Init National Language Support */ init_nls(); #endif /* Get HZ */ get_HZ(); /* Process args... */ while (opt < argc) { #ifdef DEBUG if (!strcmp(argv[opt], "--debuginfo")) { flags |= I_D_DEBUG; opt++; } else #endif if (!strncmp(argv[opt], "-", 1)) { for (i = 1; *(argv[opt] + i); i++) { switch (*(argv[opt] + i)) { case 'h': /* Display an easy-to-read CIFS report */ flags |= I_D_HUMAN_READ; break; case 'k': if (DISPLAY_MEGABYTES(flags)) { usage(argv[0]); } /* Display stats in kB/s */ flags |= I_D_KILOBYTES; break; case 'm': if (DISPLAY_KILOBYTES(flags)) { usage(argv[0]); } /* Display stats in MB/s */ flags |= I_D_MEGABYTES; break; case 't': /* Display timestamp */ flags |= I_D_TIMESTAMP; break; case 'V': /* Print version number and exit */ print_version(); break; default: usage(argv[0]); } } opt++; } else if (!it) { interval = atol(argv[opt++]); if (interval < 0) { usage(argv[0]); } count = -1; it = 1; } else if (it > 0) { count = atol(argv[opt++]); if ((count < 1) || !interval) { usage(argv[0]); } it = -1; } else { usage(argv[0]); } } if (!interval) { count = 1; } /* Init structures according to machine architecture */ io_sys_init(); get_localtime(&rectime); /* Get system name, release number and hostname */ uname(&header); if (print_gal_header(&rectime, header.sysname, header.release, header.nodename, header.machine, cpu_nr)) { flags |= I_D_ISO; } printf("\n"); /* Set a handler for SIGALRM */ alarm_handler(0); /* Main loop */ rw_io_stat_loop(count, &rectime); /* Free structures */ io_sys_free(); return 0; }