@ -7,10 +7,6 @@
# include <csignal>
# include <csignal>
# if !defined(_WIN32) && !defined(__OpenBSD__)
# include <wordexp.h>
# endif
# include <cxxopts.hpp>
# include <cxxopts.hpp>
# include <string>
# include <string>
# include <iostream>
# include <iostream>
@ -59,31 +55,6 @@ handle_signal_win32(DWORD fdwCtrlType)
}
}
# endif
# endif
/// resolve ~ and symlinks into actual paths (so we know the real path on disk,
/// to remove assumptions and confusion with permissions)
std : : string
resolvePath ( std : : string conffname )
{
// implemented in netbsd, removed downstream for security reasons
// even though it is defined by POSIX.1-2001+
# if !defined(_WIN32) && !defined(__OpenBSD__)
wordexp_t exp_result ;
wordexp ( conffname . c_str ( ) , & exp_result , 0 ) ;
char * resolvedPath = realpath ( exp_result . we_wordv [ 0 ] , NULL ) ;
if ( ! resolvedPath )
{
// relative paths don't need to be resolved
// llarp::LogWarn("Can't resolve path: ", exp_result.we_wordv[0]);
return conffname ;
}
return resolvedPath ;
# else
// TODO(despair): dig through LLVM local patch set
// one of these exists deep in the bowels of LLVMSupport
return conffname ; // eww, easier said than done outside of cygwin
# endif
}
/// this sets up, configures and runs the main context
/// this sets up, configures and runs the main context
static void
static void
run_main_context ( std : : string conffname , llarp_main_runtime_opts opts )
run_main_context ( std : : string conffname , llarp_main_runtime_opts opts )
@ -152,7 +123,7 @@ main(int argc, char *argv[])
bool genconfigOnly = false ;
bool genconfigOnly = false ;
bool asRouter = false ;
bool asRouter = false ;
bool overWrite = false ;
bool overWrite = false ;
std : : string conffname ; // suggestions: confFName? conf_fname?
std : : string conffname ;
try
try
{
{
auto result = options . parse ( argc , argv ) ;
auto result = options . parse ( argc , argv ) ;
@ -226,33 +197,10 @@ main(int argc, char *argv[])
fs : : path fname = fs : : path ( conffname ) ;
fs : : path fname = fs : : path ( conffname ) ;
fs : : path basedir = fname . parent_path ( ) ;
fs : : path basedir = fname . parent_path ( ) ;
conffname = fname . string ( ) ;
conffname = fname . string ( ) ;
conffname = resolvePath ( conffname ) ;
std : : error_code ec ;
// llarp::LogDebug("Basedir: ", basedir);
if ( basedir . string ( ) . empty ( ) )
{
// relative path to config
// does this file exist?
if ( ! basedir . empty ( ) )
if ( genconfigOnly )
{
if ( ! llarp_ensure_config ( conffname . c_str ( ) , basedir . string ( ) . c_str ( ) ,
overWrite , asRouter ) )
return 1 ;
}
else
{
{
if ( ! fs : : exists ( fname , ec ) )
std : : error_code ec ;
{
llarp : : LogError ( " Config file not found " , conffname ) ;
return 1 ;
}
}
}
else
{
// absolute path to config
if ( ! fs : : create_directories ( basedir , ec ) )
if ( ! fs : : create_directories ( basedir , ec ) )
{
{
if ( ec )
if ( ec )
@ -262,29 +210,27 @@ main(int argc, char *argv[])
return 1 ;
return 1 ;
}
}
}
}
}
if ( genconfigOnly )
if ( genconfigOnly )
{
{
// find or create file
if ( ! llarp_ensure_config ( conffname . c_str ( ) , basedir . string ( ) . c_str ( ) ,
if ( ! llarp_ensure_config ( conffname . c_str ( ) , basedir . string ( ) . c_str ( ) ,
overWrite , asRouter ) )
overWrite , asRouter ) )
return 1 ;
return 1 ;
}
}
else
else
{
{
// does this file exist?
std : : error_code ec ;
if ( ! fs : : exists ( conf fname, ec ) )
if ( ! fs : : exists ( fname, ec ) )
{
{
llarp : : LogError ( " Config file not found " , conffname ) ;
llarp : : LogError ( " Config file not found " , conffname ) ;
return 1 ;
return 1 ;
}
}
}
}
}
}
}
else
else
{
{
auto basepath = llarp : : GetDefaultConfigDir ( ) ;
auto basepath = llarp : : GetDefaultConfigDir ( ) ;
// I don't think this is necessary with this condition
// conffname = resolvePath(conffname);
llarp : : LogDebug ( " Find or create " , basepath . string ( ) ) ;
llarp : : LogDebug ( " Find or create " , basepath . string ( ) ) ;
std : : error_code ec ;
std : : error_code ec ;