Пример #1
0
/* Open a new log file: determine the start of the current
 * period, generate the log file name from the fileTemplate,
 * determine the end of the period and open the new log file.
 *
 * Returns the file descriptor of the new log file and also sets the
 * name of the file and the start time of the next period via pointers
 * supplied.
 */
static FILE *new_log_file(const char *fileTemplate, const char *linkname,
                          mode_t linktype, const char *prevlinkname,
                          PERIODICITY periodicity, int period_multiple,
                          int period_delay, char *pfilename,
                          size_t pfilename_len, time_t time_now,
                          time_t *pnext_period) {
  time_t start_of_period;
  struct tm   *tm;
  int log_fd;

  start_of_period = start_of_this_period(time_now, periodicity,
                                         period_multiple);
  tm = localtime(&start_of_period);
  strftime(pfilename, pfilename_len, fileTemplate, tm);
  *pnext_period = start_of_next_period(start_of_period, periodicity,
                                       period_multiple) + period_delay;

  CRONO_DEBUG(("%s (%d): using log file \"%s\" from %s (%d) until %s (%d) "
        "(for %d secs)\n",
        timestamp(time_now), time_now, pfilename,
        timestamp(start_of_period), start_of_period,
        timestamp(*pnext_period), *pnext_period,
        *pnext_period - time_now));

  log_fd = open(pfilename, O_WRONLY|O_CREAT|O_APPEND, FILE_MODE);

#ifndef DONT_CREATE_SUBDIRS
  if ((log_fd < 0) && (errno == ENOENT)) {
    create_subdirs(pfilename);
    log_fd = open(pfilename, O_WRONLY|O_CREAT|O_APPEND, FILE_MODE);
  }
#endif

  if (log_fd < 0) {
    perror(pfilename);
    return NULL;
  }

  if (linkname) {
    /* Create a relative symlink to logs under linkname's directory */
    std::string dir = Util::safe_dirname(linkname);
    if (dir != "/") {
      dir.append("/");
    }
    std::string filename;
    if (!strncmp(pfilename, dir.c_str(), dir.length())) {
      filename = pfilename + dir.length();
    } else {
      filename = pfilename;
    }

    create_link(filename.c_str(), linkname, linktype, prevlinkname);
  }
  return fdopen(log_fd, "a");
}
Пример #2
0
/* Open a new log file: determine the start of the current
 * period, generate the log file name from the fileTemplate,
 * determine the end of the period and open the new log file.
 *
 * Returns the file descriptor of the new log file and also sets the
 * name of the file and the start time of the next period via pointers
 * supplied.
 */
static FILE *new_log_file(const char *fileTemplate, const char *linkname,
                          mode_t linktype, const char *prevlinkname,
                          PERIODICITY periodicity, int period_multiple,
                          int period_delay, char *pfilename,
                          size_t pfilename_len, time_t time_now,
                          time_t *pnext_period) {
  time_t start_of_period;
  struct tm   *tm;
  int log_fd;

  start_of_period = start_of_this_period(time_now, periodicity,
                                         period_multiple);
  tm = localtime(&start_of_period);
  strftime(pfilename, pfilename_len, fileTemplate, tm);
  *pnext_period = start_of_next_period(start_of_period, periodicity,
                                       period_multiple) + period_delay;

  DEBUG(("%s (%d): using log file \"%s\" from %s (%d) until %s (%d) "
        "(for %d secs)\n",
        timestamp(time_now), time_now, pfilename,
        timestamp(start_of_period), start_of_period,
        timestamp(*pnext_period), *pnext_period,
        *pnext_period - time_now));

  log_fd = open(pfilename, O_WRONLY|O_CREAT|O_APPEND, FILE_MODE);

#ifndef DONT_CREATE_SUBDIRS
  if ((log_fd == 0) && (errno == ENOENT)) {
    create_subdirs(pfilename);
    log_fd = open(pfilename, O_WRONLY|O_CREAT|O_APPEND, FILE_MODE);
  }
#endif

  if (log_fd < 0) {
    perror(pfilename);
    return NULL;
  }

  if (linkname) {
    create_link(pfilename, linkname, linktype, prevlinkname);
  }
  return fdopen(log_fd, "a");
}
Пример #3
0
/*
 * property
 * family
 * structure
 * read
 * write
 * data
 * other
 * */
