Exemple #1
0
eEsifError EsifWebStart()
{
	
	if (!EsifWebIsStarted()) {
		esif_ccb_thread_create(&g_webthread, esif_web_worker_thread, NULL);
	}
	return ESIF_OK;
}
Exemple #2
0
void EsifDataLogStart()
{
	/* write header */
	EsifDataLogFire(ESIF_TRUE);

	g_dataLogQuit = ESIF_FALSE;
	esif_ccb_event_init(&g_dataLogQuitEvent);
	esif_ccb_thread_create(&g_dataLogThread, EsifDataLogWorkerThread, NULL);
	g_dataLogActive = ESIF_TRUE;
}
Exemple #3
0
eEsifError EsifEventMgr_Init(void)
{
	eEsifError rc = ESIF_OK;
	UInt8 i;

	ESIF_TRACE_ENTRY_INFO();

	esif_ccb_lock_init(&g_EsifEventMgr.listLock);

	for (i = 0; i < NUM_EVENT_LISTS; i++) {
		g_EsifEventMgr.observerLists[i] = esif_link_list_create();
		if (NULL == g_EsifEventMgr.observerLists[i]) {
			rc = ESIF_E_NO_MEMORY;
			goto exit;
		}
	}

	g_EsifEventMgr.eventQueuePtr = esif_queue_create(ESIF_UF_EVENT_QUEUE_SIZE, ESIF_UF_EVENT_QUEUE_NAME, ESIF_UF_EVENT_QUEUE_TIMEOUT);
	g_EsifEventMgr.garbageList = esif_link_list_create();

	if ((NULL == g_EsifEventMgr.eventQueuePtr) ||
		(NULL == g_EsifEventMgr.garbageList)) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	rc = esif_ccb_thread_create(&g_EsifEventMgr.eventQueueThread, EsifEventMgr_EventQueueThread, NULL);
	if (rc != ESIF_OK) {
		goto exit;
	}
exit:
	if (rc != ESIF_OK) {
		EsifEventMgr_Exit();
	}
	ESIF_TRACE_EXIT_INFO_W_STATUS(rc);
	return rc;
}
Exemple #4
0
static int run_as_server(FILE* input, char* command, int quit_after_command)
{
	char *ptr = NULL;
	char line[MAX_LINE + 1]  = {0};
	char line2[MAX_LINE + 1] = {0};
	g_debuglog = stdin;
	
	/* Prompt */
	#define PROMPT_LEN 64
	char *prompt = NULL;
	char full_prompt[MAX_LINE + 1] = {0};
	char prompt_buf[PROMPT_LEN] = {0};
	ESIF_DATA(data_prompt, ESIF_DATA_STRING, prompt_buf, PROMPT_LEN);

	esif_uf_init("");
	esif_ccb_thread_create(&g_thread, esif_event_worker_thread, "Server");
	sleep(1); 
	cmd_app_subsystem(SUBSYSTEM_ESIF);
 	while (!g_quit) {
                int count = 0;
                // Startup Command?
                if (command) {
                        parse_cmd(command, ESIF_FALSE);
                        if (ESIF_TRUE == quit_after_command) {
                                g_quit = 1;
                                continue;
                        }
                }

                // Get User Input
                g_appMgr.GetPrompt(&g_appMgr, &data_prompt);
                prompt = (esif_string)data_prompt.buf_ptr;

#ifdef ESIF_ATTR_OS_LINUX_HAVE_READLINE
                // Use Readline With History
                sprintf(full_prompt, "%s ", prompt);
                ptr = readline(full_prompt);
                // Add To History NO NUL's
                if (ptr[0] != 0) {
                        add_history(ptr);
                }
                strcpy(line, ptr);
                free(ptr);
#else
                // No History So Sorry
                printf("%s ", prompt);
                if (fgets(line, MAX_LINE, input) == NULL) {
                        break;
                }
                ptr = line;
                while (*ptr != '\0') {
                        if (*ptr == '\r' || *ptr == '\n' || *ptr == '#') {
                                *ptr = '\0';
                        }
                        ptr++;
                }
#endif

    		if (1 == g_repeat || !strncmp(line, "repeat", 6)) {
                        parse_cmd(line, ESIF_FALSE);
                } else {
                        for (count = 0; count < g_repeat; count++) {
                                strcpy(line2, line);
                                parse_cmd(line2, ESIF_FALSE);   /* parse destroys command line */
                                if (kbhit()) {
                                        break;
                                }
                                if (g_soe && g_errorlevel != 0) {
                                        break;
                                }
                                if (g_repeat_delay && count + 1 < g_repeat) {
                                        esif_ccb_sleep(g_repeat_delay / 1000);
                                }
                        }
                        g_repeat = 1;
                }
        }
}
Exemple #5
0
static int run_as_daemon(int start_with_pipe, int start_with_log)
{
	FILE *fp = NULL;
	char *ptr = NULL;
	char line[MAX_LINE + 1] = {0};

	/* 1. Call Fork */ 
	pid_t process_id = fork();

	if (-1 == process_id) {
		return -1;
	} else if (process_id != 0) {
		/* 2. Exit From Parent */
		printf("\nESIF Daemon/Loader (c) 2013-2014 Intel Corp. Ver x1.0.0.1\n");
		printf("Spawn Daemon ESIF Child Process: %d\n", process_id);
		if (ESIF_TRUE == start_with_pipe) {
			printf("Command Input:  %s\n", cmd_in);
		}

		if (ESIF_TRUE == start_with_log) {
			printf("Command Output: %s\n", cmd_out);
		}
		exit(EXIT_SUCCESS);
	}

	/* 3. Call setsid */
	if (-1 == setsid()) {
		return -1;
	}

	/* Child will receive input from FIFO PIPE? */
	if (ESIF_TRUE == start_with_pipe) {
		if (-1 == mkfifo(cmd_in, S_IROTH)) {
		}
	}

	/* 4. Change to known directory.  Performed in main */
	/* 5. Close all file descriptors incuding stdin, stdout, stderr */
	close(STDIN_FILENO); /* stdin */
	close(STDOUT_FILENO); /* stdout */
	close(STDERR_FILENO); /* stderr */

	/* 6. Open file descriptors 0, 1, and 2 and redirect */
	/* stdin */
	if (ESIF_TRUE == start_with_log) {
		open (cmd_out, O_RDWR | O_CREAT | O_TRUNC);
	} else {
       		open ("/dev/null", O_RDWR);
	}

	/* stdout */
	dup(0);
	setvbuf(stdout, NULL, _IONBF, 0);
	/* stderr */
	dup(0);
	setvbuf(stderr, NULL, _IONBF, 0);

	/*
	** Start The Daemon
	*/
	esif_uf_init("");
	esif_ccb_thread_create(&g_thread, esif_event_worker_thread, "Daemon");
	cmd_app_subsystem(SUBSYSTEM_ESIF);

	/* Process Input ? */
	if (ESIF_TRUE == start_with_pipe) {
		while (!g_quit) {
			fp = fopen(cmd_in, "r");
			if (NULL == fp) {
				break;
			}

			/* Grab line from FIFO PIPE */
			if (fgets(line, MAX_LINE, fp) == NULL) {
				/* do nothing */
			}
			ptr = line;
			while (*ptr != '\0') {
				if (*ptr == '\r' || *ptr == '\n' || *ptr == '#') {
					*ptr = '\0';
				}
				ptr++;
			}

			/* Parse and execute the command */
			parse_cmd(line, ESIF_FALSE);
		}

		if (NULL != fp) {
			fclose(fp);
		}
	}
}