diff --git a/cmdmon.c b/cmdmon.c index 2131681..b28d438 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -261,16 +261,10 @@ prepare_socket(int family) void CAM_Initialise(void) { - - if (initialised) { - CROAK("Shouldn't be initialised"); - } - + assert(!initialised); initialised = 1; - if ((sizeof(permissions)/sizeof(permissions[0])) != N_REQUEST_TYPES) { - CROAK("Permissions table size wrong"); - } + assert(sizeof (permissions) / sizeof (permissions[0]) == N_REQUEST_TYPES); 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); break; case NSR_NoSuchSource: - CROAK("Impossible"); + assert(0); break; } } @@ -1289,7 +1283,7 @@ handle_add_peer(CMD_Request *rx_message, CMD_Reply *tx_message) tx_message->status = htons(STT_INVALIDAF); break; case NSR_NoSuchSource: - CROAK("Impossible"); + assert(0); break; } } @@ -1317,7 +1311,7 @@ handle_del_source(CMD_Request *rx_message, CMD_Reply *tx_message) case NSR_TooManySources: case NSR_AlreadyInUse: case NSR_InvalidAF: - CROAK("Impossible"); + assert(0); break; } } @@ -1508,7 +1502,7 @@ handle_subnets_accessed(CMD_Request *rx_message, CMD_Reply *tx_message) tx_message->status = htons(STT_INACTIVE); return; default: - CROAK("Impossible"); + assert(0); break; } } @@ -1563,7 +1557,7 @@ handle_client_accesses(CMD_Request *rx_message, CMD_Reply *tx_message) tx_message->status = htons(STT_INACTIVE); return; default: - CROAK("Impossible"); + assert(0); break; } } @@ -1615,7 +1609,7 @@ handle_client_accesses_by_index(CMD_Request *rx_message, CMD_Reply *tx_message) tx_message->status = htons(STT_INACTIVE); return; default: - CROAK("Impossible"); + assert(0); break; } } @@ -2011,7 +2005,7 @@ read_from_cmd_socket(void *anything) allowed = 1; break; default: - CROAK("Impossible"); + assert(0); } if (allowed) { diff --git a/local.c b/local.c index ad0aa34..f0ca964 100644 --- a/local.c +++ b/local.c @@ -123,9 +123,9 @@ calculate_sys_precision(void) iters++; } } 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_log = 0; while (best_dusec < 500000) { @@ -196,7 +196,7 @@ LCL_AddParameterChangeHandler(LCL_ParameterChangeHandler handler, void *anything /* Check that the handler is not already registered */ for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) { 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) { - CROAK("did not find a matching handler"); - } + assert(ok); /* Unlink entry from the list */ ptr->next->prev = ptr->prev; @@ -257,7 +255,7 @@ LCL_AddDispersionNotifyHandler(LCL_DispersionNotifyHandler handler, void *anythi /* Check that the handler is not already registered */ for (ptr = dispersion_notify_list.next; ptr != &dispersion_notify_list; ptr = ptr->next) { 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) { - CROAK("no matching handler found"); - } + assert(ok); /* Unlink entry from the list */ ptr->next->prev = ptr->prev; @@ -317,8 +313,8 @@ LCL_ReadRawTime(struct timeval *result) { struct timezone tz; - if (!(gettimeofday(result, &tz) >= 0)) { - CROAK("Could not get time of day"); + if (gettimeofday(result, &tz) < 0) { + LOG_FATAL(LOGF_Local, "gettimeofday() failed"); } } diff --git a/logging.c b/logging.c index a2f471e..15f1b6a 100644 --- a/logging.c +++ b/logging.c @@ -249,22 +249,6 @@ LOG_RateLimited(void) 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 diff --git a/logging.h b/logging.h index c309c66..37ecc0e 100644 --- a/logging.h +++ b/logging.h @@ -63,6 +63,7 @@ typedef enum { LOGF_Regress, LOGF_Sys, LOGF_SysLinux, + LOGF_SysNetBSD, LOGF_SysSolaris, LOGF_SysSunOS, LOGF_SysWinnt, @@ -100,15 +101,6 @@ extern int LOG_RateLimited(void); #define LOG_FATAL LOG_Position(__FILE__, __LINE__, ""); LOG_Fatal_Function #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 */ typedef int LOG_FileID; diff --git a/ntp_core.c b/ntp_core.c index 1fe9771..952308c 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -1210,7 +1210,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins break; default: - CROAK("Impossible"); + assert(0); break; } @@ -1224,7 +1224,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins break; default: - CROAK("Impossible"); + assert(0); break; } @@ -1786,7 +1786,7 @@ NCR_InitiateSampleBurst(NCR_Instance inst, int n_good_samples, int n_total_sampl default: - CROAK("Impossible"); + assert(0); break; } } @@ -1808,7 +1808,7 @@ NCR_ReportSource(NCR_Instance inst, RPT_SourceReport *report, struct timeval *no report->mode = RPT_NTP_PEER; break; default: - CROAK("Impossible"); + assert(0); } return; @@ -1872,7 +1872,7 @@ NCR_IncrementActivityCounters(NCR_Instance inst, int *online, int *offline, ++*offline; break; default: - CROAK("Impossible"); + assert(0); break; } } diff --git a/regress.c b/regress.c index 372e462..9f85090 100644 --- a/regress.c +++ b/regress.c @@ -69,9 +69,7 @@ RGR_WeightedRegression double u, ui, aa; int i; - if (n<3) { - CROAK("Insufficient points"); - } + assert(n >= 3); W = U = 0; for (i=0; i= 0); /* If this bit of the array is already sorted, simple! */ if (flags[index]) { @@ -404,8 +400,6 @@ find_ordered_entry_with_flags(double *x, int n, int index, int *flags) v = r - 1; } else if (index > r) { u = l; - } else { - CROAK("Impossible"); } } } while (1); @@ -619,7 +613,7 @@ RGR_FindBestRobustRegression bhi = bmid; rhi = rmid; } else { - CROAK("Impossible"); + assert(0); } } while ((bhi - blo) > tol); diff --git a/rtc_linux.c b/rtc_linux.c index 19b72f8..a88c331 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -193,12 +193,7 @@ discard_samples(int new_first) { int n_to_save; - if (!(new_first < n_samples)) { - CROAK("new_first should be < n_samples"); - } - if (!(new_first >= 0)) { - CROAK("new_first should be non-negative"); - } + assert(new_first >= 0 && new_first < n_samples); n_to_save = n_samples - new_first; @@ -802,7 +797,7 @@ process_reading(time_t rtc_time, struct timeval *system_time) } break; default: - CROAK("Impossible"); + assert(0); break; } @@ -937,7 +932,7 @@ turn_off_interrupt: break; default: - CROAK("Impossible"); + assert(0); break; } diff --git a/sched.c b/sched.c index 908f50b..dacc9d2 100644 --- a/sched.c +++ b/sched.c @@ -164,16 +164,12 @@ SCH_AddInputFileHandler (int fd, SCH_FileHandler handler, SCH_ArbitraryArgument arg) { - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); /* Don't want to allow the same fd to register a handler more than once without deleting a previous association - this suggests a bug somewhere else in the program. */ - if (FD_ISSET(fd, &read_fds)) { - CROAK("File handler already registered"); - } + assert(!FD_ISSET(fd, &read_fds)); ++n_read_fds; @@ -197,14 +193,10 @@ SCH_RemoveInputFileHandler(int fd) { int fds_left, fd_to_check; - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); /* Check that a handler was registered for the fd in question */ - if (!FD_ISSET(fd, &read_fds)) { - CROAK("File handler not registered"); - } + assert(FD_ISSET(fd, &read_fds)); --n_read_fds; @@ -278,9 +270,7 @@ SCH_AddTimeout(struct timeval *tv, SCH_TimeoutHandler handler, SCH_ArbitraryArgu TimerQueueEntry *new_tqe; TimerQueueEntry *ptr; - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); new_tqe = allocate_tqe(); @@ -321,9 +311,7 @@ SCH_AddTimeoutByDelay(double delay, SCH_TimeoutHandler handler, SCH_ArbitraryArg { struct timeval now, then; - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); LCL_ReadRawTime(&now); UTI_AddDoubleToTimeval(&now, delay, &then); @@ -344,9 +332,7 @@ SCH_AddTimeoutInClass(double min_delay, double separation, double diff; double new_min_delay; - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); LCL_ReadRawTime(&now); new_min_delay = min_delay; @@ -402,9 +388,7 @@ SCH_RemoveTimeout(SCH_TimeoutID id) TimerQueueEntry *ptr; int ok; - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); ok = 0; @@ -527,9 +511,7 @@ SCH_MainLoop(void) struct timeval tv, *ptv; struct timeval now; - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); while (!need_to_exit) { @@ -565,8 +547,7 @@ SCH_MainLoop(void) status = select(one_highest_fd, &rd, NULL, NULL, ptv); if (status < 0) { - if (!need_to_exit) - CROAK("Status < 0 after select"); + assert(need_to_exit); } else if (status > 0) { /* A file descriptor is ready to read */ @@ -574,15 +555,11 @@ SCH_MainLoop(void) dispatch_filehandlers(status, &rd); } else { - if (status != 0) { - CROAK("Unexpected value from select"); - } + assert(status == 0); /* No descriptors readable, timeout must have elapsed. Therefore, tv must be non-null */ - if (!ptv) { - CROAK("No descriptors or timeout?"); - } + assert(ptv); /* There's nothing to do here, since the timeouts will be dispatched at the top of the next loop @@ -600,9 +577,7 @@ SCH_MainLoop(void) void SCH_QuitProgram(void) { - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); need_to_exit = 1; } diff --git a/sources.c b/sources.c index 094e21c..98e4dc7 100644 --- a/sources.c +++ b/sources.c @@ -169,9 +169,7 @@ SRC_Instance SRC_CreateNewInstance(unsigned long ref_id, SRC_Type type, IPAddr * { SRC_Instance result; - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); result = MallocNew(struct SRC_Instance_Record); result->stats = SST_CreateInstance(ref_id, addr); @@ -214,9 +212,7 @@ void SRC_DestroyInstance(SRC_Instance instance) { int dead_index, i; - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); if (instance->index == selected_source_index) { instance->reachable = 0; @@ -251,9 +247,7 @@ void SRC_DestroyInstance(SRC_Instance instance) void SRC_GetFrequencyRange(SRC_Instance instance, double *lo, double *hi) { - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); SST_GetFrequencyRange(instance->stats, lo, hi); return; @@ -284,9 +278,7 @@ void SRC_AccumulateSample NTP_Leap leap_status) { - if (!initialised) { - CROAK("Should be initialised"); - } + assert(initialised); inst->leap_status = leap_status; @@ -372,7 +364,7 @@ source_to_string(SRC_Instance inst) case SRC_REFCLOCK: return UTI_RefidToString(inst->ref_id); default: - CROAK("Unknown source type"); + assert(0); } return NULL; } @@ -530,7 +522,7 @@ SRC_SelectSource(unsigned long match_addr) break; case CENTRE: - CROAK("CENTRE cannot occur"); + assert(0); break; case HIGH: diff --git a/sys_linux.c b/sys_linux.c index 8567df9..fe326f1 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -222,7 +222,7 @@ update_slow_slew_error(int offset) return; if (gettimeofday(&now, &tz) < 0) { - CROAK("gettimeofday() failed"); + LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed"); } 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 (gettimeofday(&now, &tz) < 0) { - CROAK("gettimeofday() failed"); + LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed"); } } @@ -357,17 +357,15 @@ stop_fast_slew(void) double slew_duration; /* Should never get here unless this is true */ - if (!fast_slewing) { - CROAK("Should be fast slewing"); - } + assert(fast_slewing); /* Now set the thing off */ if (gettimeofday(&T1, &tz) < 0) { - CROAK("gettimeofday() failed in stop_fast_slew"); + LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed"); } if (TMX_SetTick(current_tick) < 0) { - CROAK("adjtimex() failed in stop_fast_slew"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } fast_slewing = 0; @@ -401,7 +399,7 @@ adjust_fast_slew(double old_tick, double old_delta_tick) assert(fast_slewing); 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); @@ -437,9 +435,7 @@ initiate_slew(void) struct timezone tz; /* Don't want to get here if we already have an adjust on the go! */ - if (fast_slewing) { - CROAK("Should not be fast slewing"); - } + assert(!fast_slewing); if (offset_register == 0.0) { return; @@ -449,21 +445,21 @@ initiate_slew(void) if (slow_slewing) { 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; slow_slewing = 0; update_slow_slew_error(0); } else if (nano_slewing) { if (TMX_GetPLLOffsetLeft(&offset) < 0) { - CROAK("adjtimex() failed in accrue_offset"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } offset_register -= (double) offset / 1.0e9; update_nano_slew_error(offset, 0); offset = 0; if (TMX_ApplyPLLOffset(offset) < 0) { - CROAK("adjtimex() failed in accrue_offset"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } nano_slewing = 0; update_nano_slew_error(offset, 1); @@ -474,7 +470,7 @@ initiate_slew(void) offset = 1.0e9 * -offset_register; if (TMX_ApplyPLLOffset(offset) < 0) { - CROAK("adjtimex() failed in accrue_offset"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } offset_register = 0.0; nano_slewing = 1; @@ -487,7 +483,7 @@ initiate_slew(void) if (offset != 0) { if (TMX_ApplyOffset(&offset) < 0) { - CROAK("adjtimex() failed in initiate_slew"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } slow_slewing = 1; update_slow_slew_error(offset); @@ -524,13 +520,11 @@ initiate_slew(void) /* Now set the thing off */ if (gettimeofday(&T0, &tz) < 0) { - CROAK("gettimeofday() failed in initiate_slew"); + LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed"); } if (TMX_SetTick(slewing_tick) < 0) { - LOG(LOGS_INFO, LOGF_SysLinux, "c_t=%ld ta=%ld sl_t=%ld dtt=%e", - current_tick, tick_adjust, slewing_tick, delta_total_tick); - CROAK("adjtimex() failed to start big slew"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } /* 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) { - CROAK("gettimeofday in apply_step_offset"); + LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed"); } UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); if (settimeofday(&new_time, &tz) < 0) { - CROAK("settimeofday in apply_step_offset"); + LOG_FATAL(LOGF_SysLinux, "settimeofday() failed"); } 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); @@ -727,7 +721,7 @@ read_frequency(void) double freq_term; 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 @@ -773,22 +767,22 @@ get_offset_correction(struct timeval *raw, switch (have_readonly_adjtime) { case 2: if (TMX_GetOffsetLeft(&offset) < 0) { - CROAK("adjtimex() failed in get_offset_correction"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } break; case 0: toffset = 0; if (TMX_ApplyOffset(&toffset) < 0) { - CROAK("adjtimex() failed in get_offset_correction"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } offset = toffset; if (TMX_ApplyOffset(&toffset) < 0) { - CROAK("adjtimex() failed in get_offset_correction"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } break; case 1: if (TMX_GetOffsetLeftOld(&offset) < 0) { - CROAK("adjtimex() failed in get_offset_correction"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } break; default: @@ -805,7 +799,7 @@ get_offset_correction(struct timeval *raw, noffset = 0; } else { if (TMX_GetPLLOffsetLeft(&noffset) < 0) { - CROAK("adjtimex() failed in get_offset_correction"); + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } if (noffset == 0) { nano_slewing = 0; @@ -1091,7 +1085,7 @@ SYS_Linux_Initialise(void) 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)) { diff --git a/sys_netbsd.c b/sys_netbsd.c index 8c0cacc..f998bdf 100644 --- a/sys_netbsd.c +++ b/sys_netbsd.c @@ -85,14 +85,14 @@ clock_initialise(void) current_freq = 0.0; if (gettimeofday(&T0, &tz) < 0) { - CROAK("gettimeofday() failed in clock_initialise()"); + LOG_FATAL(LOGF_SysNetBSD, "gettimeofday() failed"); } newadj.tv_sec = 0; newadj.tv_usec = 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 */ if (gettimeofday(&T1, &tz) < 0) { - CROAK("gettimeofday() failed in start_adjust"); + LOG_FATAL(LOGF_SysNetBSD, "gettimeofday() failed"); } UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); @@ -151,7 +151,7 @@ start_adjust(void) UTI_DiffTimevalsToDouble(&rounding_error, &newadj, &exact_newadj); if (adjtime(&newadj, &oldadj) < 0) { - CROAK("adjtime() failed in start_adjust"); + LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed"); } UTI_TimevalToDouble(&oldadj, &old_adjust_remaining); @@ -178,11 +178,11 @@ stop_adjust(void) zeroadj.tv_usec = 0; if (adjtime(&zeroadj, &remadj) < 0) { - CROAK("adjtime() failed in stop_adjust"); + LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed"); } if (gettimeofday(&T1, &tz) < 0) { - CROAK("gettimeofday() failed in stop_adjust"); + LOG_FATAL(LOGF_SysNetBSD, "gettimeofday() failed"); } UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); @@ -226,13 +226,13 @@ apply_step_offset(double offset) stop_adjust(); 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); if (settimeofday(&new_time, &tz) < 0) { - CROAK("settimeofday in apply_step_offset"); + LOG_FATAL(LOGF_SysNetBSD, "settimeofday() failed"); } UTI_AddDoubleToTimeval(&T0, offset, &T1); @@ -291,15 +291,15 @@ SYS_NetBSD_Initialise(void) kt = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); if (!kt) { - CROAK("Cannot open kvm\n"); + LOG_FATAL(LOGF_SysNetBSD, "Cannot open kvm"); } 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) { - 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) { diff --git a/sys_solaris.c b/sys_solaris.c index f75485a..44ea0b7 100644 --- a/sys_solaris.c +++ b/sys_solaris.c @@ -101,17 +101,17 @@ clock_initialise(void) current_freq = 0.0; if (gettimeofday(&T0, &tz) < 0) { - CROAK("gettimeofday() failed in clock_initialise()"); + LOG_FATAL(LOGF_SysSolaris, "gettimeofday() failed"); } newadj = GET_ZERO; if (adjtime(&newadj, &oldadj) < 0) { - CROAK("adjtime() failed in clock_initialise"); + LOG_FATAL(LOGF_SysSolaris, "adjtime() failed"); } if (adjtime(&newadj, &oldadj) < 0) { - CROAK("adjtime() failed in clock_initialise"); + LOG_FATAL(LOGF_SysSolaris, "adjtime() failed"); } return; @@ -144,7 +144,7 @@ start_adjust(void) /* Determine the amount of error built up since the last adjustment */ if (gettimeofday(&T1, &tz) < 0) { - CROAK("gettimeofday() failed in start_adjust"); + LOG_FATAL(LOGF_SysSolaris, "gettimeofday() failed"); } UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); @@ -164,7 +164,7 @@ start_adjust(void) UTI_DiffTimevalsToDouble(&rounding_error, &exact_newadj, &newadj); if (adjtime(&newadj, &oldadj) < 0) { - CROAK("adjtime() failed in start_adjust"); + LOG_FATAL(LOGF_SysSolaris, "adjtime() failed"); } UTI_TimevalToDouble(&oldadj, &old_adjust_remaining); @@ -191,11 +191,11 @@ stop_adjust(void) zeroadj = GET_ZERO; if (adjtime(&zeroadj, &remadj) < 0) { - CROAK("adjtime() failed in stop_adjust"); + LOG_FATAL(LOGF_SysSolaris, "adjtime() failed"); } if (gettimeofday(&T1, &tz) < 0) { - CROAK("gettimeofday() failed in stop_adjust"); + LOG_FATAL(LOGF_SysSolaris, "gettimeofday() failed"); } UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); @@ -239,7 +239,7 @@ apply_step_offset(double offset) stop_adjust(); 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); @@ -260,7 +260,7 @@ apply_step_offset(double offset) UTI_DiffTimevalsToDouble(&rounding_error, &rounded_new_time, &new_time); if (settimeofday(&new_time, &tz) < 0) { - CROAK("settimeofday in apply_step_offset"); + LOG_FATAL(LOGF_SysSolaris, "settimeofday() failed"); } UTI_AddDoubleToTimeval(&T0, offset, &T1); @@ -394,9 +394,7 @@ set_dosynctodr(unsigned long on_off) kvm_t *kt; unsigned long read_back; - if (on_off!=1 && on_off!=0) { - CROAK("on_off should be 0 or 1"); - } + assert(on_off == 1 || on_off == 0); kt = kvm_open(NULL, NULL, NULL, O_RDWR, NULL); if (!kt) { @@ -424,9 +422,7 @@ set_dosynctodr(unsigned long on_off) kvm_close(kt); - if (read_back != on_off) { - CROAK("read_back should equal on_off"); - } + assert(read_back == on_off); #if 0 LOG(LOGS_INFO, LOGF_SysSolaris, "Set value of dosynctodr to %d", on_off); diff --git a/sys_sunos.c b/sys_sunos.c index 6540fa6..0898af8 100644 --- a/sys_sunos.c +++ b/sys_sunos.c @@ -91,18 +91,18 @@ clock_initialise(void) current_freq = 0.0; if (gettimeofday(&T0, &tz) < 0) { - CROAK("gettimeofday() failed in clock_initialise()"); + LOG_FATAL(LOGF_SysSunOS, "gettimeofday() failed"); } newadj.tv_sec = 0; newadj.tv_usec = 0; if (adjtime(&newadj, &oldadj) < 0) { - CROAK("adjtime() failed in clock_initialise"); + LOG_FATAL(LOGF_SysSunOS, "adjtime() failed"); } if (adjtime(&newadj, &oldadj) < 0) { - CROAK("adjtime() failed in clock_initialise"); + LOG_FATAL(LOGF_SysSunOS, "adjtime() failed"); } return; @@ -136,7 +136,7 @@ start_adjust(void) /* Determine the amount of error built up since the last adjustment */ if (gettimeofday(&T1, &tz) < 0) { - CROAK("gettimeofday() failed in start_adjust"); + LOG_FATAL(LOGF_SysSunOS, "gettimeofday() failed"); } UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); @@ -167,7 +167,7 @@ start_adjust(void) UTI_DiffTimevalsToDouble(&rounding_error, &newadj, &exact_newadj); if (adjtime(&newadj, &oldadj) < 0) { - CROAK("adjtime() failed in start_adjust"); + LOG_FATAL(LOGF_SysSunOS, "adjtime() failed"); } UTI_TimevalToDouble(&oldadj, &old_adjust_remaining); @@ -195,11 +195,11 @@ stop_adjust(void) zeroadj.tv_usec = 0; if (adjtime(&zeroadj, &remadj) < 0) { - CROAK("adjtime() failed in stop_adjust"); + LOG_FATAL(LOGF_SysSunOS, "adjtime() failed"); } if (gettimeofday(&T1, &tz) < 0) { - CROAK("gettimeofday() failed in stop_adjust"); + LOG_FATAL(LOGF_SysSunOS, "gettimeofday() failed"); } UTI_DiffTimevalsToDouble(&elapsed, &T1, &T0); @@ -242,13 +242,13 @@ apply_step_offset(double offset) stop_adjust(); 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); if (settimeofday(&new_time, &tz) < 0) { - CROAK("settimeofday in apply_step_offset"); + LOG_FATAL(LOGF_SysSunOS, "settimeofday() failed"); } UTI_AddDoubleToTimeval(&T0, offset, &T1); @@ -343,9 +343,7 @@ setup_kernel(unsigned long on_off) unsigned long our_tick = 10000; unsigned long default_tickadj = 625; - if (on_off!=1 && on_off!=0) { - CROAK("on_off should be 0 or 1"); - } + assert(on_off == 1 || on_off == 0); kt = kvm_open(NULL, NULL, NULL, O_RDWR, NULL); if (!kt) {