388 struct timespec timeout;
392 int initState = FEE_CE_NOTINIT;
396 unsigned int envVal = 0;
398 int restartCount = 0;
410 name = getenv(
"FEE_SERVER_NAME");
413 printf(
"No FEE_SERVER_NAME \n");
422 printf(
"no memory available while trying to create server name!\n");
430 dns = getenv(
"DIM_DNS_NODE");
433 printf(
"No DIM_DNS_NODE specified. \n");
439 if (getenv(
"FEE_LOG_LEVEL")) {
440 sscanf(getenv(
"FEE_LOG_LEVEL"),
"%d", &envVal);
441 if ((envVal < 0) || (envVal > MSG_MAX_VAL)) {
443 printf(
"Environmental variable has invalid Log Level, using default instead.\n");
452 if (getenv(
"FEE_LOGWATCHDOG_TIMEOUT")) {
453 sscanf(getenv(
"FEE_LOGWATCHDOG_TIMEOUT"),
"%d", &envVal);
454 if ((envVal <= 0) || (envVal > MAX_TIMEOUT)) {
456 printf(
"Environmental variable has invalid LogWatchDog Timeout, using default instead.\n");
465 if (getenv(
"FEESERVER_RESTART_COUNT")) {
466 restartCount = atoi(getenv(
"FEESERVER_RESTART_COUNT"));
471 printf(
"\n ** FeeServer version %s ** \n\n", FEESERVER_VERSION);
473 printf(
"Using DIM_DNS_NODE: %s\n", dns);
475 printf(
" -> Benchmark version of FeeServer <- \n");
477 printf(
"Current log level is: %d (MSG_ALARM (%d) is always on)\n",
logLevel, MSG_ALARM);
478 printf(
"Restart Count is: %d; Restart-Env is: %s\n", restartCount,
479 getenv(
"FEESERVER_RESTART_COUNT"));
495 printf(
"Lock init mutex error: %d\n", status);
501 status = pthread_attr_init(&attr);
504 printf(
"Init attribute error: %d\n", status);
509 status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
512 printf(
"Set attribute error: %d\n", status);
520 if (initOk ==
true) {
525 printf(
"Create thread error: %d\n", status);
528 initState = FEE_CE_NOTINIT;
530 # ifdef __DEBUG // for debugging the time amount the watchdog really waits (START) 531 time_t initStartTime =
time(NULL);
535 status = gettimeofday(&now, 0);
536 if ((status != 0) || (restartCount <= 0)) {
539 printf(
"Get time of day error: %d or restartCount <= 0 (%d), using backup solution\n",
540 status, restartCount);
547 printf(
"Unlock mutex error: %d\n", status);
552 usleep((TIMEOUT_INIT_CE_MSEC * 1000));
554 const int sleepFraction = 1;
555 int sleepLoops = TIMEOUT_INIT_CE_SEC / sleepFraction;
562 }
while ( cycles++ < sleepLoops);
569 printf(
"No thread to cancel: %d\n", status);
574 initState = FEE_CE_NOTINIT;
576 printf(
"Timeout in init [sleep]: %d\n", initState);
584 printf(
"Init of CE failed, error: %d\n",
ceInitState);
587 initState = FEE_CE_NOTINIT;
598 timeout.tv_sec = now.tv_sec + TIMEOUT_INIT_CE_SEC;
599 timeout.tv_nsec = (now.tv_usec * 1000) +
600 (TIMEOUT_INIT_CE_MSEC * 1000000);
611 printf(
"No thread to cancel: %d\n", status);
616 initState = FEE_CE_NOTINIT;
618 printf(
"Timeout in init [timed_wait]: %d\n", initState);
626 printf(
"Init of CE failed, error: %d\n",
ceInitState);
629 initState = FEE_CE_NOTINIT;
640 # ifdef __DEBUG // for debugging the time amout the watchdog waits (STOP) 641 time_t initStopTime =
time(NULL);
642 if (initState != FEE_OK) {
643 printf(
"Watchdog: CE init tread\n started %s",
644 ctime(&initStartTime));
645 printf(
" killed %s\n", ctime(&initStopTime));
650 printf(
"Watchdog: CE init tread\n started %s",
651 ctime(&initStartTime));
652 printf(
" finished %s\n", ctime(&initStopTime));
660 status = pthread_attr_destroy(&attr);
663 printf(
"Destroy attribute error: %d\n", status);
672 if (initState != FEE_OK) {
675 printf(
"Init failed, unpublishing item list\n");
686 nRet =
start(initState);
692 printf(
"Unlock mutex error: %d\n", status);
695 if (nRet == FEE_OK) {
700 if (nRet != FEE_OK) {
702 printf(
"unable to start DIM server, exiting.\n");
708 printf(
"DIM Server successfully started, ready to accept commands.\n");
714 printf(
"DEBUG - Init-State: %d, CE-State: %d, Restart-Env: %s, RestartCount: %d.\n",
715 initState,
ceInitState, getenv(
"FEESERVER_RESTART_COUNT"), restartCount);
721 if ((initState != FEE_OK) && (getenv(
"FEESERVER_RESTART_COUNT")) &&
722 (restartCount > 0)) {
724 "Triggering a FeeServer restart to give CE init another try. Restart count (backward counter): %d ",
728 printf(
"Triggering a FeeServer restart for another CE init try (backward count: %d).\n",
static bool ceReadySignaled
void dim_dummy_exit_handler(int *bufp)
void fee_exit_handler(unsigned int state)
void threadInitializeCE()
static int serverNameLength
void dis_add_error_handler(void(*user_routine)())
unsigned int dtq_sleep(int secs)
void createLogMessage(unsigned int type, char *description, char *origin)
void unpublishCharItemList()
void dim_error_msg_handler(int severity, int error_code, char *msg)
static unsigned int logWatchDogTimeout
static unsigned int logLevel
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
static pthread_cond_t init_cond
static pthread_mutex_t wait_init_mut
void unpublishIntItemList()
static pthread_t thread_init
void triggerRestart(int exitVal)
#define dis_add_exit_handler
sprintf(name1,"NewService%d", i)