[Aggregator] Use pthread_cleanup*

This commit is contained in:
Matteo Cypriani 2011-03-24 10:29:42 +01:00
parent 2289e0ef9f
commit a3f0fb4130
1 changed files with 7 additions and 4 deletions

View File

@ -501,6 +501,7 @@ void* monitor_requests(void *NULL_value)
owl_create_udp_trx_socket(cfg_getstr(cfg, "positioner_ip"),
cfg_getint(cfg, "positioner_port"),
&serv, &client) ;
pthread_cleanup_push(&owl_close_fd, &sockfd) ;
/* Open output file */
if (strcmp("-", cfg_getstr(cfg, "output_file")) == 0)
@ -515,6 +516,7 @@ void* monitor_requests(void *NULL_value)
fd = stdout ; // we fail back to stdout.
}
}
pthread_cleanup_push(&owl_close_file, &fd) ;
while (run)
{
@ -652,9 +654,8 @@ void* monitor_requests(void *NULL_value)
}
/* Close output file & socket */
if (fclose(fd) != 0)
perror("Error closing output file") ;
close(sockfd) ;
pthread_cleanup_pop(1) ;
pthread_cleanup_pop(1) ;
pthread_exit(NULL_value) ;
}
@ -830,6 +831,7 @@ void* listen_for_aps(void *NULL_value)
" listeners") ;
exit(ERR_CREATING_SOCKET) ;
}
pthread_cleanup_push(&owl_close_fd, &listen_sockfd) ;
while (run)
{
@ -853,7 +855,8 @@ void* listen_for_aps(void *NULL_value)
update_ap(message.ap_mac_addr_bytes, ap_ip_addr) ;
}
close(listen_sockfd) ;
/* Close the socket */
pthread_cleanup_pop(1) ;
pthread_exit(NULL_value) ;
}