[Aggregator] Flush the requests' list at exit

Instead of just freeing the requests' list, output every request and
free the list at the same time.
This commit is contained in:
Matteo Cypriani 2013-06-12 17:11:49 -04:00
parent 47103f3360
commit d9344673b0
3 changed files with 49 additions and 29 deletions

View File

@ -82,8 +82,6 @@ Work to do in OwlPS
= Aggregator =
- Flush the requests' list when exiting.
- Rename ap_check_interval to something more meaningful
(something like autocalibration_order_interval).

View File

@ -111,12 +111,14 @@ int read_loop(int sockfd) ;
void got_request(owl_captured_request request) ;
void* monitor_requests(void *NULL_value) ;
void flush_request_list(FILE *const stream,
const int sockfd,
const struct sockaddr_in *const serv) ;
void output_request(request_list *const request_ptr,
FILE *const stream,
const int sockfd,
const struct sockaddr_in *const serv) ;
void free_request_list(void) ;
#ifndef NDEBUG
void print_request_list(void) ;
void print_request_info(request_info_list *info) ;

View File

@ -180,7 +180,7 @@ int main(int argc, char **argv)
if (sockfd >= 0)
close(sockfd) ; // Close socket
free_request_list() ;
assert(requests == NULL) ;
free_ap_list() ;
cfg_free(cfg) ; // Clean configuration
// Destroy semaphores:
@ -649,6 +649,13 @@ void got_request(owl_captured_request request)
/* Add it in the list */
sem_wait(&lock_requests) ;
// Make sure we are still running once we've got the lock
if (! owl_run)
{
free(tmp_info) ;
goto end ;
}
tmp_request = requests ;
if (requests == NULL) // If the request list does not exist,
{
@ -823,6 +830,7 @@ void* monitor_requests(void *NULL_value)
}
pthread_cleanup_push(&owl_close_file, &stream) ;
/* Main loop */
while (owl_run)
{
request_prev = NULL ;
@ -890,6 +898,9 @@ void* monitor_requests(void *NULL_value)
owl_msleep(cfg_getint(cfg, "check_interval")) ;
}
/* Flush the requests' list prior to return */
flush_request_list(stream, sockfd, &serv) ;
/* Close output file & socket */
pthread_cleanup_pop(1) ;
pthread_cleanup_pop(1) ;
@ -898,6 +909,40 @@ void* monitor_requests(void *NULL_value)
}
/*
* Prints and sends all the requests in the requests' list and frees
* the list.
*/
void flush_request_list(FILE *const stream,
const int sockfd,
const struct sockaddr_in *const serv)
{
request_list *next_request ;
if (VERBOSE_CHATTERBOX)
fprintf(stderr, "Flushing the requests' list...") ;
sem_wait(&lock_requests) ;
while (requests)
{
// If the request was not treated already, we print its data
if (requests->info != NULL)
output_request(requests, stream, sockfd, serv) ;
// Free the current request and jump to the next
next_request = requests->next ;
free(requests) ;
requests = next_request ;
}
sem_post(&lock_requests) ;
if (VERBOSE_CHATTERBOX)
fprintf(stderr, " Requests' list flushed.\n") ;
}
/*
* Prints a request to the output file and sends it to the aggregation
* server. The request's info field is deleted.
@ -1002,31 +1047,6 @@ void output_request(request_list *const request_ptr,
/*
* Empties the request list.
* Note that this function does not use lock_requests, so it should not
* be called in a concurrent context.
*/
void free_request_list()
{
request_list *next_request ;
request_info_list *next_request_info ;
while (requests != NULL)
{
while (requests->info != NULL)
{
next_request_info = requests->info->next ;
free(requests->info) ;
requests->info = next_request_info ;
}
next_request = requests->next ;
free(requests) ;
requests = next_request ;
}
}
#ifndef NDEBUG
/*
* Prints the request list.