mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
+ add --pidfile cmdline option
This commit is contained in:
parent
5d510f1cf4
commit
e4255ed712
2
Daemon.h
2
Daemon.h
@ -63,7 +63,7 @@ namespace i2p
|
|||||||
virtual bool stop();
|
virtual bool stop();
|
||||||
private:
|
private:
|
||||||
std::string pidfile;
|
std::string pidfile;
|
||||||
int pidFilehandle;
|
int pidFH;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -78,22 +78,25 @@ namespace i2p
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pidfile
|
// Pidfile
|
||||||
pidfile = IsService () ? "/var/run" : i2p::util::filesystem::GetDataDir().string();
|
// this code is c-styled and a bit ugly, but we need fd for locking pidfile
|
||||||
pidfile.append("/i2pd.pid");
|
pidfile = i2p::util::config::GetArg("pidfile", "");
|
||||||
pidFilehandle = open(pidfile.c_str(), O_RDWR | O_CREAT, 0600);
|
if (pidfile != "") {
|
||||||
if (pidFilehandle == -1)
|
pidFH = open(pidfile.c_str(), O_RDWR | O_CREAT, 0600);
|
||||||
{
|
if (pidFH < 0)
|
||||||
LogPrint(eLogError, "Daemon: could not create pid file ", pidfile, ": ", strerror(errno));
|
{
|
||||||
return false;
|
LogPrint(eLogError, "Daemon: could not create pid file ", pidfile, ": ", strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (lockf(pidFH, F_TLOCK, 0) != 0)
|
||||||
|
{
|
||||||
|
LogPrint(eLogError, "Daemon: could not lock pid file ", pidfile, ": ", strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
char pid[10];
|
||||||
|
sprintf(pid, "%d\n", getpid());
|
||||||
|
ftruncate(pidFH, 0);
|
||||||
|
write(pidFH, pid, strlen(pid));
|
||||||
}
|
}
|
||||||
if (lockf(pidFilehandle, F_TLOCK, 0) == -1)
|
|
||||||
{
|
|
||||||
LogPrint(eLogError, "Daemon: could not lock pid file ", pidfile, ": ", strerror(errno));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
char pid[10];
|
|
||||||
sprintf(pid, "%d\n", getpid());
|
|
||||||
write(pidFilehandle, pid, strlen(pid));
|
|
||||||
|
|
||||||
// Signal handler
|
// Signal handler
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
@ -110,7 +113,6 @@ namespace i2p
|
|||||||
|
|
||||||
bool DaemonLinux::stop()
|
bool DaemonLinux::stop()
|
||||||
{
|
{
|
||||||
close(pidFilehandle);
|
|
||||||
unlink(pidfile.c_str());
|
unlink(pidfile.c_str());
|
||||||
|
|
||||||
return Daemon_Singleton::stop();
|
return Daemon_Singleton::stop();
|
||||||
|
@ -7,6 +7,7 @@ i2pd cmdline options
|
|||||||
* --httpport= - The port to listen on (HTTP server)
|
* --httpport= - The port to listen on (HTTP server)
|
||||||
* --log= - Enable or disable logging to file. 1 for yes, 0 for no.
|
* --log= - Enable or disable logging to file. 1 for yes, 0 for no.
|
||||||
* --loglevel= - Log messages above this level (debug, *info, warn, error)
|
* --loglevel= - Log messages above this level (debug, *info, warn, error)
|
||||||
|
* --pidfile= - Where to write pidfile (dont write by default)
|
||||||
* --daemon= - Enable or disable daemon mode. 1 for yes, 0 for no.
|
* --daemon= - Enable or disable daemon mode. 1 for yes, 0 for no.
|
||||||
* --service= - 1 if uses system folders (/var/run/i2pd.pid, /var/log/i2pd.log, /var/lib/i2pd).
|
* --service= - 1 if uses system folders (/var/run/i2pd.pid, /var/log/i2pd.log, /var/lib/i2pd).
|
||||||
* --v6= - 1 if supports communication through ipv6, off by default
|
* --v6= - 1 if supports communication through ipv6, off by default
|
||||||
|
Loading…
x
Reference in New Issue
Block a user