Browse Source

* i2p::fs migration: Daemon, DaemonLinux, api (#290)

pull/388/head
hagen 9 years ago
parent
commit
97c136d043
  1. 29
      Daemon.cpp
  2. 9
      DaemonLinux.cpp
  3. 12
      api.cpp

29
Daemon.cpp

@ -5,6 +5,7 @@
#include "Config.h" #include "Config.h"
#include "Log.h" #include "Log.h"
#include "FS.h"
#include "Base.h" #include "Base.h"
#include "version.h" #include "version.h"
#include "Transports.h" #include "Transports.h"
@ -14,7 +15,6 @@
#include "Tunnel.h" #include "Tunnel.h"
#include "NetDb.h" #include "NetDb.h"
#include "Garlic.h" #include "Garlic.h"
#include "util.h"
#include "Streaming.h" #include "Streaming.h"
#include "Destination.h" #include "Destination.h"
#include "HTTPServer.h" #include "HTTPServer.h"
@ -63,9 +63,17 @@ namespace i2p
i2p::config::Init(); i2p::config::Init();
i2p::config::ParseCmdline(argc, argv); i2p::config::ParseCmdline(argc, argv);
std::string config = i2p::util::filesystem::GetConfigFile().string(); std::string config; i2p::config::GetOption("conf", config);
std::string tunconf = i2p::util::filesystem::GetTunnelsConfigFile().string(); std::string tunconf; i2p::config::GetOption("tunconf", tunconf);
std::string datadir = i2p::util::filesystem::GetDataDir().string(); std::string datadir; i2p::config::GetOption("datadir", datadir);
i2p::fs::DetectDataDir(datadir, IsService());
i2p::fs::Init();
datadir = i2p::fs::GetDataDir();
if (config == "")
config = i2p::fs::DataDirPath("i2p.conf");
if (tunconf == "")
tunconf = i2p::fs::DataDirPath("tunnels.cfg");
i2p::config::ParseConfig(config); i2p::config::ParseConfig(config);
i2p::config::Finalize(); i2p::config::Finalize();
@ -144,18 +152,9 @@ namespace i2p
if (isDaemon && (logs == "" || logs == "stdout")) if (isDaemon && (logs == "" || logs == "stdout"))
logs = "file"; logs = "file";
if (logs == "file") if (logs == "file") {
{
if (logfile == "") if (logfile == "")
{ logfile = i2p::fs::DataDirPath("i2pd.log");
// use autodetect of logfile
logfile = IsService () ? "/var/log" : i2p::util::filesystem::GetDataDir().string();
#ifndef _WIN32
logfile.append("/i2pd.log");
#else
logfile.append("\\i2pd.log");
#endif
}
StartLog (logfile); StartLog (logfile);
} else { } else {
// use stdout // use stdout

9
DaemonLinux.cpp

@ -9,8 +9,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "Config.h" #include "Config.h"
#include "FS.h"
#include "Log.h" #include "Log.h"
#include "util.h"
void handle_signal(int sig) void handle_signal(int sig)
{ {
@ -55,7 +55,7 @@ namespace i2p
LogPrint(eLogError, "Daemon: could not create process group."); LogPrint(eLogError, "Daemon: could not create process group.");
return false; return false;
} }
std::string d(i2p::util::filesystem::GetDataDir().string ()); // make a copy std::string d = i2p::fs::GetDataDir();
if (chdir(d.c_str()) != 0) if (chdir(d.c_str()) != 0)
{ {
LogPrint(eLogError, "Daemon: could not chdir: ", strerror(errno)); LogPrint(eLogError, "Daemon: could not chdir: ", strerror(errno));
@ -75,8 +75,7 @@ namespace i2p
// this code is c-styled and a bit ugly, but we need fd for locking pidfile // this code is c-styled and a bit ugly, but we need fd for locking pidfile
std::string pidfile; i2p::config::GetOption("pidfile", pidfile); std::string pidfile; i2p::config::GetOption("pidfile", pidfile);
if (pidfile == "") { if (pidfile == "") {
pidfile = IsService () ? "/var/run" : i2p::util::filesystem::GetDataDir().string(); pidfile = i2p::fs::DataDirPath("i2pd.pid");
pidfile.append("/i2pd.pid");
} }
if (pidfile != "") { if (pidfile != "") {
pidFH = open(pidfile.c_str(), O_RDWR | O_CREAT, 0600); pidFH = open(pidfile.c_str(), O_RDWR | O_CREAT, 0600);
@ -115,7 +114,7 @@ namespace i2p
bool DaemonLinux::stop() bool DaemonLinux::stop()
{ {
unlink(pidfile.c_str()); i2p::fs::Remove(pidfile);
return Daemon_Singleton::stop(); return Daemon_Singleton::stop();
} }

12
api.cpp

@ -9,7 +9,7 @@
#include "Identity.h" #include "Identity.h"
#include "Destination.h" #include "Destination.h"
#include "Crypto.h" #include "Crypto.h"
#include "util.h" #include "FS.h"
#include "api.h" #include "api.h"
namespace i2p namespace i2p
@ -18,10 +18,16 @@ namespace api
{ {
void InitI2P (int argc, char* argv[], const char * appName) void InitI2P (int argc, char* argv[], const char * appName)
{ {
i2p::util::filesystem::SetAppName (appName);
i2p::config::Init (); i2p::config::Init ();
i2p::config::ParseCmdline (argc, argv); i2p::config::ParseCmdline (argc, argv);
i2p::config::Finalize (); i2p::config::Finalize ();
std::string datadir; i2p::config::GetOption("datadir", datadir);
i2p::fs::SetAppName (appName);
i2p::fs::DetectDataDir(datadir, false);
i2p::fs::Init();
i2p::crypto::InitCrypto (); i2p::crypto::InitCrypto ();
i2p::context.Init (); i2p::context.Init ();
} }
@ -36,7 +42,7 @@ namespace api
if (logStream) if (logStream)
StartLog (logStream); StartLog (logStream);
else else
StartLog (i2p::util::filesystem::GetFullPath (i2p::util::filesystem::GetAppName () + ".log")); StartLog (i2p::fs::DataDirPath (i2p::fs::GetAppName () + ".log"));
LogPrint(eLogInfo, "API: starting NetDB"); LogPrint(eLogInfo, "API: starting NetDB");
i2p::data::netdb.Start(); i2p::data::netdb.Start();
LogPrint(eLogInfo, "API: starting Transports"); LogPrint(eLogInfo, "API: starting Transports");

Loading…
Cancel
Save