Repository :
http://git.fedorahosted.org/cgit/firewalld-recode.git
On branch : master
---------------------------------------------------------------
commit 1b46b9e7b524252f27be9cb0bccfa28d95950adb
Author: Daniel Kopecek <dkopecek(a)redhat.com>
Date: Tue Oct 14 10:48:58 2014 +0200
Allow to specify PID file path on the command-line
---------------------------------------------------------------
src/Common/Utility.cpp | 10 ++++------
src/Common/Utility.hpp | 2 +-
src/Daemon/CLI.cpp | 10 ++++++++++
src/Daemon/CLI.hpp | 1 +
src/Daemon/main.cpp | 2 +-
5 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/src/Common/Utility.cpp b/src/Common/Utility.cpp
index 6f323bd..59e89de 100644
--- a/src/Common/Utility.cpp
+++ b/src/Common/Utility.cpp
@@ -73,15 +73,13 @@ namespace firewalld
return;
}
- bool writePID(const char *filepath)
+ bool writePID(const String& filepath)
{
- FILE *fp;
-
- if ((fp = ::fopen(filepath, "w")) == nullptr) {
+ std::ofstream pidstream(filepath, std::ios_base::trunc);
+ if (!pidstream) {
return false;
}
- ::fprintf(fp, "%u\n", (unsigned int)getpid());
- ::fclose(fp);
+ pidstream << numberToString(getpid()) << std::endl;
return true;
}
diff --git a/src/Common/Utility.hpp b/src/Common/Utility.hpp
index 271350a..a748888 100644
--- a/src/Common/Utility.hpp
+++ b/src/Common/Utility.hpp
@@ -33,7 +33,7 @@ namespace firewalld
{
void daemonize(void);
- bool writePID(const char *filepath);
+ bool writePID(const String& filepath);
#if defined(__GNUC__)
# define likely(expr) __builtin_expect(!!(expr), 1)
diff --git a/src/Daemon/CLI.cpp b/src/Daemon/CLI.cpp
index b5bfd45..e56c3ae 100644
--- a/src/Daemon/CLI.cpp
+++ b/src/Daemon/CLI.cpp
@@ -39,6 +39,7 @@ namespace firewalld
debug_level = 0;
debug_gc = false;
config_path = "firewalld.conf";
+ pid_path = "firewalld.pid";
// Define CLI options
add_option_entry("nofork",
@@ -47,6 +48,10 @@ namespace firewalld
add_option_entry("nopid",
"Disable writing pid file and don't check for existing.",
no_pid);
+ add_option_entry("pid",
+ "Write PID to the specified file.",
+ SLOT(*this, &CLIOptionGroup::on_option_arg_string),
+ OptionEntry::FLAG_FILENAME);
add_option_entry("config",
"Load configuration from the specified file.",
SLOT(*this, &CLIOptionGroup::on_option_arg_string),
@@ -94,6 +99,11 @@ namespace firewalld
VLOG(2) << "Using command-line specified configuration file path: "
<< config_path;
}
+ if (option_name == "--pid") {
+ pid_path = value;
+ VLOG(2) << "Using command-line specified PID file path: " <<
pid_path;
+ }
+
return true;
}
diff --git a/src/Daemon/CLI.hpp b/src/Daemon/CLI.hpp
index 9dc478e..7ab0f7e 100644
--- a/src/Daemon/CLI.hpp
+++ b/src/Daemon/CLI.hpp
@@ -36,6 +36,7 @@ namespace firewalld
bool debug_gc;
int debug_level;
UString config_path;
+ UString pid_path;
private:
// Add a long option entry associated with a variable
diff --git a/src/Daemon/main.cpp b/src/Daemon/main.cpp
index 28a7d5c..eb41c45 100644
--- a/src/Daemon/main.cpp
+++ b/src/Daemon/main.cpp
@@ -91,7 +91,7 @@ int main(int argc, char *argv[])
}
// Write PID file
if (!option_grp.no_pid) {
- if (!writePID("/tmp/firewalld.pid")) {
+ if (!writePID(option_grp.pid_path)) {
firewalld_exit(EXIT_FAILURE);
}
}