Пример #1
0
TEST(LogFileOutput, startup_truncation) {
  const char* filename = "start-truncate-test";
  const char* archived_filename = "start-truncate-test.0";

  delete_file(filename);
  delete_file(archived_filename);

  // Use the same log file twice and expect it to be overwritten/truncated
  init_log_file(filename, "filecount=0");
  ASSERT_TRUE(file_exists(filename))
    << "configured logging to file '" << filename << "' but file was not found";

  init_log_file(filename, "filecount=0");
  ASSERT_TRUE(file_exists(filename))
    << "configured logging to file '" << filename << "' but file was not found";
  EXPECT_FALSE(file_exists(archived_filename))
    << "existing log file was not properly truncated when filecount was 0";

  // Verify that the file was really truncated and not just appended
  EXPECT_TRUE(file_contains_substring(filename, LOG_TEST_STRING_LITERAL));
  const char* repeated[] = { LOG_TEST_STRING_LITERAL, LOG_TEST_STRING_LITERAL };
  EXPECT_FALSE(file_contains_substrings_in_order(filename, repeated))
    << "log file " << filename << " appended rather than truncated";

  delete_file(filename);
  delete_file(archived_filename);
}
Пример #2
0
/* set up function pointers for logging */
int init_logging(int logtype, const char *file, int flags)
{
   int rc;
   output_plugin *log_fun;
   switch (logtype)
   {
      case LOG_FILE:
         log_fun = init_log_file();
         break;
      case LOG_STDOUT:
         log_fun = init_log_stdout();
         break;
      case LOG_FIFO:
         log_fun = init_log_fifo();
         break;
      /* these types are coming !*/
      case LOG_ASCII:
         break;
      case LOG_UNIFIED:
         break;
      default:
         fprintf(stderr,"whoops! init_logging\n");
   }
   if(log_fun){
       log_output[n_outputs++] = log_fun;
       if(log_fun->init) {
           rc = log_fun->init(log_fun, file, flags);
           if(rc)
               n_outputs--;
           return rc;
       } else 
           return 0;
   }
   return 0xFABE;
}
Пример #3
0
TEST(LogFileOutput, startup_rotation) {
  const size_t rotations = 5;
  const char* filename = "start-rotate-test";
  char* rotated_file[rotations];

  ResourceMark rm;
  for (size_t i = 0; i < rotations; i++) {
    size_t len = strlen(filename) + 3;
    rotated_file[i] = NEW_RESOURCE_ARRAY(char, len);
    int ret = jio_snprintf(rotated_file[i], len, "%s." SIZE_FORMAT, filename, i);
    ASSERT_NE(-1, ret);
    delete_file(rotated_file[i]);
  }

  delete_file(filename);
  init_log_file(filename);
  ASSERT_TRUE(file_exists(filename))
    << "configured logging to file '" << filename << "' but file was not found";

  // Initialize the same file a bunch more times to trigger rotations
  for (size_t i = 0; i < rotations; i++) {
    init_log_file(filename);
    EXPECT_TRUE(file_exists(rotated_file[i]));
  }

  // Remove a file and expect its slot to be re-used
  delete_file(rotated_file[1]);
  init_log_file(filename);
  EXPECT_TRUE(file_exists(rotated_file[1]));

  // Clean up after test
  delete_file(filename);
  for (size_t i = 0; i < rotations; i++) {
    delete_file(rotated_file[i]);
  }
}
Пример #4
0
void aesm_internal_log(const char *file_name, int line_no, const char *funname, int level, const char *format, ...)
{
    if(level <= aesm_trace_level){
        if(at_start){
            at_start=0;
            se_mutex_init(&cs);
            init_log_file();
        }
        char filename[MAX_PATH];
        ae_error_t err = aesm_get_cpathname(FT_PERSISTENT_STORAGE, AESM_DBG_LOG_FID, filename, MAX_PATH);
        if(err != AE_SUCCESS)
            return;
        FILE *logfile = NULL;
        se_mutex_lock(&cs);
        logfile = fopen(filename, "a+");
        if(logfile == NULL){
            se_mutex_unlock(&cs);
            return;
        }
        time_t t;
        struct tm time_info;
        va_list varg;
        char time_buf[TIME_BUF_SIZE];
        time(&t);
        struct tm *temp_time_info;
        temp_time_info = localtime(&t);
        memcpy_s(&time_info, sizeof(time_info), temp_time_info, sizeof(*temp_time_info));
        if(strftime(time_buf, TIME_BUF_SIZE, "%c", &time_info)!=0){
           fprintf(logfile, "[%s|%d|%s|%s]",file_name, line_no, funname, time_buf);
        }else{
           fprintf(logfile, "[%s|%d|%s]",file_name, line_no, funname);
        }
        va_start(varg, format);
        char message_buf[MAX_BUF_SIZE];
        vsnprintf(message_buf, MAX_BUF_SIZE-1, format, varg);
        va_end(varg);
        std::string input_message = message_buf;
        std::string output_message = internal_log_msg_trans(input_message);
        fprintf(logfile, "%s\n", output_message.c_str());
        fflush(logfile);
        fclose(logfile);
        se_mutex_unlock(&cs);
    }
}
//
//
//
/// @brief A help function used in the constructor that open and
///        initializes the log file if the file do not exists yet.
//
/// @return None.
//
void inline open_and_init()
{
	manager.file_system::open_txt_output(log_file);
	switch(manager.file_system::is_open())
	{
		case false:
		{
			report_bad_init();
		}
		break;
		case true:
		{
			log_file_ready = true;
			init_log_file();
			report_input_list();
		}
		break;
	}
};
Пример #6
0
int main(int argc, char *argv[]){   
    int fuserc;
    struct newfs_state *state;

    state = malloc(sizeof(struct newfs_state));
    state->logfile = init_log_file();

    write_log("--------------------\n");
 
    // Initialise the file system. This is being done outside of fuse for ease of debugging.
    init_fs();

    fuserc = fuse_main(argc, argv, &newfs_oper, state);
    
    // Shutdown the file system.
    shutdown_fs();

    close_log_file();

    free(state);

    return fuserc;
}
Пример #7
0
DR_EXPORT void dr_init(client_id_t id)
{
	const char *option;

	option = dr_get_options(id);
	fi_printf("the passed option to this client: %s\n", option);
	sid = atoi(option);
	fi_printf("sid: %d\n", sid);

	init_log_file();

	dr_register_filter_syscall_event(pre_syscall_filter);
	drmgr_init();

	tls_idx = drmgr_register_tls_field();
	drmgr_register_pre_syscall_event(pre_syscall);
	drmgr_register_post_syscall_event(post_syscall);

	drmgr_register_thread_init_event(thread_init_event);
	drmgr_register_thread_exit_event(thread_exit_event);

	jfile_fds[0] = -1;
	jfile_fds[1] = -1;
}
Пример #8
0
/*!
 * \param argc The number of argument on command line
 * \param argv The arguments on command line
 * \return zero on success else non zero value
 */
