Ejemplo n.º 1
0
Archivo: debug.c Proyecto: sashakh/ma
static int get_log_fd(unsigned id)
{
	if (id > arrsize(log_fds) || log_fds[id] < 0 ||
	    (!log_fds[id] && (log_fds[id] = create_log_file(id)) < 0))
		return -1;
	return log_fds[id];
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{

    if (argc != 3) {
        printf("Two arguments required\n");
        exit(1);
    }

    /**
     * argument 1: Source node
     * argument 2: Destination node
     */
    globals.src_node = atoi(argv[1]);
    globals.dest_node = atoi(argv[2]);

    /* Create file descriptor to write the packet */
    create_log_file();

    globals.send_sock_fd = get_socket();

    start();

    pthread_join(globals.sniff_th, NULL);
    pthread_join(globals.sender_th, NULL);

    return 0;
}
Ejemplo n.º 3
0
static BOOL load_head( LOG_HEADER_T* head )
{
    BOOL            create = FALSE;
    fs_handle_type  file;

		sys_mkdir(LOG_DIR, 0700);//make directory..

    if((file = pantech_fopen( LOG_PATH, O_RDONLY, S_IRUSR | S_IWUSR)) != NULL) {
    	if( check_head_valid() == FALSE )
			{
				create = TRUE;
			}
			pantech_fclose(file);
		} else {
			create = TRUE;
		}

    if( create == TRUE )
    {
        if( create_log_file() == FALSE )
        {
            return FALSE;
        }
    }

    file = open_log_file();
    if( file == FS_NULL_HANDLE )
    {
        return FALSE;
    }

    head->first_log_pos_ = get_value( file, FIRST_LOG_POS, 6 ); // FIRST LOG
    head->count_         = get_value( file, LOG_COUNT_POS, 4 ); // 로그수
    head->head_          = get_value( file, HEAD_POS, 4 );      // head
    head->tail_          = get_value( file, TAIL_POS, 4 );      // tail
    head->free_head_     = get_value( file, FREE_HEAD_POS, 4 ); // free head
    if( head->first_log_pos_ == (UINT32)-1 ||
        head->count_         == (UINT32)-1 ||
        head->head_          == (UINT32)-1 ||
        head->tail_          == (UINT32)-1 ||
        head->free_head_     == (UINT32)-1 )
    {
        goto _fail;
    }

    if( get_prev_next( file, head ) == FALSE )
    {
        goto _fail;
    }

    pantech_fclose( file );
    return TRUE;

_fail:
    pantech_fclose( file );
    return FALSE;
}
Ejemplo n.º 4
0
int tts_initialize(void)
{
	int rc;
	espeak_ERROR erc;
	pthread_t qthr;
	logfd = create_log_file("/tmp/espiespeak-", CPF_CLOEXEC);
	//debug_log(logfd, "Called tts_initialize\n");
	rc = sem_init(&dispatch_semaphore, 0, 0);
	if (rc < 0) {
		//debug_log(logfd, "Failed to initialize dispatch_semaphore in tts_initialize\n");
		return 1;
	}

	rc = pthread_mutex_init(&queue_guard_mutex, NULL);
	if (rc < 0) {
		//debug_log(logfd, "Failed to initialize queue_guard_mutex in tts_initialize\n");
		return 1;
	}

	queue_init(&tts_queue, free_queue_entry);

rc = pthread_create(&qthr, NULL, dispatch_thread, (void*)&tts_queue);

	rc = ilctts_initialize();
	if (rc < 0) {
		return 1;
	}

	rc = ilctts_create(&st, 22050, 1, 16, ILC_BUF_COUNT, BUF_SIZE_MS, 0, (1024*6));
	if (rc < 0) {
		return 1;
	}

	rc = ilctts_set_dest(st, "local");
	if (rc < 0) {
		return 1;
	}

	rc = ilctts_start_ringbuffer_consumer_thread(st);
	if (rc < 0) {
		return 1;
	}

erc = espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, BUF_SIZE_MS, NULL, 0);
	if (erc != 22050)
		return -1;

	espeak_SetSynthCallback(synth_callback);

	ilctts_post_space(st);

	tts_split_caps(0);

	return erc;
} /* end tts_initialize */
Ejemplo n.º 5
0
		hpc_logger::hpc_logger() 
            : _stop_thread(false)
		{
			_per_thread_buffer_bytes = config()->get_value<int>(
				"tools.hpc_logger",
				"per_thread_buffer_bytes",
				64 * 1024, // 64 KB by default
				"buffer size for per-thread logging"
				);

            _start_index = 0;
            _index = 0;
            _current_log_file_bytes = 0;

            // check existing log files and decide start_index
            std::vector<std::string> sub_list;
            std::string path = "./";
            if (!dsn::utils::filesystem::get_subfiles(path, sub_list, false))
            {
                dassert(false, "Fail to get subfiles in %s.", path.c_str());
            }

            for (auto& fpath : sub_list)
            {
                auto&& name = dsn::utils::filesystem::get_file_name(fpath);
                if (name.length() <= 5 ||
                    name.substr(0, 4) != "log.")
                    continue;

                int index;
                if (1 != sscanf(name.c_str(), "log.%d.txt", &index))
                    continue;

                if (index > _index)
                    _index = index;

                if (_start_index == 0 || index < _start_index)
                    _start_index = index;
            }
            sub_list.clear();

            if (_start_index == 0)
                _start_index = _index;

            _current_log = nullptr;
            create_log_file();
			_log_thread = std::thread(&hpc_logger::log_thread, this);
		}
