Replace all CROAK calls with assert or LOG_FATAL

Remove croak() and use assert() or LOG_FATAL() everywhere. Hopefully
the problems with debugging mentioned in the croak() comment are long gone.
This commit is contained in:
Miroslav Lichvar 2010-08-12 14:30:05 +02:00
parent 2a64b75893
commit 6b0198c2d7
13 changed files with 105 additions and 195 deletions

View file

@ -261,16 +261,10 @@ prepare_socket(int family)
void void
CAM_Initialise(void) CAM_Initialise(void)
{ {
assert(!initialised);
if (initialised) {
CROAK("Shouldn't be initialised");
}
initialised = 1; initialised = 1;
if ((sizeof(permissions)/sizeof(permissions[0])) != N_REQUEST_TYPES) { assert(sizeof (permissions) / sizeof (permissions[0]) == N_REQUEST_TYPES);
CROAK("Permissions table size wrong");
}
utoken = (unsigned long) time(NULL); utoken = (unsigned long) time(NULL);
@ -1248,7 +1242,7 @@ handle_add_server(CMD_Request *rx_message, CMD_Reply *tx_message)
tx_message->status = htons(STT_INVALIDAF); tx_message->status = htons(STT_INVALIDAF);
break; break;
case NSR_NoSuchSource: case NSR_NoSuchSource:
CROAK("Impossible"); assert(0);
break; break;
} }
} }
@ -1289,7 +1283,7 @@ handle_add_peer(CMD_Request *rx_message, CMD_Reply *tx_message)
tx_message->status = htons(STT_INVALIDAF); tx_message->status = htons(STT_INVALIDAF);
break; break;
case NSR_NoSuchSource: case NSR_NoSuchSource:
CROAK("Impossible"); assert(0);
break; break;
} }
} }
@ -1317,7 +1311,7 @@ handle_del_source(CMD_Request *rx_message, CMD_Reply *tx_message)
case NSR_TooManySources: case NSR_TooManySources:
case NSR_AlreadyInUse: case NSR_AlreadyInUse:
case NSR_InvalidAF: case NSR_InvalidAF:
CROAK("Impossible"); assert(0);
break; break;
} }
} }
@ -1508,7 +1502,7 @@ handle_subnets_accessed(CMD_Request *rx_message, CMD_Reply *tx_message)
tx_message->status = htons(STT_INACTIVE); tx_message->status = htons(STT_INACTIVE);
return; return;
default: default:
CROAK("Impossible"); assert(0);
break; break;
} }
} }
@ -1563,7 +1557,7 @@ handle_client_accesses(CMD_Request *rx_message, CMD_Reply *tx_message)
tx_message->status = htons(STT_INACTIVE); tx_message->status = htons(STT_INACTIVE);
return; return;
default: default:
CROAK("Impossible"); assert(0);
break; break;
} }
} }
@ -1615,7 +1609,7 @@ handle_client_accesses_by_index(CMD_Request *rx_message, CMD_Reply *tx_message)
tx_message->status = htons(STT_INACTIVE); tx_message->status = htons(STT_INACTIVE);
return; return;
default: default:
CROAK("Impossible"); assert(0);
break; break;
} }
} }
@ -2011,7 +2005,7 @@ read_from_cmd_socket(void *anything)
allowed = 1; allowed = 1;
break; break;
default: default:
CROAK("Impossible"); assert(0);
} }
if (allowed) { if (allowed) {

22
local.c
View file

@ -123,9 +123,9 @@ calculate_sys_precision(void)
iters++; iters++;
} }
} while (iters < NITERS); } while (iters < NITERS);
if (!(best_dusec > 0)) {
CROAK("best_dusec should be positive"); assert(best_dusec > 0);
}
precision_quantum = best_dusec * 1.0e-6; precision_quantum = best_dusec * 1.0e-6;
precision_log = 0; precision_log = 0;
while (best_dusec < 500000) { while (best_dusec < 500000) {
@ -196,7 +196,7 @@ LCL_AddParameterChangeHandler(LCL_ParameterChangeHandler handler, void *anything
/* Check that the handler is not already registered */ /* Check that the handler is not already registered */
for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) { for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) {
if (!(ptr->handler != handler || ptr->anything != anything)) { if (!(ptr->handler != handler || ptr->anything != anything)) {
CROAK("a handler is already registered"); assert(0);
} }
} }
@ -234,9 +234,7 @@ void LCL_RemoveParameterChangeHandler(LCL_ParameterChangeHandler handler, void *
} }
} }
if (!ok) { assert(ok);
CROAK("did not find a matching handler");
}
/* Unlink entry from the list */ /* Unlink entry from the list */
ptr->next->prev = ptr->prev; ptr->next->prev = ptr->prev;
@ -257,7 +255,7 @@ LCL_AddDispersionNotifyHandler(LCL_DispersionNotifyHandler handler, void *anythi
/* Check that the handler is not already registered */ /* Check that the handler is not already registered */
for (ptr = dispersion_notify_list.next; ptr != &dispersion_notify_list; ptr = ptr->next) { for (ptr = dispersion_notify_list.next; ptr != &dispersion_notify_list; ptr = ptr->next) {
if (!(ptr->handler != handler || ptr->anything != anything)) { if (!(ptr->handler != handler || ptr->anything != anything)) {
CROAK("a handler is already registered"); assert(0);
} }
} }
@ -295,9 +293,7 @@ void LCL_RemoveDispersionNotifyHandler(LCL_DispersionNotifyHandler handler, void
} }
} }
if (!ok) { assert(ok);
CROAK("no matching handler found");
}
/* Unlink entry from the list */ /* Unlink entry from the list */
ptr->next->prev = ptr->prev; ptr->next->prev = ptr->prev;
@ -317,8 +313,8 @@ LCL_ReadRawTime(struct timeval *result)
{ {
struct timezone tz; struct timezone tz;
if (!(gettimeofday(result, &tz) >= 0)) { if (gettimeofday(result, &tz) < 0) {
CROAK("Could not get time of day"); LOG_FATAL(LOGF_Local, "gettimeofday() failed");
} }
} }