int
initialisation (int argc, char *argv[])
{

#ifdef MSDOS
  _crt0_startup_flags |= _CRT0_FLAG_NO_LFN;
  // Disable long filename to avoid mem waste in select_rom func.
#endif

  memset (&option, 0, sizeof (option));

  option.want_stereo = FALSE;
  option.want_fullscreen = FALSE;
  option.want_fullscreen_aspect = FALSE;
  option.configure_joypads = FALSE;
  option.want_hardware_scaling = FALSE;
  option.want_arcade_card_emulation = TRUE; 
  option.want_supergraphx_emulation = TRUE;
  option.window_size = 1;

#if defined(ENABLE_NETPLAY)
  option.local_input_mapping[0] = 0;
  option.local_input_mapping[1] = 1;
  option.local_input_mapping[2] = -1;
  option.local_input_mapping[3] = -1;
  option.local_input_mapping[4] = -1;
  strcpy(option.server_hostname,"localhost");
#endif

  /*
   * Most sound cards won't like this value but we'll accept whatever SDL
   * gives us.  This frequency will get us really close to the original
   * pc engine sound behaviour.
   */
  option.want_snd_freq = 21963;

  // Initialise paths
  osd_init_paths (argc, argv);

  // Create the log file
  init_log_file ();

  // Init the random seed
  srand ((unsigned int) time (NULL));

#if 0 // ZX: !defined( NGC) && !defined(PSP)
  // Read configuration in ini file
  parse_INIfile ();

  // Read the command line
  parse_commandline (argc, argv);
#endif

  // Initialise the host machine
  if (!osd_init_machine ())
    return -1;

  // If backup memory name hasn't been overriden on command line, use the default
# if 0 //LUDO:
  if ((bmdefault) && (strcmp (bmdefault, "")))
    snprintf (backup_mem, sizeof (backup_mem), "%s%s", short_exe_name,
        bmdefault);
  else
    snprintf (backup_mem, sizeof (backup_mem), "%sbackup.dat",
        short_exe_name);
# endif

  // In case of crash, try to free audio related ressources if possible
//      atexit (TrashSound);

  // Initialise the input devices
  if (osd_init_input () != 0)
    {
      fprintf (stderr, "Initialization of input system failed\n");
      return (-2);
    }

  return 0;
}