summaryrefslogtreecommitdiffstats
path: root/plugin/firewall/eurephiafw.c
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2010-11-26 22:05:28 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2010-11-26 22:05:28 +0100
commit525d75316848f79208101e48a54e21396464c98b (patch)
tree9475b2a3821d317a55ad118903839fed163e10d7 /plugin/firewall/eurephiafw.c
parent5581ba10af35b94e750596312a9782255084aaeb (diff)
downloadeurephia-525d75316848f79208101e48a54e21396464c98b.tar.gz
eurephia-525d75316848f79208101e48a54e21396464c98b.tar.xz
eurephia-525d75316848f79208101e48a54e21396464c98b.zip
Move daemonize() code to be called in the firewall child thread only
The eurephia plug-in would daemonize the OpenVPN process by calling daemonize() too early. This patch renames daemoinze() to efw_daemonize() and calls it only in the firewall child process. Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Diffstat (limited to 'plugin/firewall/eurephiafw.c')
-rw-r--r--plugin/firewall/eurephiafw.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/plugin/firewall/eurephiafw.c b/plugin/firewall/eurephiafw.c
index 12fb697..9ae126e 100644
--- a/plugin/firewall/eurephiafw.c
+++ b/plugin/firewall/eurephiafw.c
@@ -130,12 +130,35 @@ int eFW_load(eurephiaCTX *ctx, const char *intf) {
/**
+ * daemonize the firewall thread if "daemon" environment variable is set.
+ * preserves stderr access after being daemonized, but
+ * only if "daemon_log_direct" environment variable is set.
+ *
+ * @param ctx eurephiaCTX - Used for error logging only
+ * @param logdir Set to 1 if logging should be redirected
+ */
+static void efw_daemonize(eurephiaCTX *ctx, const int logredir)
+{
+ int fd = -1;
+ if( logredir ) {
+ fd = dup (2);
+ }
+ if( daemon(0, 0) < 0 ) {
+ eurephia_log(ctx, LOG_WARNING, 0, "efw_daemonize() failed");
+ } else if( fd >= 3 ) {
+ dup2(fd, 2);
+ close(fd);
+ }
+}
+
+
+/**
* Starts the firewall thread. It is started as a separate process, to make sure it will run with
* root privileges.
*
* @param ctx eurephiaCTX
*/
-void eFW_StartFirewall(eurephiaCTX *ctx) {
+void eFW_StartFirewall(eurephiaCTX *ctx, const int daemon, const int logredir) {
struct mq_attr mqattr;
eurephiaCTX *shadowctx = NULL;
eFWupdateRequest updreq;
@@ -220,6 +243,9 @@ void eFW_StartFirewall(eurephiaCTX *ctx) {
}
switch( ctx->fwcfg->fwproc_pid ) {
case 0: // Child process
+ if( daemon ) {
+ efw_daemonize(ctx, logredir);
+ }
eDBdisconnect(ctx);
eFW_RunFirewall(&(*ctx->fwcfg).thrdata);
exit(-1); // If our child process exits abnormally.