t_log* log_create(char* file, char *program_name, bool is_active_console, t_log_level detail) {
	t_log* logger = malloc(sizeof(t_log));

	if (logger == NULL) {
		perror("Cannot create logger");
		return NULL;
	}

	FILE *file_opened = NULL;

	if (file != NULL) {
		file_opened = txt_open_for_append(file);

		if (file_opened == NULL) {
			perror("Cannot create/open log file");
			free(logger);
			return NULL;
		}
	}

	logger->file = file_opened;
	logger->is_active_console = is_active_console;
	logger->detail = detail;
	logger->pid = process_getpid();
	logger->program_name = string_duplicate(program_name);
	return logger;
}
Ejemplo n.º 2
0
int main(){
	char *proxInstrucc;

	dic_Variables = dictionary_create();

	cpu_file_log = txt_open_for_append("./CPU/logs/cpu.log");
	txt_write_in_file(cpu_file_log,"---------------------Nueva ejecucion------------------------------\n");

	txt_write_in_file(cpu_file_log, "Cargo la configuracion desde el archivo\n");

	t_config *unaConfig = config_create("./CPU/cpu_config");
	char *puertoKernel = config_get_string_value(unaConfig, "Puerto_Kernel");
	char *ipKernel = config_get_string_value(unaConfig, "IP_Kernel");
	char *puertoUmv = config_get_string_value(unaConfig, "Puerto_UMV");
	char *ipUmv = config_get_string_value(unaConfig, "IP_UMV");
	imprimo_config(puertoKernel, ipKernel, puertoUmv, ipUmv);

	printf("El PID de este CPU es %d \n", getpid());

	/*conexion con el kernel*/
	handshake_kernel(puertoKernel, ipKernel);

	/*conexion con la umv*/
	handshake_umv(puertoUmv, ipUmv);

	/*maneja si recibe la señal SIGUSR, hay que revisarlo todavia*/
	signal(SIGUSR1, signal_handler);
	signal(SIGINT, signal_handler);

	while(quit_sistema){
		/*recibe un pcb del kernel*/
		recibirUnPcb();
		if(pcb == NULL)
			goto _fin;
		/* le digo a la UMV q cambie el proceso activo */
		cambio_PA(pcb->id);

		traerIndiceEtiquetas();
		/*se crea un diccionario para guardar las variables del contexto*/
		regenerar_dicc_var();

		for (quantum_actual = 0;(quantum_actual < quantum_max) && (!fueFinEjecucion) && (!entre_io) && (!sem_block); quantum_actual++){//aca cicla hasta q el haya terminado los quantums
			printf("Quantum nº%i\n",quantum_actual+1);
			proxInstrucc = solicitarProxSentenciaAUmv();
			analizadorLinea(proxInstrucc, &functions, &kernel_functions);
			free(proxInstrucc);
		}
		if(!fueFinEjecucion){
			salirPorQuantum();
		}
		free(etiquetas);
		free(pcb);
		pcb = NULL;
		cambio_PA(0);//lo cambio a 0 asi la UMV puede comprobar q hay un error
		fueFinEjecucion = 0;
		huboSegFault = 0;
		entre_io = 0;
		sem_block = 0;
	}
	socket_cerrar(socketKernel);
	socket_cerrar(socketUmv);
	_fin:
	return 0;
}