View file

@ -249,22 +249,6 @@ LOG_RateLimited(void)
return 0; return 0;
} }
/* ================================================== */
/* Force a core dump and exit without doing abort() or assert(0).
These do funny things with the call stack in the core file that is
generated, which makes diagnosis difficult. */
int
croak(const char *file, int line, const char *msg)
{
int a;
LOG(LOGS_ERR, LOGF_Util, "Unexpected condition [%s] at %s:%d, core dumped",
msg, file, line);
a = * (int *) 0;
return a; /* Can't happen - this stops the optimiser optimising the
line above */
}
/* ================================================== */ /* ================================================== */
LOG_FileID LOG_FileID

View file

@ -63,6 +63,7 @@ typedef enum {
LOGF_Regress, LOGF_Regress,
LOGF_Sys, LOGF_Sys,
LOGF_SysLinux, LOGF_SysLinux,
LOGF_SysNetBSD,
LOGF_SysSolaris, LOGF_SysSolaris,
LOGF_SysSunOS, LOGF_SysSunOS,
LOGF_SysWinnt, LOGF_SysWinnt,
@ -100,15 +101,6 @@ extern int LOG_RateLimited(void);
#define LOG_FATAL LOG_Position(__FILE__, __LINE__, ""); LOG_Fatal_Function #define LOG_FATAL LOG_Position(__FILE__, __LINE__, ""); LOG_Fatal_Function
#endif /* defined (__GNUC__) */ #endif /* defined (__GNUC__) */
/* Like assert(0) */
#if defined(LINUX) && defined(__alpha__)
#define CROAK(message) assert(0) /* Added JGH Feb 24 2001 FIXME */
#else
extern int croak(const char *file, int line, const char *msg);
#define CROAK(message) croak(__FILE__, __LINE__, message);
#endif
/* File logging functions */ /* File logging functions */
typedef int LOG_FileID; typedef int LOG_FileID;

View file

@ -1210,7 +1210,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
break; break;
default: default:
CROAK("Impossible"); assert(0);
break; break;
} }
@ -1224,7 +1224,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
break; break;
default: default:
CROAK("Impossible"); assert(0);
break; break;
} }
@ -1786,7 +1786,7 @@ NCR_InitiateSampleBurst(NCR_Instance inst, int n_good_samples, int n_total_sampl
default: default:
CROAK("Impossible"); assert(0);
break; break;
} }
} }
@ -1808,7 +1808,7 @@ NCR_ReportSource(NCR_Instance inst, RPT_SourceReport *report, struct timeval *no
report->mode = RPT_NTP_PEER; report->mode = RPT_NTP_PEER;
break; break;
default: default:
CROAK("Impossible"); assert(0);
} }
return; return;
@ -1872,7 +1872,7 @@ NCR_IncrementActivityCounters(NCR_Instance inst, int *online, int *offline,
++*offline; ++*offline;
break; break;
default: default:
CROAK("Impossible"); assert(0);
break; break;
} }
} }

View file

@ -69,9 +69,7 @@ RGR_WeightedRegression
double u, ui, aa; double u, ui, aa;
int i; int i;
if (n<3) { assert(n >= 3);
CROAK("Insufficient points");
}
W = U = 0; W = U = 0;
for (i=0; i<n; i++) { for (i=0; i<n; i++) {
@ -358,9 +356,7 @@ find_ordered_entry_with_flags(double *x, int n, int index, int *flags)
double piv; double piv;
int pivind; int pivind;
if (index < 0) { assert(index >= 0);
CROAK("Negative index");
}
/* If this bit of the array is already sorted, simple! */ /* If this bit of the array is already sorted, simple! */
if (flags[index]) { if (flags[index]) {
@ -404,8 +400,6 @@ find_ordered_entry_with_flags(double *x, int n, int index, int *flags)
v = r - 1; v = r - 1;
} else if (index > r) { } else if (index > r) {
u = l; u = l;
} else {
CROAK("Impossible");
} }
} }
} while (1); } while (1);
@ -619,7 +613,7 @@ RGR_FindBestRobustRegression
bhi = bmid; bhi = bmid;
rhi = rmid; rhi = rmid;
} else { } else {
CROAK("Impossible"); assert(0);
} }
} while ((bhi - blo) > tol); } while ((bhi - blo) > tol);

