Skip to content

Commit

Permalink
Fix finish_signal_on_queue
Browse files Browse the repository at this point in the history
Check for the signal in the whole items under the key, instead of
just checking the the last item.
  • Loading branch information
jjnicola committed Mar 19, 2021
1 parent 7d38724 commit 2f2b20e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
[#447](https://github.com/greenbone/gvm-libs/pull/447)
[#451](https://github.com/greenbone/gvm-libs/pull/451)

### Fixed
- Fix finish_signal_on_queue for boreas. [#464](https://github.com/greenbone/gvm-libs/pull/464)

### Removed
- Remove handling of severity class from auth [#402](https://github.com/greenbone/gvm-libs/pull/402)
- Remove version from the nvticache name. [#386](https://github.com/greenbone/gvm-libs/pull/386)
Expand Down
34 changes: 23 additions & 11 deletions boreas/boreas_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,38 @@ put_host_on_queue (kb_t kb, char *addr_str)
}

/**
* @brief Checks if the finish signal is already set as last item in the queue.
* @brief Checks if the finish signal is already set.
*
* @param main_kb kb to use
* @return 1 if it is already set. 0 otherwise.
*/
int
finish_signal_on_queue (kb_t main_kb)
{
struct kb_item *last_queue_item;
int ret;

ret = 0;
last_queue_item =
kb_item_get_single (main_kb, ALIVE_DETECTION_QUEUE, KB_TYPE_STR);
static gboolean fin_msg_already_on_queue = FALSE;
struct kb_item *queue_items = NULL;
int ret = 0;

if (last_queue_item && (last_queue_item->type == KB_TYPE_STR)
&& (!g_strcmp0 (last_queue_item->v_str, ALIVE_DETECTION_FINISHED)))
ret = 1;
if (fin_msg_already_on_queue)
return 1;

kb_item_free (last_queue_item);
/* Check if it was already set throught the whole items under the key.
If so, set the static variable to avoid quering redis unnecessarily. */
queue_items =
kb_item_get_all (main_kb, ALIVE_DETECTION_QUEUE);
if (queue_items)
{
while (queue_items)
{
if (!g_strcmp0 (queue_items->v_str, ALIVE_DETECTION_FINISHED))
{
fin_msg_already_on_queue = TRUE;
ret = 1;
}
queue_items = queue_items->next;
}
kb_item_free (queue_items);
}
return ret;
}

Expand Down

0 comments on commit 2f2b20e

Please sign in to comment.