Exemplo n.º 1
0
// ----------------------------------------------------------------------
// load file & check time-to-live
TEST(leapsec, loadFileTTL) {
	const char *cp = leap1;
	int rc;
	leap_table_t * pt = leapsec_get_table(0);
	time_t         pivot = 0x70000000;

	const uint32_t limit = 3610569600u;

	rc =   leapsec_load(pt, stringreader, &cp, false)
	    && leapsec_set_table(pt);
	TEST_ASSERT_EQUAL(1, rc);

	// exactly 1 day to live
	rc = leapsec_daystolive(limit - 86400, &pivot);
	TEST_ASSERT_EQUAL( 1, rc);
	// less than 1 day to live
	rc = leapsec_daystolive(limit - 86399, &pivot);
	TEST_ASSERT_EQUAL( 0, rc);
	// hit expiration exactly
	rc = leapsec_daystolive(limit, &pivot);
	TEST_ASSERT_EQUAL( 0, rc);
	// expired since 1 sec
	rc = leapsec_daystolive(limit + 1, &pivot);
	TEST_ASSERT_EQUAL(-1, rc);
}
Exemplo n.º 2
0
/*
 * check expiration of a loaded leap table
 */
static void
check_leap_expiration(
	int           is_daily_check,
	uint32_t      ntptime       ,
	const time_t *systime
	)
{
	static const char * const logPrefix = "leapsecond file";
	int  rc;

	/* test the expiration of the leap data and log with proper
	 * level and frequency (once/hour or once/day, depending on the
	 * state.
	 */
	rc = leapsec_daystolive(ntptime, systime);	
	if (rc == 0) {
		msyslog(LOG_WARNING,
			"%s ('%s'): will expire in less than one day",
			logPrefix, leapfile_name);
	} else if (is_daily_check && rc < 28) {
		if (rc < 0)
			msyslog(LOG_ERR,
				"%s ('%s'): expired less than %d day%s ago",
				logPrefix, leapfile_name, -rc, (rc == -1 ? "" : "s"));
		else
			msyslog(LOG_WARNING,
				"%s ('%s'): will expire in less than %d days",
				logPrefix, leapfile_name, 1+rc);
	}
}