From bc5d347bb28e7dad682e2a1534db1a64c6fd80c0 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 1 Aug 2023 14:31:31 -0500 Subject: [PATCH] Call perror() before close(), add detail to messages --- modules/libcom/RTEMS/epicsNtp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/libcom/RTEMS/epicsNtp.c b/modules/libcom/RTEMS/epicsNtp.c index 873ee836f..2098e2783 100644 --- a/modules/libcom/RTEMS/epicsNtp.c +++ b/modules/libcom/RTEMS/epicsNtp.c @@ -37,7 +37,7 @@ int epicsNtpGetTime(char *ntpIp, struct timespec *now) sockfd = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); // Create a UDP socket. if ( sockfd < 0 ) { - perror( "epicsNtpGetTime" ); + perror( "epicsNtpGetTime creating socket" ); return -1; } @@ -51,24 +51,24 @@ int epicsNtpGetTime(char *ntpIp, struct timespec *now) // Call up the server using its IP address and port number. if ( connect( sockfd, ( struct sockaddr * ) &serv_addr, sizeof( serv_addr) ) < 0 ) { + perror( "epicsNtpGetTime connecting socket" ); close( sockfd ); - perror( "epicsNtpGetTime" ); return -1; } // Send it the NTP packet it wants. If n == -1, it failed. n = write( sockfd, ( char* ) &packet, sizeof( ntp_packet ) ); if ( n < 0 ) { + perror( "epicsNtpGetTime sending NTP request" ); close( sockfd ); - perror( "epicsNtpGetTime" ); return -1; } -// Wait and receive the packet back from the server. If n == -1, it failed. + // Wait and receive the packet back from the server. If n == -1, it failed. n = read( sockfd, ( char* ) &packet, sizeof( ntp_packet ) ); if ( n < 0 ) { + perror( "epicsNtpGetTime reading NTP reply" ); close( sockfd ); - perror( "epicsNtpGetTime" ); return -1; }