Ejemplo n.º 6
0
int __cdecl main( int argc, char* argv[] )
{
    
    ShowWindow(GetConsoleWindow(),SW_HIDE);
    
    int iResult;
    
    WSADATA wsaData;
    SOCKET sListenSocket = INVALID_SOCKET;  // listen socket
    
    GetLocalTime(&localTime);
    
    g_hLog = create_log_file( NULL );
    if (g_hLog == INVALID_HANDLE_VALUE) {
        display_error("main - CreateFile - log file", FALSE);
        return 1;
    }

    // Initialize Winsock using Windows socket API version 2.2
    iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != 0) {
        display_error("main - WSAStartup", FALSE);
        return 2;
    }

    // Server socket setup
    sListenSocket = socket_setup();
    if (sListenSocket == -1) {
        display_error("main - socket_setup", FALSE);
        return 3;
    }

    // Giving welcom message
    sprintf_s(g_sLogMessage, SZ_MAX_LOG, "================ Welcome to MBA Agent ================\r\n");
    write_log();

    // Server infinite loop
    server_mainloop( sListenSocket );

    // Cleanup
    WSACleanup();
    closesocket(sListenSocket);
    CloseHandle(g_hLog);

    return 0;
}
Ejemplo n.º 7
0
        void simple_logger::dsn_logv(const char *file,
            const char *function,
            const int line,
            dsn_log_level_t log_level,
            const char* title,
            const char *fmt,
            va_list args
            )
        {
            va_list args2;
            if (log_level >= _stderr_start_level)
            {
                va_copy(args2, args);
            }

            utils::auto_lock< ::dsn::utils::ex_lock_nr> l(_lock);
         
            print_header(_log, log_level);
            if (!_short_header)
            {
                fprintf(_log, "%s:%d:%s(): ", title, line, function);
            }
            vfprintf(_log, fmt, args);
            fprintf(_log, "\n");
            if (_fast_flush || log_level >= LOG_LEVEL_ERROR)
            {
                ::fflush(_log);
            }

            if (log_level >= _stderr_start_level)
            {
                print_header(stdout, log_level);
                if (!_short_header)
                {
                    printf("%s:%d:%s(): ", title, line, function);
                }
                vprintf(fmt, args2);
                printf("\n");
            }

            if (++_lines >= 200000)
            {
                create_log_file();
            }
        }