View file

@ -193,12 +193,7 @@ discard_samples(int new_first)
{ {
int n_to_save; int n_to_save;
if (!(new_first < n_samples)) { assert(new_first >= 0 && new_first < n_samples);
CROAK("new_first should be < n_samples");
}
if (!(new_first >= 0)) {
CROAK("new_first should be non-negative");
}
n_to_save = n_samples - new_first; n_to_save = n_samples - new_first;
@ -802,7 +797,7 @@ process_reading(time_t rtc_time, struct timeval *system_time)
} }
break; break;
default: default:
CROAK("Impossible"); assert(0);
break; break;
} }
@ -937,7 +932,7 @@ turn_off_interrupt:
break; break;
default: default:
CROAK("Impossible"); assert(0);
break; break;
} }

51
sched.c
View file

@ -164,16 +164,12 @@ SCH_AddInputFileHandler
(int fd, SCH_FileHandler handler, SCH_ArbitraryArgument arg) (int fd, SCH_FileHandler handler, SCH_ArbitraryArgument arg)
{ {
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
/* Don't want to allow the same fd to register a handler more than /* Don't want to allow the same fd to register a handler more than
once without deleting a previous association - this suggests once without deleting a previous association - this suggests
a bug somewhere else in the program. */ a bug somewhere else in the program. */
if (FD_ISSET(fd, &read_fds)) { assert(!FD_ISSET(fd, &read_fds));
CROAK("File handler already registered");
}
++n_read_fds; ++n_read_fds;
@ -197,14 +193,10 @@ SCH_RemoveInputFileHandler(int fd)
{ {
int fds_left, fd_to_check; int fds_left, fd_to_check;
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
/* Check that a handler was registered for the fd in question */ /* Check that a handler was registered for the fd in question */
if (!FD_ISSET(fd, &read_fds)) { assert(FD_ISSET(fd, &read_fds));
CROAK("File handler not registered");
}
--n_read_fds; --n_read_fds;
@ -278,9 +270,7 @@ SCH_AddTimeout(struct timeval *tv, SCH_TimeoutHandler handler, SCH_ArbitraryArgu
TimerQueueEntry *new_tqe; TimerQueueEntry *new_tqe;
TimerQueueEntry *ptr; TimerQueueEntry *ptr;
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
new_tqe = allocate_tqe(); new_tqe = allocate_tqe();
@ -321,9 +311,7 @@ SCH_AddTimeoutByDelay(double delay, SCH_TimeoutHandler handler, SCH_ArbitraryArg
{ {
struct timeval now, then; struct timeval now, then;
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
LCL_ReadRawTime(&now); LCL_ReadRawTime(&now);
UTI_AddDoubleToTimeval(&now, delay, &then); UTI_AddDoubleToTimeval(&now, delay, &then);
@ -344,9 +332,7 @@ SCH_AddTimeoutInClass(double min_delay, double separation,
double diff; double diff;
double new_min_delay; double new_min_delay;
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
LCL_ReadRawTime(&now); LCL_ReadRawTime(&now);
new_min_delay = min_delay; new_min_delay = min_delay;
@ -402,9 +388,7 @@ SCH_RemoveTimeout(SCH_TimeoutID id)
TimerQueueEntry *ptr; TimerQueueEntry *ptr;
int ok; int ok;
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
ok = 0; ok = 0;
@ -527,9 +511,7 @@ SCH_MainLoop(void)
struct timeval tv, *ptv; struct timeval tv, *ptv;
struct timeval now; struct timeval now;
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
while (!need_to_exit) { while (!need_to_exit) {
@ -565,8 +547,7 @@ SCH_MainLoop(void)
status = select(one_highest_fd, &rd, NULL, NULL, ptv); status = select(one_highest_fd, &rd, NULL, NULL, ptv);
if (status < 0) { if (status < 0) {
if (!need_to_exit) assert(need_to_exit);
CROAK("Status < 0 after select");
} else if (status > 0) { } else if (status > 0) {
/* A file descriptor is ready to read */ /* A file descriptor is ready to read */
@ -574,15 +555,11 @@ SCH_MainLoop(void)
dispatch_filehandlers(status, &rd); dispatch_filehandlers(status, &rd);
} else { } else {
if (status != 0) { assert(status == 0);
CROAK("Unexpected value from select");
}
/* No descriptors readable, timeout must have elapsed. /* No descriptors readable, timeout must have elapsed.
Therefore, tv must be non-null */ Therefore, tv must be non-null */
if (!ptv) { assert(ptv);
CROAK("No descriptors or timeout?");
}
/* There's nothing to do here, since the timeouts /* There's nothing to do here, since the timeouts
will be dispatched at the top of the next loop will be dispatched at the top of the next loop
@ -600,9 +577,7 @@ SCH_MainLoop(void)
void void
SCH_QuitProgram(void) SCH_QuitProgram(void)
{ {
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
need_to_exit = 1; need_to_exit = 1;
} }

View file

@ -169,9 +169,7 @@ SRC_Instance SRC_CreateNewInstance(unsigned long ref_id, SRC_Type type, IPAddr *
{ {
SRC_Instance result; SRC_Instance result;
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
result = MallocNew(struct SRC_Instance_Record); result = MallocNew(struct SRC_Instance_Record);
result->stats = SST_CreateInstance(ref_id, addr); result->stats = SST_CreateInstance(ref_id, addr);
@ -214,9 +212,7 @@ void SRC_DestroyInstance(SRC_Instance instance)
{ {
int dead_index, i; int dead_index, i;
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
if (instance->index == selected_source_index) { if (instance->index == selected_source_index) {
instance->reachable = 0; instance->reachable = 0;
@ -251,9 +247,7 @@ void SRC_DestroyInstance(SRC_Instance instance)
void SRC_GetFrequencyRange(SRC_Instance instance, double *lo, double *hi) void SRC_GetFrequencyRange(SRC_Instance instance, double *lo, double *hi)
{ {
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
SST_GetFrequencyRange(instance->stats, lo, hi); SST_GetFrequencyRange(instance->stats, lo, hi);
return; return;
@ -284,9 +278,7 @@ void SRC_AccumulateSample
NTP_Leap leap_status) NTP_Leap leap_status)
{ {
if (!initialised) { assert(initialised);
CROAK("Should be initialised");
}
inst->leap_status = leap_status; inst->leap_status = leap_status;
@ -372,7 +364,7 @@ source_to_string(SRC_Instance inst)
case SRC_REFCLOCK: case SRC_REFCLOCK:
return UTI_RefidToString(inst->ref_id); return UTI_RefidToString(inst->ref_id);
default: default:
CROAK("Unknown source type"); assert(0);
} }
return NULL; return NULL;
} }
@ -530,7 +522,7 @@ SRC_SelectSource(unsigned long match_addr)
break; break;
case CENTRE: case CENTRE:
CROAK("CENTRE cannot occur"); assert(0);
break; break;
case HIGH: case HIGH:

View file

@ -222,7 +222,7 @@ update_slow_slew_error(int offset)
return; return;
if (gettimeofday(&now, &tz) < 0) { if (gettimeofday(&now, &tz) < 0) {
CROAK("gettimeofday() failed"); LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
} }
if (offset < 0) if (offset < 0)
@ -279,7 +279,7 @@ update_nano_slew_error(long offset, int new)
if (new || nano_slew_error_start.tv_sec > 0) { if (new || nano_slew_error_start.tv_sec > 0) {
if (gettimeofday(&now, &tz) < 0) { if (gettimeofday(&now, &tz) < 0) {
CROAK("gettimeofday() failed"); LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
} }
} }
@ -357,17 +357,15 @@ stop_fast_slew(void)
double slew_duration; double slew_duration;
/* Should never get here unless this is true */ /* Should never get here unless this is true */
if (!fast_slewing) { assert(fast_slewing);
CROAK("Should be fast slewing");
}
/* Now set the thing off */ /* Now set the thing off */
if (gettimeofday(&T1, &tz) < 0) { if (gettimeofday(&T1, &tz) < 0) {
CROAK("gettimeofday() failed in stop_fast_slew"); LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
} }
if (TMX_SetTick(current_tick) < 0) { if (TMX_SetTick(current_tick) < 0) {
CROAK("adjtimex() failed in stop_fast_slew"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
fast_slewing = 0; fast_slewing = 0;
@ -401,7 +399,7 @@ adjust_fast_slew(double old_tick, double old_delta_tick)
assert(fast_slewing); assert(fast_slewing);
if (gettimeofday(&tv, &tz) < 0) { if (gettimeofday(&tv, &tz) < 0) {
CROAK("gettimeofday() failed in stop_fast_slew"); LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
} }
UTI_DiffTimevalsToDouble(&slew_duration, &tv, &slew_start_tv); UTI_DiffTimevalsToDouble(&slew_duration, &tv, &slew_start_tv);
@ -437,9 +435,7 @@ initiate_slew(void)
struct timezone tz; struct timezone tz;
/* Don't want to get here if we already have an adjust on the go! */ /* Don't want to get here if we already have an adjust on the go! */
if (fast_slewing) { assert(!fast_slewing);
CROAK("Should not be fast slewing");
}
if (offset_register == 0.0) { if (offset_register == 0.0) {
return; return;
@ -449,21 +445,21 @@ initiate_slew(void)
if (slow_slewing) { if (slow_slewing) {
offset = 0; offset = 0;
if (TMX_ApplyOffset(&offset) < 0) { if (TMX_ApplyOffset(&offset) < 0) {
CROAK("adjtimex() failed in accrue_offset"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
offset_register -= (double) offset / 1.0e6; offset_register -= (double) offset / 1.0e6;
slow_slewing = 0; slow_slewing = 0;
update_slow_slew_error(0); update_slow_slew_error(0);
} else if (nano_slewing) { } else if (nano_slewing) {
if (TMX_GetPLLOffsetLeft(&offset) < 0) { if (TMX_GetPLLOffsetLeft(&offset) < 0) {
CROAK("adjtimex() failed in accrue_offset"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
offset_register -= (double) offset / 1.0e9; offset_register -= (double) offset / 1.0e9;
update_nano_slew_error(offset, 0); update_nano_slew_error(offset, 0);
offset = 0; offset = 0;
if (TMX_ApplyPLLOffset(offset) < 0) { if (TMX_ApplyPLLOffset(offset) < 0) {
CROAK("adjtimex() failed in accrue_offset"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
nano_slewing = 0; nano_slewing = 0;
update_nano_slew_error(offset, 1); update_nano_slew_error(offset, 1);
@ -474,7 +470,7 @@ initiate_slew(void)
offset = 1.0e9 * -offset_register; offset = 1.0e9 * -offset_register;
if (TMX_ApplyPLLOffset(offset) < 0) { if (TMX_ApplyPLLOffset(offset) < 0) {
CROAK("adjtimex() failed in accrue_offset"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
offset_register = 0.0; offset_register = 0.0;
nano_slewing = 1; nano_slewing = 1;
@ -487,7 +483,7 @@ initiate_slew(void)
if (offset != 0) { if (offset != 0) {
if (TMX_ApplyOffset(&offset) < 0) { if (TMX_ApplyOffset(&offset) < 0) {
CROAK("adjtimex() failed in initiate_slew"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
slow_slewing = 1; slow_slewing = 1;
update_slow_slew_error(offset); update_slow_slew_error(offset);
@ -524,13 +520,11 @@ initiate_slew(void)
/* Now set the thing off */ /* Now set the thing off */
if (gettimeofday(&T0, &tz) < 0) { if (gettimeofday(&T0, &tz) < 0) {
CROAK("gettimeofday() failed in initiate_slew"); LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
} }
if (TMX_SetTick(slewing_tick) < 0) { if (TMX_SetTick(slewing_tick) < 0) {
LOG(LOGS_INFO, LOGF_SysLinux, "c_t=%ld ta=%ld sl_t=%ld dtt=%e", LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
current_tick, tick_adjust, slewing_tick, delta_total_tick);
CROAK("adjtimex() failed to start big slew");
} }
/* Compute the dispersion we have introduced by changing tick this /* Compute the dispersion we have introduced by changing tick this
@ -618,17 +612,17 @@ apply_step_offset(double offset)
} }
if (gettimeofday(&old_time, &tz) < 0) { if (gettimeofday(&old_time, &tz) < 0) {
CROAK("gettimeofday in apply_step_offset"); LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
} }
UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
if (settimeofday(&new_time, &tz) < 0) { if (settimeofday(&new_time, &tz) < 0) {
CROAK("settimeofday in apply_step_offset"); LOG_FATAL(LOGF_SysLinux, "settimeofday() failed");
} }
if (gettimeofday(&old_time, &tz) < 0) { if (gettimeofday(&old_time, &tz) < 0) {
CROAK("gettimeofday in apply_step_offset"); LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
} }
UTI_DiffTimevalsToDouble(&err, &old_time, &new_time); UTI_DiffTimevalsToDouble(&err, &old_time, &new_time);
@ -727,7 +721,7 @@ read_frequency(void)
double freq_term; double freq_term;
if (TMX_GetFrequency(&unscaled_freq) < 0) { if (TMX_GetFrequency(&unscaled_freq) < 0) {
CROAK("adjtimex failed in read_frequency"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
/* Use current_tick here rather than txc.tick, otherwise we're /* Use current_tick here rather than txc.tick, otherwise we're
@ -773,22 +767,22 @@ get_offset_correction(struct timeval *raw,
switch (have_readonly_adjtime) { switch (have_readonly_adjtime) {
case 2: case 2:
if (TMX_GetOffsetLeft(&offset) < 0) { if (TMX_GetOffsetLeft(&offset) < 0) {
CROAK("adjtimex() failed in get_offset_correction"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
break; break;
case 0: case 0:
toffset = 0; toffset = 0;
if (TMX_ApplyOffset(&toffset) < 0) { if (TMX_ApplyOffset(&toffset) < 0) {
CROAK("adjtimex() failed in get_offset_correction"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
offset = toffset; offset = toffset;
if (TMX_ApplyOffset(&toffset) < 0) { if (TMX_ApplyOffset(&toffset) < 0) {
CROAK("adjtimex() failed in get_offset_correction"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
break; break;
case 1: case 1:
if (TMX_GetOffsetLeftOld(&offset) < 0) { if (TMX_GetOffsetLeftOld(&offset) < 0) {
CROAK("adjtimex() failed in get_offset_correction"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
break; break;
default: default:
@ -805,7 +799,7 @@ get_offset_correction(struct timeval *raw,
noffset = 0; noffset = 0;
} else { } else {
if (TMX_GetPLLOffsetLeft(&noffset) < 0) { if (TMX_GetPLLOffsetLeft(&noffset) < 0) {
CROAK("adjtimex() failed in get_offset_correction"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
if (noffset == 0) { if (noffset == 0) {
nano_slewing = 0; nano_slewing = 0;
@ -1091,7 +1085,7 @@ SYS_Linux_Initialise(void)
offset = 0; offset = 0;
if (TMX_ApplyOffset(&offset) < 0) { if (TMX_ApplyOffset(&offset) < 0) {
CROAK("adjtimex() failed in initialise"); LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
} }
if (have_readonly_adjtime == 2 && (TMX_GetOffsetLeft(&offset) < 0 || offset)) { if (have_readonly_adjtime == 2 && (TMX_GetOffsetLeft(&offset) < 0 || offset)) {

View file

@ -85,14 +85,14 @@ clock_initialise(void)
current_freq = 0.0; current_freq = 0.0;
if (gettimeofday(&T0, &tz) < 0) { if (gettimeofday(&T0, &tz) < 0) {
CROAK("gettimeofday() failed in clock_initialise()"); LOG_FATAL(LOGF_SysNetBSD, "gettimeofday() failed");
} }
newadj.tv_sec = 0; newadj.tv_sec = 0;
newadj.tv_usec = 0; newadj.tv_usec = 0;
if (adjtime(&newadj, &oldadj) < 0) { if (adjtime(&newadj, &oldadj) < 0) {
CROAK("adjtime() failed in clock_initialise"); LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed");
} }
} }
@ -123,7 +123,7 @@ start_adjust(void)
/* Determine the amount of error built up since the last adjustment */ /* Determine the amount of error built up since the last adjustment */
if (gettimeofday(&T1, &tz) < 0) { if (gettimeofday(&T1, &tz) < 0) {
CROAK("gettimeofday() failed in start_adjust"); LOG_FATAL(LOGF_SysNetBSD, "gettimeofday() failed");
} }
UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0);
@ -151,7 +151,7 @@ start_adjust(void)
UTI_DiffTimevalsToDouble(&rounding_error, &newadj, &exact_newadj); UTI_DiffTimevalsToDouble(&rounding_error, &newadj, &exact_newadj);
if (adjtime(&newadj, &oldadj) < 0) { if (adjtime(&newadj, &oldadj) < 0) {
CROAK("adjtime() failed in start_adjust"); LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed");
} }
UTI_TimevalToDouble(&oldadj, &old_adjust_remaining); UTI_TimevalToDouble(&oldadj, &old_adjust_remaining);
@ -178,11 +178,11 @@ stop_adjust(void)
zeroadj.tv_usec = 0; zeroadj.tv_usec = 0;
if (adjtime(&zeroadj, &remadj) < 0) { if (adjtime(&zeroadj, &remadj) < 0) {
CROAK("adjtime() failed in stop_adjust"); LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed");
} }
if (gettimeofday(&T1, &tz) < 0) { if (gettimeofday(&T1, &tz) < 0) {
CROAK("gettimeofday() failed in stop_adjust"); LOG_FATAL(LOGF_SysNetBSD, "gettimeofday() failed");
} }
UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0);
@ -226,13 +226,13 @@ apply_step_offset(double offset)
stop_adjust(); stop_adjust();
if (gettimeofday(&old_time, &tz) < 0) { if (gettimeofday(&old_time, &tz) < 0) {
CROAK("gettimeofday in apply_step_offset"); LOG_FATAL(LOGF_SysNetBSD, "gettimeofday() failed");
} }
UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
if (settimeofday(&new_time, &tz) < 0) { if (settimeofday(&new_time, &tz) < 0) {
CROAK("settimeofday in apply_step_offset"); LOG_FATAL(LOGF_SysNetBSD, "settimeofday() failed");
} }
UTI_AddDoubleToTimeval(&T0, offset, &T1); UTI_AddDoubleToTimeval(&T0, offset, &T1);
@ -291,15 +291,15 @@ SYS_NetBSD_Initialise(void)
kt = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); kt = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
if (!kt) { if (!kt) {
CROAK("Cannot open kvm\n"); LOG_FATAL(LOGF_SysNetBSD, "Cannot open kvm");
} }
if (kvm_nlist(kt, nl) < 0) { if (kvm_nlist(kt, nl) < 0) {
CROAK("Cannot read kernel symbols\n"); LOG_FATAL(LOGF_SysNetBSD, "Cannot read kernel symbols");
} }
if (kvm_read(kt, nl[0].n_value, (char *)(&kern_tickadj), sizeof(int)) < 0) { if (kvm_read(kt, nl[0].n_value, (char *)(&kern_tickadj), sizeof(int)) < 0) {
CROAK("Cannot read from _tickadj\n"); LOG_FATAL(LOGF_SysNetBSD, "Cannot read from _tickadj");
} }
if (kvm_read(kt, nl[1].n_value, (char *)(&kern_bigadj), sizeof(long)) < 0) { if (kvm_read(kt, nl[1].n_value, (char *)(&kern_bigadj), sizeof(long)) < 0) {

View file

@ -101,17 +101,17 @@ clock_initialise(void)
current_freq = 0.0; current_freq = 0.0;
if (gettimeofday(&T0, &tz) < 0) { if (gettimeofday(&T0, &tz) < 0) {
CROAK("gettimeofday() failed in clock_initialise()"); LOG_FATAL(LOGF_SysSolaris, "gettimeofday() failed");
} }
newadj = GET_ZERO; newadj = GET_ZERO;
if (adjtime(&newadj, &oldadj) < 0) { if (adjtime(&newadj, &oldadj) < 0) {
CROAK("adjtime() failed in clock_initialise"); LOG_FATAL(LOGF_SysSolaris, "adjtime() failed");
} }
if (adjtime(&newadj, &oldadj) < 0) { if (adjtime(&newadj, &oldadj) < 0) {
CROAK("adjtime() failed in clock_initialise"); LOG_FATAL(LOGF_SysSolaris, "adjtime() failed");
} }
return; return;
@ -144,7 +144,7 @@ start_adjust(void)
/* Determine the amount of error built up since the last adjustment */ /* Determine the amount of error built up since the last adjustment */
if (gettimeofday(&T1, &tz) < 0) { if (gettimeofday(&T1, &tz) < 0) {
CROAK("gettimeofday() failed in start_adjust"); LOG_FATAL(LOGF_SysSolaris, "gettimeofday() failed");
} }
UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0);
@ -164,7 +164,7 @@ start_adjust(void)
UTI_DiffTimevalsToDouble(&rounding_error, &exact_newadj, &newadj); UTI_DiffTimevalsToDouble(&rounding_error, &exact_newadj, &newadj);
if (adjtime(&newadj, &oldadj) < 0) { if (adjtime(&newadj, &oldadj) < 0) {
CROAK("adjtime() failed in start_adjust"); LOG_FATAL(LOGF_SysSolaris, "adjtime() failed");
} }
UTI_TimevalToDouble(&oldadj, &old_adjust_remaining); UTI_TimevalToDouble(&oldadj, &old_adjust_remaining);
@ -191,11 +191,11 @@ stop_adjust(void)
zeroadj = GET_ZERO; zeroadj = GET_ZERO;
if (adjtime(&zeroadj, &remadj) < 0) { if (adjtime(&zeroadj, &remadj) < 0) {
CROAK("adjtime() failed in stop_adjust"); LOG_FATAL(LOGF_SysSolaris, "adjtime() failed");
} }
if (gettimeofday(&T1, &tz) < 0) { if (gettimeofday(&T1, &tz) < 0) {
CROAK("gettimeofday() failed in stop_adjust"); LOG_FATAL(LOGF_SysSolaris, "gettimeofday() failed");
} }
UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0);
@ -239,7 +239,7 @@ apply_step_offset(double offset)
stop_adjust(); stop_adjust();
if (gettimeofday(&old_time, &tz) < 0) { if (gettimeofday(&old_time, &tz) < 0) {
CROAK("gettimeofday in apply_step_offset"); LOG_FATAL(LOGF_SysSolaris, "gettimeofday() failed");
} }
UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
@ -260,7 +260,7 @@ apply_step_offset(double offset)
UTI_DiffTimevalsToDouble(&rounding_error, &rounded_new_time, &new_time); UTI_DiffTimevalsToDouble(&rounding_error, &rounded_new_time, &new_time);
if (settimeofday(&new_time, &tz) < 0) { if (settimeofday(&new_time, &tz) < 0) {
CROAK("settimeofday in apply_step_offset"); LOG_FATAL(LOGF_SysSolaris, "settimeofday() failed");
} }
UTI_AddDoubleToTimeval(&T0, offset, &T1); UTI_AddDoubleToTimeval(&T0, offset, &T1);
@ -394,9 +394,7 @@ set_dosynctodr(unsigned long on_off)
kvm_t *kt; kvm_t *kt;
unsigned long read_back; unsigned long read_back;
if (on_off!=1 && on_off!=0) { assert(on_off == 1 || on_off == 0);
CROAK("on_off should be 0 or 1");
}
kt = kvm_open(NULL, NULL, NULL, O_RDWR, NULL); kt = kvm_open(NULL, NULL, NULL, O_RDWR, NULL);
if (!kt) { if (!kt) {
@ -424,9 +422,7 @@ set_dosynctodr(unsigned long on_off)
kvm_close(kt); kvm_close(kt);
if (read_back != on_off) { assert(read_back == on_off);
CROAK("read_back should equal on_off");
}
#if 0 #if 0
LOG(LOGS_INFO, LOGF_SysSolaris, "Set value of dosynctodr to %d", on_off); LOG(LOGS_INFO, LOGF_SysSolaris, "Set value of dosynctodr to %d", on_off);

View file

@ -91,18 +91,18 @@ clock_initialise(void)
current_freq = 0.0; current_freq = 0.0;
if (gettimeofday(&T0, &tz) < 0) { if (gettimeofday(&T0, &tz) < 0) {
CROAK("gettimeofday() failed in clock_initialise()"); LOG_FATAL(LOGF_SysSunOS, "gettimeofday() failed");
} }
newadj.tv_sec = 0; newadj.tv_sec = 0;
newadj.tv_usec = 0; newadj.tv_usec = 0;
if (adjtime(&newadj, &oldadj) < 0) { if (adjtime(&newadj, &oldadj) < 0) {
CROAK("adjtime() failed in clock_initialise"); LOG_FATAL(LOGF_SysSunOS, "adjtime() failed");
} }
if (adjtime(&newadj, &oldadj) < 0) { if (adjtime(&newadj, &oldadj) < 0) {
CROAK("adjtime() failed in clock_initialise"); LOG_FATAL(LOGF_SysSunOS, "adjtime() failed");
} }
return; return;
@ -136,7 +136,7 @@ start_adjust(void)
/* Determine the amount of error built up since the last adjustment */ /* Determine the amount of error built up since the last adjustment */
if (gettimeofday(&T1, &tz) < 0) { if (gettimeofday(&T1, &tz) < 0) {
CROAK("gettimeofday() failed in start_adjust"); LOG_FATAL(LOGF_SysSunOS, "gettimeofday() failed");
} }
UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0);
@ -167,7 +167,7 @@ start_adjust(void)
UTI_DiffTimevalsToDouble(&rounding_error, &newadj, &exact_newadj); UTI_DiffTimevalsToDouble(&rounding_error, &newadj, &exact_newadj);
if (adjtime(&newadj, &oldadj) < 0) { if (adjtime(&newadj, &oldadj) < 0) {
CROAK("adjtime() failed in start_adjust"); LOG_FATAL(LOGF_SysSunOS, "adjtime() failed");
} }
UTI_TimevalToDouble(&oldadj, &old_adjust_remaining); UTI_TimevalToDouble(&oldadj, &old_adjust_remaining);
@ -195,11 +195,11 @@ stop_adjust(void)
zeroadj.tv_usec = 0; zeroadj.tv_usec = 0;
if (adjtime(&zeroadj, &remadj) < 0) { if (adjtime(&zeroadj, &remadj) < 0) {
CROAK("adjtime() failed in stop_adjust"); LOG_FATAL(LOGF_SysSunOS, "adjtime() failed");
} }
if (gettimeofday(&T1, &tz) < 0) { if (gettimeofday(&T1, &tz) < 0) {
CROAK("gettimeofday() failed in stop_adjust"); LOG_FATAL(LOGF_SysSunOS, "gettimeofday() failed");
} }
UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0);
@ -242,13 +242,13 @@ apply_step_offset(double offset)
stop_adjust(); stop_adjust();
if (gettimeofday(&old_time, &tz) < 0) { if (gettimeofday(&old_time, &tz) < 0) {
CROAK("gettimeofday in apply_step_offset"); LOG_FATAL(LOGF_SysSunOS, "gettimeofday() failed");
} }
UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
if (settimeofday(&new_time, &tz) < 0) { if (settimeofday(&new_time, &tz) < 0) {
CROAK("settimeofday in apply_step_offset"); LOG_FATAL(LOGF_SysSunOS, "settimeofday() failed");
} }
UTI_AddDoubleToTimeval(&T0, offset, &T1); UTI_AddDoubleToTimeval(&T0, offset, &T1);
@ -343,9 +343,7 @@ setup_kernel(unsigned long on_off)
unsigned long our_tick = 10000; unsigned long our_tick = 10000;
unsigned long default_tickadj = 625; unsigned long default_tickadj = 625;
if (on_off!=1 && on_off!=0) { assert(on_off == 1 || on_off == 0);
CROAK("on_off should be 0 or 1");
}
kt = kvm_open(NULL, NULL, NULL, O_RDWR, NULL); kt = kvm_open(NULL, NULL, NULL, O_RDWR, NULL);
if (!kt) { if (!kt) {