]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
swanctl: Terminate --monitor-sa command if daemon closes connection
authorTobias Brunner <tobias@strongswan.org>
Thu, 26 Jan 2023 10:17:30 +0000 (11:17 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 22 Feb 2023 10:44:14 +0000 (11:44 +0100)
src/swanctl/commands/list_sas.c

index 8102eb10a8399889c1978284ebfa1cc470e27270..6989533abd27bd67767d787670fd01fe7ee06f8e 100755 (executable)
@@ -452,10 +452,19 @@ static int list_sas(vici_conn_t *conn)
        return 0;
 }
 
+CALLBACK(close_cb, void,
+       int *ret)
+{
+       fprintf(stderr, "connection closed\n");
+       *ret = ECONNRESET;
+       kill(0, SIGTERM);
+}
+
 static int monitor_sas(vici_conn_t *conn)
 {
        command_format_options_t format = COMMAND_FORMAT_NONE;
        char *arg;
+       int ret = 0;
 
        while (TRUE)
        {
@@ -476,6 +485,9 @@ static int monitor_sas(vici_conn_t *conn)
                }
                break;
        }
+
+       vici_on_close(conn, close_cb, &ret);
+
        if (vici_register(conn, "ike-updown", list_cb, &format) != 0)
        {
                fprintf(stderr, "registering for IKE_SAs failed: %s\n",
@@ -491,9 +503,11 @@ static int monitor_sas(vici_conn_t *conn)
 
        wait_sigint();
 
-       fprintf(stderr, "disconnecting...\n");
-
-       return 0;
+       if (!ret)
+       {
+               fprintf(stderr, "disconnecting...\n");
+       }
+       return ret;
 }
 
 /**