X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Frtc_static.c;h=b411dbe4fc958eaa9761690dc92887fb8fb5cc3a;hb=05ce11d8c370a66c238b1db3fff1fde4790fa701;hp=cce8ddc205f598a6873ca63d72f1d3e508ef7c03;hpb=c06c626ddf4f45a28a3db3f1afbb7ac87160045f;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 cce8ddc..b411dbe 100644 --- a/src/rmr/common/src/rtc_static.c +++ b/src/rmr/common/src/rtc_static.c @@ -42,6 +42,20 @@ #include #include +static int refresh_vlevel( int vfd ) { + int vlevel = 0; + char rbuf[128]; + + if( vfd >= 0 ) { // if file is open, read current value + rbuf[0] = 0; + lseek( vfd, 0, 0 ); + read( vfd, rbuf, 10 ); + vlevel = atoi( rbuf ); + } + + return vlevel; +} + /* Route Table Collector A side thread which opens a socket and subscribes to a routing table generator. @@ -71,7 +85,7 @@ Buffers received from the route table generator can contain multiple newline terminated records, but each buffer must be less than 4K in length, and the last record in a - buffere may NOT be split across buffers. + buffer may NOT be split across buffers. Other chores: In addition to the primary task of getting, vetting, and installing a new route table, or @@ -113,18 +127,13 @@ static void* rtc( void* vctx ) { if( (ctx = (uta_ctx_t *) vctx) == NULL ) { - fprintf( stderr, "[CRI] rmr_rtc: internal mishap: context passed in was nil\n" ); + rmr_vlog( RMR_VL_CRIT, "rmr_rtc: internal mishap: context passed in was nil\n" ); return NULL; } if( (eptr = getenv( ENV_VERBOSE_FILE )) != NULL ) { vfd = open( eptr, O_RDONLY ); - if( vfd >= 0 ) { - wbuf[0] = 0; - lseek( vfd, 0, 0 ); - read( vfd, wbuf, 10 ); - vlevel = atoi( wbuf ); - } + vlevel = refresh_vlevel( vfd ); } read_static_rt( ctx, vlevel ); // seed the route table if one provided @@ -157,7 +166,7 @@ static void* rtc( void* vctx ) { } if( (pvt_cx = init( port, MAX_RTG_MSG_SZ, FL_NOTHREAD )) == NULL ) { // open a private context - fprintf( stderr, "[CRI] rmr_rtc: unable to initialise listen port for RTG (pvt_cx)\n" ); + rmr_vlog( RMR_VL_CRIT, "rmr_rtc: unable to initialise listen port for RTG (pvt_cx)\n" ); while( TRUE ) { // no listen port, just dump counts now and then sleep( count_delay ); @@ -170,24 +179,24 @@ static void* rtc( void* vctx ) { if( (rcv_fd = rmr_get_rcvfd( pvt_cx )) >= 0 ) { // get the epoll fd for the rtg socket if( rcv_fd < 0 ) { - fprintf( stderr, "[WARN] cannot get epoll fd for rtg session; stats will generate only after update from rt manager\n" ); + rmr_vlog( RMR_VL_WARN, "cannot get epoll fd for rtg session; stats will generate only after update from rt manager\n" ); } else { if( (epfd = epoll_create1( 0 )) < 0 ) { - fprintf( stderr, "[WARN] stats will generate only after rt manager update; unable to create epoll fd for rtg session: %s\n", strerror( errno ) ); + rmr_vlog( RMR_VL_WARN, "stats will generate only after rt manager update; unable to create epoll fd for rtg session: %s\n", strerror( errno ) ); rcv_fd = -1; } else { epe.events = EPOLLIN; epe.data.fd = rcv_fd; if( epoll_ctl( epfd, EPOLL_CTL_ADD, rcv_fd, &epe ) != 0 ) { - fprintf( stderr, "[WARN] stats will generate only after rt manager update; unable to init epoll_ctl: %s\n", strerror( errno ) ); + rmr_vlog( RMR_VL_WARN, "stats will generate only after rt manager update; unable to init epoll_ctl: %s\n", strerror( errno ) ); rcv_fd = -1; } } } } - if( DEBUG ) fprintf( stderr, "[DBUG] rtc thread is running and listening; listening for rtg conns on %s\n", port ); + if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "rtc thread is running and listening; listening for rtg conns on %s\n", port ); free( fport ); // future: if we need to register with the rtg, then build a message and send it through a wormhole here @@ -210,28 +219,26 @@ static void* rtc( void* vctx ) { } if( time( NULL ) > blabber ) { - blabber = time( NULL ) + count_delay; // set next time to blabber, then do so - if( blabber > bump_freq ) { - count_delay = 300; + vlevel = refresh_vlevel( vfd ); + if( vlevel >= 0 ) { // allow it to be forced off with -n in verbose file + blabber = time( NULL ) + count_delay; // set next time to blabber, then do so + if( blabber > bump_freq ) { + count_delay = 300; + } + rt_epcounts( ctx->rtable, ctx->my_name ); } - rt_epcounts( ctx->rtable, ctx->my_name ); } } - if( vfd >= 0 ) { // if file open, check for change to vlevel - wbuf[0] = 0; - lseek( vfd, 0, 0 ); - read( vfd, wbuf, 10 ); - vlevel = atoi( wbuf ); - } + vlevel = refresh_vlevel( vfd ); // ensure it's fresh when we get a message if( msg != NULL && msg->len > 0 ) { payload = msg->payload; mlen = msg->len; // usable bytes in the payload if( vlevel > 1 ) { - fprintf( stderr, "[DBUG] rmr_rtc: received rt message; %d bytes (%s)\n", (int) mlen, msg->payload ); + rmr_vlog( RMR_VL_DEBUG, "rmr_rtc: received rt message; %d bytes (%s)\n", (int) mlen, msg->payload ); } else { - if( DEBUG > 1 || (vlevel > 0) ) fprintf( stderr, "[DBUG] rmr_rtc: received rt message; %d bytes\n", (int) mlen ); + if( DEBUG > 1 || (vlevel > 0) ) rmr_vlog( RMR_VL_DEBUG, "rmr_rtc: received rt message; %d bytes\n", (int) mlen ); } if( pbuf_size <= mlen ) { @@ -257,7 +264,7 @@ static void* rtc( void* vctx ) { } if( vlevel > 1 ) { - fprintf( stderr, "[DBUG] rmr_rtc: processing (%s)\n", curr ); + rmr_vlog( RMR_VL_DEBUG, "rmr_rtc: processing (%s)\n", curr ); } parse_rt_rec( ctx, curr, vlevel ); // parse record and add to in progress table