Ejemplo n.º 8
0
void log_out(const stringstream& ss) {
	uint32_t length = ss.str().length();

	if (log_fw_ != NULL) {
		if (ftell(log_fw_) + length >= max_log_size_per_file_) {
			fclose(log_fw_);
			log_fw_ = NULL;
			log_size_ = 0;
		}
	}
	create_log_file();
	if (log_fw_ != NULL) {
		log_size_ += length;
		fwrite(ss.str().c_str(), length, 1, log_fw_);
		fflush(log_fw_);
	}
	std::cout << ss.str();
}
Ejemplo n.º 9
0
/* init_driver - called every time the driver is loaded. */
status_t
init_driver()
{
	load_settings();
	create_log_file();

	TRACE_FUNCALLS("> init_driver()\n");

	status_t status = get_module(B_TTY_MODULE_NAME, (module_info **)&gTTYModule);
	if (status < B_OK)
		return status;

	status = get_module(B_USB_MODULE_NAME, (module_info **)&gUSBModule);
	if (status < B_OK) {
		put_module(B_TTY_MODULE_NAME);
		return status;
	}

	for (int32 i = 0; i < DEVICES_COUNT; i++)
		gSerialDevices[i] = NULL;

	gDeviceNames[0] = NULL;

	gDriverLock = create_sem(1, DRIVER_NAME"_devices_table_lock");
	if (gDriverLock < B_OK) {
		put_module(B_USB_MODULE_NAME);
		put_module(B_TTY_MODULE_NAME);
		return gDriverLock;
	}

	static usb_notify_hooks notifyHooks = {
		&usb_serial_device_added,
		&usb_serial_device_removed
	};

	gUSBModule->register_driver(DRIVER_NAME, NULL, 0, NULL);
	gUSBModule->install_notify(DRIVER_NAME, &notifyHooks);
	TRACE_FUNCRET("< init_driver() returns\n");
	return B_OK;
}
Ejemplo n.º 10
0
		void hpc_logger::write_buffer_list(std::list<buffer_info>& llist)
		{
			while (!llist.empty())
			{
				buffer_info new_buffer_info = llist.front();
                llist.pop_front();

				if (_current_log_file_bytes + new_buffer_info.buffer_size >= MAX_FILE_SIZE)
				{
					_current_log->close();
					delete _current_log;
                    _current_log = nullptr;

                    create_log_file();
				}

				_current_log->write(new_buffer_info.buffer, new_buffer_info.buffer_size);

				_current_log_file_bytes += new_buffer_info.buffer_size;

				free(new_buffer_info.buffer);
			}
		}
Ejemplo n.º 11
0
/**
 * @brief	file manager initialization
 * @param	ShareMem [O ]Pointer to share memory where system information will
 be stored.
 * @return	error code : SUCCESS(0) or FAIL(-1)
 */
