]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
starter: Make piddir configurable similar to daemon name
authorTobias Brunner <tobias@strongswan.org>
Tue, 19 May 2015 13:21:48 +0000 (15:21 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 29 May 2015 12:17:00 +0000 (14:17 +0200)
conf/options/starter.opt
src/starter/files.h
src/starter/invokecharon.c
src/starter/starter.c
src/starter/starterstroke.c

index 54689e976034401b698c6d6b1a8cce13269354af..3b552b4c7ead2fa3572427873ff57429f7551f01 100644 (file)
@@ -6,3 +6,6 @@ starter.load =
 
 starter.load_warning = yes
        Disable charon plugin load option warning.
+
+starter.piddir = ${piddir}
+       Directory for PID and UNIX socket files.
index 76cdaa986379dfbd5cc06cae7e1c46e121a927d8..2e6f1692a45160f6fca512f545da46fd0bff8a02 100644 (file)
 #define CONFIG_FILE     IPSEC_CONFDIR "/ipsec.conf"
 #define SECRETS_FILE    IPSEC_CONFDIR "/ipsec.secrets"
 
-#define CHARON_CTL_FILE IPSEC_PIDDIR "/charon.ctl"
-
 extern char *daemon_name;
 extern char *cmd;
+extern char *piddir;
 extern char *pid_file;
 
-#define DYNIP_DIR       IPSEC_PIDDIR "/dynip"
-
 #endif /* _STARTER_FILES_H_ */
 
index 5d95305cb251714d1e793e32b0686c333595c39b..adbd3417cd64caea0fd4cea9351515b69616ec86 100644 (file)
@@ -179,7 +179,6 @@ int starter_start_charon (starter_config_t *cfg, bool no_fork, bool attach_gdb)
        }
        else
        {
-               unlink(CHARON_CTL_FILE);
                _stop_requested = 0;
 
                pid = fork();
index a1929892309ac67a680bb3adb45506c6477c6fa6..d6697bb51cf387f97e88353f1ca68c7552af1a42 100644 (file)
@@ -57,6 +57,7 @@ static const char* pid_file_default = IPSEC_PIDDIR "/charon.pid";
 static const char* starter_pid_file_default = IPSEC_PIDDIR "/starter.pid";
 
 char *daemon_name = NULL;
+char *piddir = NULL;
 char *cmd = NULL;
 char *pid_file = NULL;
 char *starter_pid_file = NULL;
@@ -363,12 +364,12 @@ static bool set_daemon_name()
                 cmd = (char*)cmd_default;
        }
 
-       if (asprintf(&pid_file, IPSEC_PIDDIR"/%s.pid", daemon_name) < 0)
+       if (asprintf(&pid_file, "%s/%s.pid", piddir, daemon_name) < 0)
        {
                 pid_file = (char*)pid_file_default;
        }
 
-       if (asprintf(&starter_pid_file, IPSEC_PIDDIR"/starter.%s.pid",
+       if (asprintf(&starter_pid_file, "%s/starter.%s.pid", piddir,
                                 daemon_name) < 0)
        {
                 starter_pid_file = (char*)starter_pid_file_default;
@@ -399,7 +400,7 @@ static void usage(char *name)
 {
        fprintf(stderr, "Usage: starter [--nofork] [--auto-update <sec>]\n"
                        "               [--debug|--debug-more|--debug-all|--nolog]\n"
-                       "               [--attach-gdb] [--daemon <name>]\n"
+                       "               [--attach-gdb] [--daemon <name>] [--piddir <dir>]\n"
                        "               [--conf <path to ipsec.conf>]\n");
        exit(LSB_RC_INVALID_ARGUMENT);
 }
@@ -468,6 +469,10 @@ int main (int argc, char **argv)
                {
                        daemon_name = argv[++i];
                }
+               else if (streq(argv[i], "--piddir") && i+1 < argc)
+               {
+                       piddir = argv[++i];
+               }
                else if (streq(argv[i], "--conf") && i+1 < argc)
                {
                        config_file = argv[++i];
@@ -482,6 +487,11 @@ int main (int argc, char **argv)
                }
        }
 
+       if (!piddir)
+       {
+               piddir = lib->settings->get_str(lib->settings,
+                                                                               "starter.piddir", IPSEC_PIDDIR);
+       }
        if (!set_daemon_name())
        {
                DBG1(DBG_APP, "unable to set daemon name");
index 79a92cdad493e000b3ba4b9b17dad6c9aa4c5643..9a9911bbb22d29f57fdb4bed12318a0cdaa5b102 100644 (file)
@@ -14,6 +14,8 @@
  * for more details.
  */
 
+#define _GNU_SOURCE /* for asprintf() */
+#include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
@@ -76,7 +78,7 @@ static void push_string_impl(stroke_msg_t **msg, size_t offset, char *string)
 static int send_stroke_msg(stroke_msg_t *msg)
 {
        stream_t *stream;
-       char *uri, buffer[64];
+       char *uri, *uri_default, buffer[64];
        int count;
 
        if (msg->length == UINT16_MAX)
@@ -89,15 +91,21 @@ static int send_stroke_msg(stroke_msg_t *msg)
        /* starter is not called from commandline, and therefore absolutely silent */
        msg->output_verbosity = -1;
 
+       if (asprintf(&uri_default, "unix://%s/charon.ctl", piddir) < 0)
+       {
+               uri_default = strdup("unix://" IPSEC_PIDDIR "/charon.ctl");
+       }
        uri = lib->settings->get_str(lib->settings, "%s.plugins.stroke.socket",
-                                                                "unix://" CHARON_CTL_FILE, daemon_name);
+                                                                uri_default, daemon_name);
        stream = lib->streams->connect(lib->streams, uri);
        if (!stream)
        {
                DBG1(DBG_APP, "failed to connect to stroke socket '%s'", uri);
+               free(uri_default);
                free(msg);
                return -1;
        }
+       free(uri_default);
 
        if (!stream->write_all(stream, msg, msg->length))
        {