static int do_loop(void) { cdtime_t interval = cf_get_default_interval(); cdtime_t wait_until = cdtime() + interval; while (loop == 0) { #if HAVE_LIBKSTAT update_kstat(); #endif /* Issue all plugins */ plugin_read_all(); cdtime_t now = cdtime(); if (now >= wait_until) { WARNING("Not sleeping because the next interval is " "%.3f seconds in the past!", CDTIME_T_TO_DOUBLE(now - wait_until)); wait_until = now + interval; continue; } struct timespec ts_wait = CDTIME_T_TO_TIMESPEC(wait_until - now); wait_until = wait_until + interval; while ((loop == 0) && (nanosleep(&ts_wait, &ts_wait) != 0)) { if (errno != EINTR) { ERROR("nanosleep failed: %s", STRERRNO); return -1; } } } /* while (loop == 0) */ return 0; } /* int do_loop */
static int do_init(void) { #if HAVE_SETLOCALE if (setlocale(LC_NUMERIC, COLLECTD_LOCALE) == NULL) WARNING("setlocale (\"%s\") failed.", COLLECTD_LOCALE); /* Update the environment, so that libraries that are calling * setlocale(LC_NUMERIC, "") don't accidentally revert these changes. */ unsetenv("LC_ALL"); setenv("LC_NUMERIC", COLLECTD_LOCALE, /* overwrite = */ 1); #endif #if HAVE_LIBKSTAT kc = NULL; update_kstat(); #endif #if HAVE_LIBSTATGRAB if (sg_init( #if HAVE_LIBSTATGRAB_0_90 0 #endif )) { ERROR("sg_init: %s", sg_str_error(sg_get_error())); return -1; } if (sg_drop_privileges()) { ERROR("sg_drop_privileges: %s", sg_str_error(sg_get_error())); return -1; } #endif return plugin_init_all(); } /* int do_init () */
double get_uptime() { kstat_t *ksp; update_kstat(); ksp = kstat_lookup(kstat, "unix", -1, "system_misc"); if (ksp != NULL) { if (kstat_read(kstat, ksp, NULL) >= 0) { kstat_named_t *knp; knp = (kstat_named_t *) kstat_data_lookup(ksp, "boot_time"); if (knp != NULL) { return get_time() - (double) knp->value.ui32; } } } }