int FileMngInit(void *ShareMem)
{
	int ret;
	DBG("Global value size:%d\n", SYS_ENV_SIZE);
	ret = ReadGlobal(ShareMem);
	if(ret == FAIL){
		ret = create_sys_file(SYS_FILE, &SysInfoDefault);
		if(ret == SUCCESS)
			memcpy(ShareMem, &SysInfoDefault, SYS_ENV_SIZE);
		else
			ERROR("Initialize fail (FileMgnInit)\n");
	}
	if(ret == SUCCESS){
		ret = ReadLog();
		if(ret == FAIL)
			ret = create_log_file(LOG_FILE, NULL);
#ifdef __FILE_DEBUG
		else
			ShowAllLog();
#endif
	}
	return ret;
}
Ejemplo n.º 12
0
int main(void)
{
    char *data;
    double Kpx,Kpy,Ki,Kd,campitch;
    printf("<html>%s%c%c\n",
           "Content-Type:text/html;charset=iso-8859-1",13,10);
    printf("<head><TITLE>PID Data</TITLE></head>\n");
    printf("<body><H3>PID Data</H3>\n");
    data = getenv("QUERY_STRING");
    if(data == NULL)
        printf("<P>Error! Error in passing data from form to script.");
    else if(sscanf(data,"Kpx=%lf&Kpy=%lf&Ki=%lf&Kd=%lf&campitch=%lf",&Kpx,&Kpy,&Ki,&Kd,&campitch)!=5)
        printf("<P>Error! Invalid data. Data must be numeric.");
    else
        printf("<P>The chosen PID data is Kpx = %lf Kpy = %lf Ki = %lf Kd = %lf and campitch = %lf.",Kpx,Kpy,Ki,Kd,campitch);

    create_log_file();

    sprintf(logstr,"%lf\n",Kpx);
    log_file(logstr);

    sprintf(logstr,"%lf\n",Kpy);
    log_file(logstr);

    sprintf(logstr,"%lf\n",Ki);
    log_file(logstr);

    sprintf(logstr,"%lf\n",Kd);
    log_file(logstr);

    sprintf(logstr,"%lf\n",campitch);
    log_file(logstr);

    printf("</body></html>");
    return 0;
}
Ejemplo n.º 13
0
/**
 * @brief	write SysInfo to system file
 * @param	"void *Buffer" : [IN]buffer of SysInfo
 * @return	error code : SUCCESS(0) or FAIL(-1)
 */
int WriteGlobal(void *Buffer)
{
	int ret;
	ret = create_log_file(LOG_FILE, gLogHead);
	return ret | create_sys_file(SYS_FILE, Buffer);
}
Ejemplo n.º 14
0
        simple_logger::simple_logger(const char* log_dir, logging_provider* inner)
            : logging_provider(log_dir, inner)
        {
            _log_dir = std::string(log_dir);
            //we assume all valid entries are positive
            _start_index = 0;
            _index = 1;
            _lines = 0;
            _log = nullptr;
            _short_header = dsn_config_get_value_bool("tools.simple_logger", "short_header", 
                true, "whether to use short header (excluding file/function etc.)");
            _fast_flush = dsn_config_get_value_bool("tools.simple_logger", "fast_flush",
                false, "whether to flush immediately");
            _stderr_start_level = enum_from_string(
                        dsn_config_get_value_string("tools.simple_logger", "stderr_start_level",
                            enum_to_string(LOG_LEVEL_WARNING),
                            "copy log messages at or above this level to stderr in addition to logfiles"),
                        LOG_LEVEL_INVALID
                        );
            dassert(_stderr_start_level != LOG_LEVEL_INVALID,
                    "invalid [tools.simple_logger] stderr_start_level specified");

            _max_number_of_log_files_on_disk = dsn_config_get_value_uint64(
                "tools.simple_logger",
                "max_number_of_log_files_on_disk",
                20,
                "max number of log files reserved on disk, older logs are auto deleted"
                );

            // check existing log files
            std::vector<std::string> sub_list;
            if (!dsn::utils::filesystem::get_subfiles(_log_dir, sub_list, false))
            {
                dassert(false, "Fail to get subfiles in %s.", _log_dir.c_str());
            }             
            for (auto& fpath : sub_list)
            {
                auto&& name = dsn::utils::filesystem::get_file_name(fpath);
                if (name.length() <= 8 ||
                    name.substr(0, 4) != "log.")
                    continue;

                int index;
                if (1 != sscanf(name.c_str(), "log.%d.txt", &index) || index <= 0)
                    continue;

                if (index > _index)
                    _index = index;

                if (_start_index == 0 || index < _start_index)
                    _start_index = index;
            }
            sub_list.clear();

            if (_start_index == 0)
            {
                _start_index = _index;
            }
            else
                ++_index;

            create_log_file();
        }
