X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Frtc_static.c;h=15fe56720f016622fa7097a765715959fc5baa0c;hb=05850e0815095c029ecff43ac8e0983f2fba4fb6;hp=2deef8ee02cb1584fb8668fd9ab8befcf02a67f4;hpb=5ec64c5253b3b7611ec69cc1487989fae45eca26;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/common/src/rtc_static.c b/src/rmr/common/src/rtc_static.c index 2deef8e..15fe567 100644 --- a/src/rmr/common/src/rtc_static.c +++ b/src/rmr/common/src/rtc_static.c @@ -76,15 +76,18 @@ static void* rtc_file( void* vctx ) { ctx->flags |= CFL_NO_RTACK; // no attempt to ack when reading from a file while( 1 ) { if( vfd >= 0 ) { - wbuf[0] = 0; - lseek( vfd, 0, 0 ); - read( vfd, wbuf, 10 ); - vlevel = atoi( wbuf ); + memset( wbuf, 0, sizeof( char ) * 11 ); + if( lseek( vfd, 0, SEEK_SET ) == 0 && read( vfd, wbuf, 10 ) > 0 ) { + vlevel = atoi( wbuf ); + } } read_static_rt( ctx, vlevel ); // seed the route table if one provided if( ctx->shutdown != 0 ) { // allow for graceful termination and unit testing + if( vfd >= 0 ) { + close( vfd ); + } return NULL; } sleep( 60 ); @@ -97,9 +100,10 @@ static int refresh_vlevel( int vfd ) { if( vfd >= 0 ) { // if file is open, read current value rbuf[0] = 0; - lseek( vfd, 0, 0 ); - read( vfd, rbuf, 10 ); - vlevel = atoi( rbuf ); + memset( rbuf, 0, sizeof( char ) * 11 ); + if( lseek( vfd, 0, SEEK_SET ) == 0 && read( vfd, rbuf, 10 ) > 0 ) { + vlevel = atoi( rbuf ); + } } return vlevel;