]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
ha: Make path to FIFO configurable and fallback to configured piddir piddir-config
authorTobias Brunner <tobias@strongswan.org>
Fri, 22 May 2015 14:00:43 +0000 (16:00 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 29 May 2015 12:17:01 +0000 (14:17 +0200)
conf/plugins/ha.opt
src/libcharon/plugins/ha/ha_ctl.c

index 77d5b788805d94c9905170a02b5ed7d553681e2b..1d251a222a28cc0fdc06026a2958b60bea5164c4 100644 (file)
@@ -3,6 +3,10 @@ charon.plugins.ha.autobalance = 0
        Set to 0 to disable.
 
 charon.plugins.ha.fifo_interface = yes
+       Enable HA FIFO interface to change segment responsibility.
+
+charon.plugins.ha.fifo
+       Path of the HA FIFO (named pipe).
 
 charon.plugins.ha.heartbeat_delay = 1000
 
index a95499742f0284c619937c2898b7754011956fd0..c507845546c483222aedcc33417a01165152f76f 100644 (file)
@@ -13,8 +13,8 @@
  * for more details.
  */
 
-#include "ha_ctl.h"
-
+#define _GNU_SOURCE /* for asprintf() */
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/select.h>
 #include <unistd.h>
 #include <errno.h>
 
+#include "ha_ctl.h"
+
 #include <threading/thread.h>
 #include <processing/jobs/callback_job.h>
 
-#define HA_FIFO IPSEC_PIDDIR "/charon.ha"
+#define HA_FIFO_NAME "charon.ha"
+#define HA_FIFO IPSEC_PIDDIR "/" HA_FIFO_NAME
 
 typedef struct private_ha_ctl_t private_ha_ctl_t;
 
@@ -48,6 +51,11 @@ struct private_ha_ctl_t {
         * Resynchronization message cache
         */
        ha_cache_t *cache;
+
+       /**
+        * Path to FIFO file
+        */
+       char* fifo;
 };
 
 /**
@@ -61,7 +69,7 @@ static job_requeue_t dispatch_fifo(private_ha_ctl_t *this)
        u_int segment;
 
        oldstate = thread_cancelability(TRUE);
-       fifo = open(HA_FIFO, O_RDONLY);
+       fifo = open(this->fifo, O_RDONLY);
        thread_cancelability(oldstate);
        if (fifo == -1)
        {
@@ -100,6 +108,7 @@ static job_requeue_t dispatch_fifo(private_ha_ctl_t *this)
 METHOD(ha_ctl_t, destroy, void,
        private_ha_ctl_t *this)
 {
+       free(this->fifo);
        free(this);
 }
 
@@ -119,17 +128,33 @@ ha_ctl_t *ha_ctl_create(ha_segments_t *segments, ha_cache_t *cache)
                .cache = cache,
        );
 
-       if (access(HA_FIFO, R_OK|W_OK) != 0)
+       this->fifo = lib->settings->get_str(lib->settings, "%s.plugins.ha.fifo",
+                                                                               NULL, lib->ns);
+       if (this->fifo)
+       {
+               this->fifo = strdup(this->fifo);
+       }
+       else
+       {
+               if (asprintf(&this->fifo, "%s/" HA_FIFO_NAME,
+                                        lib->settings->get_str(lib->settings, "%s.piddir",
+                                                                                       IPSEC_PIDDIR, lib->ns)) < 0)
+               {
+                       this->fifo = strdup(HA_FIFO);
+               }
+       }
+
+       if (access(this->fifo, R_OK|W_OK) != 0)
        {
                old = umask(S_IRWXO);
-               if (mkfifo(HA_FIFO, S_IRUSR | S_IWUSR) != 0)
+               if (mkfifo(this->fifo, S_IRUSR | S_IWUSR) != 0)
                {
                        DBG1(DBG_CFG, "creating HA FIFO %s failed: %s",
-                                HA_FIFO, strerror(errno));
+                                this->fifo, strerror(errno));
                }
                umask(old);
        }
-       if (chown(HA_FIFO, lib->caps->get_uid(lib->caps),
+       if (chown(this->fifo, lib->caps->get_uid(lib->caps),
                          lib->caps->get_gid(lib->caps)) != 0)
        {
                DBG1(DBG_CFG, "changing HA FIFO permissions failed: %s",