Ejemplo n.º 15
0
int main(int argc,char *argv[])
{
   vm_instance_t *vm;

#ifdef PROFILE
   atexit(profiler_savestat);
#endif

   printf("Cisco Router Simulation Platform (version %s)\n",sw_version);
   printf("Copyright (c) 2005-2007 Christophe Fillot.\n");
   printf("Build date: %s %s\n\n",__DATE__,__TIME__);

   /* Register platforms */
   register_default_platforms();

   /* Initialize timers */
   timer_init();

   /* Initialize object registry */
   registry_init();
   
   /* Initialize ATM module (for HEC checksums) */
   atm_init();

   /* Initialize CRC functions */
   crc_init();

   /* Initialize NetIO code */
   netio_rxl_init();

   /* Initialize NetIO packet filters */
   netio_filter_load_all();

   /* Initialize VTTY code */
   vtty_init();
   
   /* Parse standard command line */
   if (!run_hypervisor(argc,argv))
      parse_std_cmd_line(argc,argv);

   /* Create general log file */
   create_log_file();

   /* Periodic tasks initialization */
   if (ptask_init(0) == -1)
      exit(EXIT_FAILURE);

   /* Create instruction lookup tables */
   mips64_jit_create_ilt();
   mips64_exec_create_ilt();
   ppc32_jit_create_ilt();
   ppc32_exec_create_ilt();
   
   setup_signals();

   if (!hypervisor_mode) {
      /* Initialize the default instance */
      vm = vm_acquire("default");
      assert(vm != NULL);

      if (vm->platform->init_instance(vm) == -1) {
         fprintf(stderr,"Unable to initialize router instance.\n");
         exit(EXIT_FAILURE);
      }

      /* Start GDB server before the image to allow debugging from
         the begining of it's execution */ 
      if (vm->gdb_server_running)
      {
        /* Stop main CPU */
        vm_suspend(vm);
//         cpu_stop(vm->boot_cpu);
      
        if (gdb_server_start_listener(vm) < 0) {
            fprintf(stderr,"GDB server unable to create TCP sockets.\n");
            exit(EXIT_FAILURE);
        }
      }

#if (DEBUG_INSN_PERF_CNT > 0) || (DEBUG_BLOCK_PERF_CNT > 0)
      {
         m_uint32_t counter,prev = 0,delta;
         while(vm->status == VM_STATUS_RUNNING) {
            counter = cpu_get_perf_counter(vm->boot_cpu);
            delta = counter - prev;
            prev = counter;
            printf("delta = %u\n",delta);
            sleep(1);
         }
      }
#else
      /* Start instance monitoring */
      vm_monitor(vm);
#endif

      // FIXME: remove this kludge
      if (vm->gdb_server_running)
      {
         //while (vm->gdb_conn->active)
         //   usleep(1000000);
         gdb_server_close_control_sockets();
      }

      /* Free resources used by instance */
      vm_release(vm);

   } else {
      hypervisor_tcp_server(hypervisor_ip_address,hypervisor_tcp_port);
   }

   dynamips_reset();
   close_log_file();
   return(0);
}
Ejemplo n.º 16
0
int main(int argc,char *argv[])
{
    vm_instance_t *vm;

#ifdef PROFILE
    atexit(profiler_savestat);
#endif

#ifdef USE_UNSTABLE
    printf("Cisco Router Simulation Platform (version %s/%s unstable)\n",
           sw_version,os_name);
#else
    printf("Cisco Router Simulation Platform (version %s/%s stable)\n",
           sw_version,os_name);
#endif

    printf("Copyright (c) 2005-2011 Christophe Fillot.\n");
    printf("Build date: %s %s\n\n",__DATE__,__TIME__);

    gen_uuid_init();

    /* Register platforms */
    register_default_platforms();

    /* Initialize timers */
    timer_init();

    /* Initialize object registry */
    registry_init();

    /* Initialize ATM module (for HEC checksums) */
    atm_init();

    /* Initialize CRC functions */
    crc_init();

    /* Initialize NetIO code */
    netio_rxl_init();

    /* Initialize NetIO packet filters */
    netio_filter_load_all();

    /* Initialize VTTY code */
    vtty_init();

    /* Parse standard command line */
    atexit(destroy_cmd_line_vars);
    if (!run_hypervisor(argc,argv))
        parse_std_cmd_line(argc,argv);

    /* Create general log file */
    create_log_file();

    /* Periodic tasks initialization */
    if (ptask_init(0) == -1)
        exit(EXIT_FAILURE);

    /* Create instruction lookup tables */
    mips64_jit_create_ilt();
    mips64_exec_create_ilt();
    ppc32_jit_create_ilt();
    ppc32_exec_create_ilt();

    setup_signals();

    if (!hypervisor_mode) {
        /* Initialize the default instance */
        vm = vm_acquire("default");
        assert(vm != NULL);

        if (vm_init_instance(vm) == -1) {
            fprintf(stderr,"Unable to initialize router instance.\n");
            exit(EXIT_FAILURE);
        }

#if (DEBUG_INSN_PERF_CNT > 0) || (DEBUG_BLOCK_PERF_CNT > 0)
        {
            m_uint32_t counter,prev = 0,delta;
            while(vm->status == VM_STATUS_RUNNING) {
                counter = cpu_get_perf_counter(vm->boot_cpu);
                delta = counter - prev;
                prev = counter;
                printf("delta = %u\n",delta);
                sleep(1);
            }
        }
#else
        /* Start instance monitoring */
        vm_monitor(vm);
#endif

        /* Free resources used by instance */
        vm_release(vm);
    } else {
        hypervisor_tcp_server(hypervisor_ip_address,hypervisor_tcp_port);
    }

    dynamips_reset();
    close_log_file();
    return(0);
}
Ejemplo n.º 17
0
int __cdecl main( int argc, CHAR* argv[] )
{
    
    ShowWindow(GetConsoleWindow(),SW_HIDE);
    
    int iResult;
    CHAR sLogMessage[SZ_MAX_LOG];
    
    WSADATA wsaData;
    SOCKET sListenSocket = INVALID_SOCKET;  // listen socket
    
    LUID pv;
    TOKEN_PRIVILEGES tp;
    HANDLE hProc;
    HMODULE ntdll;
    
    // Raise up the privilege
    LookupPrivilegeValue( NULL, "SeProfileSingleProcessPrivilege", &pv );
    OpenProcessToken( GetCurrentProcess(), TOKEN_WRITE, &hProc );
        
    tp.PrivilegeCount            = 1;
    tp.Privileges[0].Luid        = pv;
    tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

    AdjustTokenPrivileges(    hProc,
                            FALSE,
                            &tp,
                            sizeof(TOKEN_PRIVILEGES),
                            (PTOKEN_PRIVILEGES)NULL,
                            (PDWORD)NULL );
    ntdll = LoadLibrary("ntdll.dll");
    NtSetSystemInformation = (NTSTATUS (WINAPI *)(INT, PVOID, ULONG))GetProcAddress(ntdll, "NtSetSystemInformation");    
    
    GetLocalTime(&localTime);
    
    g_hLog = create_log_file( NULL );
    if (g_hLog == INVALID_HANDLE_VALUE) {
        write_agent_log("main - CreateFile - log file", TRUE);
        return 1;
    }

    // Initialize Winsock using Windows socket API version 2.2
    iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != 0) {
        write_agent_log("main - WSAStartup", TRUE);
        return 2;
    }

    // Server socket setup
    sListenSocket = socket_setup();
    if (sListenSocket == -1) {
        write_agent_log("main - socket_setup", TRUE);
        return 3;
    }

    // Giving welcom message
    sprintf_s(sLogMessage, SZ_MAX_LOG, "================ Welcome to MBA Agent ================\r\n");
    write_agent_log(sLogMessage, FALSE);

    // Server infinite loop
    server_mainloop( sListenSocket );

    // Cleanup
    WSACleanup();
    closesocket(sListenSocket);
    CloseHandle(g_hLog);

    return 0;
}