void AddProperty( char * input_string, enum external_type et )
{
	char * s_family = NULL ;
	char * s_property = NULL ;
	char * s_dummy ;
	ssize_t s_array ;
	enum ag_combined s_combined ;
	enum ag_index s_index_type ;
	enum ft_format s_format ;
	ssize_t s_length ;
	enum fc_change s_change ;
	char * s_read = NULL ;
	char * s_write = NULL ;
	char * s_data = NULL ;
	char * s_other = NULL;
	char * start_pointer = input_string ;
	
	if ( input_string == NULL ) {
		return ;
	}
	
	if ( ! Globals.allow_external ) {
		LEVEL_DEBUG("External prgroams not supported by %s",Globals.argv[0]) ;
		return ;
	}

	// property
	GetQuotedString( property ) ;
	
	// family
	GetQuotedString( family ) ;

	// type
	GetQuotedString( dummy ) ;
	switch ( s_dummy[0] ) {
		case 'D':
			s_length = PROPERTY_LENGTH_DIRECTORY ;
			s_format = ft_directory ;
			break ;
		case 'i':
			s_length = PROPERTY_LENGTH_INTEGER ;
			s_format = ft_integer ;
			break ;
		case 'u':
			s_length = PROPERTY_LENGTH_UNSIGNED ;
			s_format = ft_unsigned ;
			break ;
		case 'f':
			s_length = PROPERTY_LENGTH_FLOAT ;
			s_format = ft_float ;
			break ;
		case 'a':
			s_length = 1 ;
			s_format = ft_ascii ;
			break ;
		case 'b':
			s_length = 1 ;
			s_format = ft_binary ;
			break ;
		case 'y':
			s_length = PROPERTY_LENGTH_YESNO ;
			s_format = ft_yesno ;
			break ;
		case 'd':
			s_length = PROPERTY_LENGTH_DATE ;
			s_format = ft_date ;
			break ;
		case 't':
			s_length = PROPERTY_LENGTH_TEMP ;
			s_format = ft_temperature ;
			break ;
		case 'g':
			s_length = PROPERTY_LENGTH_TEMPGAP ;
			s_format = ft_tempgap ;
			break ;
		case 'p':
			s_length = PROPERTY_LENGTH_PRESSURE ;
			s_format = ft_pressure ;
			break ;
		default:
			LEVEL_DEFAULT("Unrecognized variable type <%s> for property <%s> family <%s>",s_dummy,s_property,s_family);
			s_format = ft_unknown ;
			return ;
	}
	if ( s_dummy[1] ) { 
		int temp_length ;
		temp_length = strtol( &s_dummy[1], NULL, 0 ) ;
		if ( temp_length < 1 ) {
			LEVEL_DEFAULT("Unrecognized variable length <%s> for property <%s> family <%s>",s_dummy,s_property,s_family);
			return ;
		}
		s_length = temp_length ;
	}

	// array
	GetQuotedString( dummy ) ;
	switch ( s_dummy[0] ) {
		case '1':
		case '0':
		case '\0':
			s_combined = ag_separate ;
			s_index_type = ag_numbers ;
			s_array = 1 ;
			break ;
		case '-':
			s_array = 1 ;
			switch ( s_dummy[1] ) {
				case '1':
					s_combined = ag_sparse ;
					s_index_type = ag_numbers ;
					break ;
				default:
					s_combined = ag_sparse ;
					s_index_type = ag_letters ;
					break ;
			}
			break ;
		case '+':
			if ( isalpha( (int) s_dummy[1] ) ) {
				s_array = toupper( (int) s_dummy[1] ) - 'A' ;
				s_combined = ag_aggregate ;
				s_index_type = ag_letters ;
			} else {
				s_array = strtol( s_dummy, NULL, 0 ) ;
				s_combined = ag_aggregate ;
				s_index_type = ag_numbers ;
			}
			break ;
		default:
			if ( isalpha( (int) s_dummy[0] ) ) {
				s_array = toupper( (int) s_dummy[0] ) - 'A' ;
				s_combined = ag_separate ;
				s_index_type = ag_letters ;
			} else {
				s_array = strtol( s_dummy, NULL, 0 ) ;
				s_combined = ag_separate ;
				s_index_type = ag_numbers ;
			}
			break ;
	}
	if ( s_array < 1 ) {
		LEVEL_DEFAULT("Unrecognized array type <%s> for property <%s> family <%s>",s_dummy,s_property,s_family);
		return ;
	}

	// persistance
	GetQuotedString( dummy ) ;
	switch ( s_dummy[0] ) {
		case 'f':
			s_change = fc_static ;
			break ;
		case 's':
			s_change = fc_stable ;
			break ;
		case 'v':
			s_change = fc_volatile ;
			break ;
		case 't':
			s_change = fc_second ;
			break ;
		case 'u':
			s_change = fc_uncached ;
			break ;
		default:
			LEVEL_DEFAULT("Unrecognized persistance <%s> for property <%s> family <%s>",s_dummy,s_property,s_family);
			return ;
	}

	// read
	GetQuotedString( read ) ;

	// write
	GetQuotedString( write ) ;

	// data
	GetQuotedString( data ) ;

	// other
	GetQuotedString( other ) ;

	// test minimums
	if ( strlen( s_family ) > 0 && strlen( s_property ) > 0 ) {
		// Actually add
		AddFamilyToTree( s_family ) ;
		AddPropertyToTree( s_property, s_family, s_format, s_array, s_combined, s_index_type, s_length, s_change, s_read, s_write, s_data, s_other, et ) ;
		create_subdirs( s_property, s_family ) ;
	}

	// Clean up
	owfree( s_property ) ;
	owfree( s_family ) ;
	owfree( s_read ) ;
	owfree( s_write ) ;
	owfree( s_data ) ;
	owfree( s_other ) ;
}