Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output the progress once more when the whole scan process finished #828

Merged
merged 3 commits into from Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/monitor.c
Expand Up @@ -16,6 +16,7 @@
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -464,12 +465,7 @@ void monitor_init(void)
}
}

void monitor_run(iterator_t *it, pthread_mutex_t *lock)
{
int_status_t *internal_status = xmalloc(sizeof(int_status_t));
export_status_t *export_status = xmalloc(sizeof(export_status_t));

while (!(zsend.complete && zrecv.complete)) {
void export_then_update(int_status_t *internal_status, iterator_t *it, export_status_t *export_status, pthread_mutex_t *lock) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now encapsulated the main functionality within the while loop (which involves obtaining the current scanning status and writing it to a status file) into a separate function called export_then_update. This encapsulation simplifies the logic in monitor_run.

The structure of the while loop remains unchanged. The only addition is to call export_then_update once more after the while loop concludes. This ensures that the status file is updated based on the latest state.

If there are any concerns regarding the style or functionality of the code modifications I've made, please let me know. Your feedback is greatly appreciated! @droe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does address the race I pointed out. No other concerns, I'm not a reviewer tho.

update_pcap_stats(lock);
export_stats(internal_status, export_status, it);
log_drop_warnings(export_status);
Expand All @@ -487,8 +483,21 @@ void monitor_run(iterator_t *it, pthread_mutex_t *lock)
if (status_fd) {
update_status_updates_file(export_status, status_fd);
}
}

void monitor_run(iterator_t *it, pthread_mutex_t *lock)
{
int_status_t *internal_status = xmalloc(sizeof(int_status_t));
export_status_t *export_status = xmalloc(sizeof(export_status_t));

// wait for the scanning process to finish
while (!(zsend.complete && zrecv.complete)) {
export_then_update(internal_status, it, export_status, lock);
sleep(UPDATE_INTERVAL);
}
// final update
export_then_update(internal_status, it, export_status, lock);

if (!zconf.quiet) {
lock_file(stderr);
fflush(stderr);
Expand Down