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 @@ @@ -5,6 +5,7 @@
#include "Config.h"
#include "Log.h"
#include "FS.h"
#include "Base.h"
#include "version.h"
#include "Transports.h"
@ -14,7 +15,6 @@ @@ -14,7 +15,6 @@
#include "Tunnel.h"
#include "NetDb.h"
#include "Garlic.h"
#include "util.h"
#include "Streaming.h"
#include "Destination.h"
#include "HTTPServer.h"
@ -63,9 +63,17 @@ namespace i2p @@ -63,9 +63,17 @@ namespace i2p
i2p::config::Init();
i2p::config::ParseCmdline(argc, argv);
std::string config = i2p::util::filesystem::GetConfigFile().string();
std::string tunconf = i2p::util::filesystem::GetTunnelsConfigFile().string();
std::string datadir = i2p::util::filesystem::GetDataDir().string();
std::string config; i2p::config::GetOption("conf", config);
std::string tunconf; i2p::config::GetOption("tunconf", tunconf);
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::Finalize();
@ -144,18 +152,9 @@ namespace i2p @@ -144,18 +152,9 @@ namespace i2p
if (isDaemon && (logs == "" || logs == "stdout"))
logs = "file";
if (logs == "file")
{
if (logs == "file") {
if (logfile == "")
{
// 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
}
logfile = i2p::fs::DataDirPath("i2pd.log");
StartLog (logfile);
} else {
// use stdout

9
DaemonLinux.cpp

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

12
api.cpp

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

Loading…
Cancel
Save