Beispiel #1
0
static bool
expand( const char *path, char *absolute_path ) {
  assert( path != NULL );
  assert( absolute_path != NULL );

  char buf[ 256 ];
  char *result = realpath( path, absolute_path );
  if ( result == NULL ) {
    trema_fprintf( stderr, "Could not get the absolute path of %s: %s.\n", path, strerror_r( errno, buf, sizeof( buf ) ) );
    return false;
  }

  return true;
}
Beispiel #2
0
/**
 * Sets chibach home directory for your chibach session.
 */
void
set_chibach_home( void ) {
  if ( getenv( CHIBACH_HOME ) == NULL ) {
    setenv( CHIBACH_HOME, "/", 1 );
    chibach_home = xstrdup( "/" );
  }
  else {
    char absolute_path[ PATH_MAX ];
    if ( !expand( getenv( CHIBACH_HOME ), absolute_path ) ) {
      trema_fprintf( stderr, "Falling back CHIBACH_HOME to \"/\".\n" );
      strncpy( absolute_path, "/", 2 );
    }
    setenv( CHIBACH_HOME, absolute_path, 1 );
    chibach_home = xstrdup( absolute_path );
  }
}
Beispiel #3
0
static void
log_file( int priority, const char *format, va_list ap ) {
  struct timeval tv;
  gettimeofday( &tv, NULL );
  char now[ 26 ];
  strftime( now, sizeof( now ), "%b %e %T", localtime( &tv.tv_sec ) ); // syslog message format look like
  const char *priority_name = priority_name_from( priority );

  char message[ max_message_length ];
  va_list new_ap;
  va_copy( new_ap, ap );
  vsnprintf( message, max_message_length, format, new_ap );

  trema_fprintf( fd, "%s.%03d [%s] %s\n", now, tv.tv_usec / 1000, priority_name, message );
  fflush( fd );
}
Beispiel #4
0
/**
 * Sets temporary directory for your Chibach session.
 */
void
set_chibach_tmp( void ) {
  char path[ PATH_MAX ];

  if ( getenv( CHIBACH_TMP ) == NULL ) {
    const char *chibach_home = get_chibach_home();
    if ( chibach_home[ strlen( chibach_home ) - 1 ] == '/' ) {
      snprintf( path, PATH_MAX, "%stmp", chibach_home );
    }
    else {
      snprintf( path, PATH_MAX, "%s/tmp", chibach_home );
    }
    path[ PATH_MAX - 1 ] = '\0';
  }
  else {
    if ( !expand( getenv( CHIBACH_TMP ), path ) ) {
      trema_fprintf( stderr, "Falling back CHIBACH_TMP to \"/tmp\".\n" );
      strncpy( path, "/tmp", 5 );
    }
  }

  chibach_tmp = xstrdup( path );
  setenv( CHIBACH_TMP, chibach_tmp, 1 );
}