From ede0f95e515977db0980955f46da8c3fb4dd3df3 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Thu, 15 Jul 2021 15:07:28 +0200 Subject: [PATCH 1/6] Added retry of sensor connection for performance reports on failure In manage.c in function get_osp_performance_string (..): The installation of the connection to the sensor via osp_connect_with_data (..) and the access to the performance data via osp_get_performance_ext (..) are now retried several times on failure. --- src/manage.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/manage.c b/src/manage.c index 94d333fa8..0c53d78ae 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4006,9 +4006,10 @@ get_osp_performance_string (scanner_t scanner, int start, int end, { char *host, *ca_pub, *key_pub, *key_priv; int port; - osp_connection_t *connection; + osp_connection_t *connection = NULL; osp_get_performance_opts_t opts; gchar *error; + int connection_retry; host = scanner_host (scanner); port = scanner_port (scanner); @@ -4016,7 +4017,14 @@ get_osp_performance_string (scanner_t scanner, int start, int end, key_pub = scanner_key_pub (scanner); key_priv = scanner_key_priv (scanner); - connection = osp_connect_with_data (host, port, ca_pub, key_pub, key_priv); + connection_retry = SCANNER_CONNECTION_RETRY_DEFAULT; + while(connection == NULL && connection_retry > 0) + { + connection = osp_connect_with_data (host, port, + ca_pub, key_pub, key_priv); + connection_retry--; + sleep(1); + } free (host); free (ca_pub); @@ -4031,7 +4039,17 @@ get_osp_performance_string (scanner_t scanner, int start, int end, opts.titles = g_strdup (titles); error = NULL; - if (osp_get_performance_ext (connection, opts, performance_str, &error)) + connection_retry = SCANNER_CONNECTION_RETRY_DEFAULT; + int return_value = 1; + while (return_value > 0 && connection_retry > 0) + { + return_value = osp_get_performance_ext (connection, opts, + performance_str, &error); + connection_retry--; + sleep(1); + } + + if (return_value) { osp_connection_close (connection); g_warning ("Error getting OSP performance report: %s", error); From e4f77afa41d8477f86956d3ebc2c7d9984d9a53c Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 16 Jul 2021 09:09:44 +0200 Subject: [PATCH 2/6] CHANGELOG entry: retry of sensor connection for performance reports --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 215178d4a..2f31b6a35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Fix VTs hash check and add --dump-vt-verification [#1611](https://github.com/greenbone/gvmd/pull/1611) [#1629](https://github.com/greenbone/gvmd/pull/1629) - Fix memory errors in modify_permission [#1613](https://github.com/greenbone/gvmd/pull/1613) +- Fix sensor connection for performance reports on failure [#1633](https://github.com/greenbone/gvmd/pull/1633) [Unreleased]: https://github.com/greenbone/gvmd/compare/v20.8.2...gvmd-20.08 From 50ee82b938d11a5c26f1f983f6a470dcc2c4455b Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Mon, 19 Jul 2021 10:24:18 +0200 Subject: [PATCH 3/6] Improved the structure of the programming in manage.c in manage.c, in function get_osp_performance_string(..): Moved the declaration of the variable "return_value" to the top of the function. --- src/manage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manage.c b/src/manage.c index 0c53d78ae..a3dbf9a35 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4009,7 +4009,7 @@ get_osp_performance_string (scanner_t scanner, int start, int end, osp_connection_t *connection = NULL; osp_get_performance_opts_t opts; gchar *error; - int connection_retry; + int connection_retry, return_value; host = scanner_host (scanner); port = scanner_port (scanner); @@ -4040,7 +4040,7 @@ get_osp_performance_string (scanner_t scanner, int start, int end, error = NULL; connection_retry = SCANNER_CONNECTION_RETRY_DEFAULT; - int return_value = 1; + return_value = 1; while (return_value > 0 && connection_retry > 0) { return_value = osp_get_performance_ext (connection, opts, From 3fa72180d0df7b91791678a445ae70df5e0edd22 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Mon, 19 Jul 2021 12:52:59 +0200 Subject: [PATCH 4/6] Amended the setting of the value "connection_retry". In manage.c, in function get_osp_performance_string (..): Replaced the assignment of value "connection_retry = SCANNER_CONNECTION_RETRY_DEFAULT;" by "connection_retry = get_scanner_connection_retry();". --- src/manage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manage.c b/src/manage.c index a3dbf9a35..6cda4812c 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4017,7 +4017,7 @@ get_osp_performance_string (scanner_t scanner, int start, int end, key_pub = scanner_key_pub (scanner); key_priv = scanner_key_priv (scanner); - connection_retry = SCANNER_CONNECTION_RETRY_DEFAULT; + connection_retry = get_scanner_connection_retry(); while(connection == NULL && connection_retry > 0) { connection = osp_connect_with_data (host, port, @@ -4039,7 +4039,7 @@ get_osp_performance_string (scanner_t scanner, int start, int end, opts.titles = g_strdup (titles); error = NULL; - connection_retry = SCANNER_CONNECTION_RETRY_DEFAULT; + connection_retry = get_scanner_connection_retry(); return_value = 1; while (return_value > 0 && connection_retry > 0) { From 2d13c54355e55b32b5e535633161625a5c839904 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Mon, 19 Jul 2021 14:36:53 +0200 Subject: [PATCH 5/6] Solved a formatting issue. In manage.c in function get_osp_performance_string (..): Amended the formatting of a while statement and the calls of get_scanner_connection_retry (). --- src/manage.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/manage.c b/src/manage.c index 6cda4812c..7c634394b 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4017,8 +4017,8 @@ get_osp_performance_string (scanner_t scanner, int start, int end, key_pub = scanner_key_pub (scanner); key_priv = scanner_key_priv (scanner); - connection_retry = get_scanner_connection_retry(); - while(connection == NULL && connection_retry > 0) + connection_retry = get_scanner_connection_retry (); + while (connection == NULL && connection_retry > 0) { connection = osp_connect_with_data (host, port, ca_pub, key_pub, key_priv); @@ -4039,7 +4039,7 @@ get_osp_performance_string (scanner_t scanner, int start, int end, opts.titles = g_strdup (titles); error = NULL; - connection_retry = get_scanner_connection_retry(); + connection_retry = get_scanner_connection_retry (); return_value = 1; while (return_value > 0 && connection_retry > 0) { From 0d06084ce3f0a4f5324324eab3828cfaa7540562 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Mon, 19 Jul 2021 16:12:37 +0200 Subject: [PATCH 6/6] Amended the logic of the connection retries. In manage.c, in function get_osp_performance_string (..): Rebuild the logic of the connection retries for osp_connect_with_data (..) and osp_get_performance_ext (..) slightly. --- src/manage.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/manage.c b/src/manage.c index 7c634394b..09d04c257 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4018,12 +4018,13 @@ get_osp_performance_string (scanner_t scanner, int start, int end, key_priv = scanner_key_priv (scanner); connection_retry = get_scanner_connection_retry (); + connection = osp_connect_with_data (host, port, ca_pub, key_pub, key_priv); while (connection == NULL && connection_retry > 0) { + sleep(1); connection = osp_connect_with_data (host, port, ca_pub, key_pub, key_priv); connection_retry--; - sleep(1); } free (host); @@ -4040,13 +4041,14 @@ get_osp_performance_string (scanner_t scanner, int start, int end, error = NULL; connection_retry = get_scanner_connection_retry (); - return_value = 1; - while (return_value > 0 && connection_retry > 0) + return_value = osp_get_performance_ext (connection, opts, + performance_str, &error); + while (return_value != 0 && connection_retry > 0) { + sleep(1); return_value = osp_get_performance_ext (connection, opts, performance_str, &error); connection_retry--; - sleep(1); } if (return_value)