EPICS Home

Experimental Physics and Industrial Control System


 
2002  2003  2004  2005  2006  2007  2008  <20092010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  <20092010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: mantis 354 - ca_host_name returns empty string if dns server hasnt responded yet?
From: "Jeff Hill" <[email protected]>
To: "Dirk D. Harper" <[email protected]>, "'Ernest L. Williams Jr.'" <[email protected]>
Cc: "'Core-Talk'" <[email protected]>
Date: Mon, 3 Aug 2009 10:41:27 -0600

All,

 

I closed out mantis 354, “ca_host_name returns empty string if dns server hasn’t responded yet”, because it appears to be a duplicate of mantis 312 (fixed in R3.14.10). If you see evidence that I have come to this conclusion in error please be vocal.

 

----------------------------------------------Mantis 354--------------------------------------------------------

 

From Ernest (and Dirk):

That does not work for me.

Only when I turn on "nscd" on my linux systems do things work reliably.
When nscd is not running most of the time I get the empty string.

Thanks,
Ernest

Jeff Hill wrote:
> Dirk,
>
>
>> I think the IP address would be better than an empty string.
>>
>
> TBOMK, it does return the dotted IP address as a string if the DNS transaction hasn't completed yet. Let me know if that isn’t the case.
>
> unsigned hostNameCache::getName (
> char * pBuf, unsigned bufSize ) const {
> if ( bufSize == 0u ) {
> return 0u;
> }
> epicsGuard < epicsMutex > guard ( this->mutex );
> if ( this->nameLength > 0u ) {
> if ( this->nameLength < bufSize ) {
> strcpy ( pBuf, this->hostNameBuf );
> return this->nameLength;
> }
> else {
> unsigned reducedSize = bufSize - 1u;
> strncpy ( pBuf, this->hostNameBuf, reducedSize );
> pBuf [ reducedSize ] = '

 

 

--------------------------------------------------Mantis 312---------------------------------------------

host name is returned empty for a brief window in time after the channel connects Description From Ernest:

> I thought cainfo would return the host:
>
> [iocegr@lcls-builder ~]$ cainfo PCAV:IN20:365:TEMP2
> PCAV:IN20:365:TEMP2
> State: connected
> Host:
> Access: read, write
> Data type: DBR_DOUBLE (native: DBF_DOUBLE)
> Element count: 1
>
>
> probe returns the host of the PV just fine.
>
> I tried this with EPICS R3.14.8.2 and also EPICS R3.14.9 as well.
>

 

I reproduced this here (on windows using excas as the server). I had some mixed results. See below. I'm not certain what is going on, but here is a possible explanation. In R3.14 all DNS queries are handled by an independent thread, and their results are returned asynchronously via callbacks. This makes CA immune to lockups when DNS goes down. I suspect that the host name is set to empty until this query comes back. So if you ask right away after the channel connects you get an empty host name. This could possibly be improved by copying the dotted IP address into the host name string - to be used until the dns name comes back.

 

I applied this patch.

cvs diff -wb -- hostNameCache.cpp (in directory C:hillR3.14.dll_hell_fixepicsbasesrcca)
Index: hostNameCache.cpp
===================================================================
RCS file: /net/phoebus/epicsmgr/cvsroot/epics/base/src/ca/hostNameCache.cpp,v
retrieving revision 1.17.2.4
diff -u -b -w -b -r1.17.2.4 hostNameCache.cpp
--- hostNameCache.cpp 19 Oct 2004 20:24:35 -0000 1.17.2.4
+++ hostNameCache.cpp 22 Sep 2008 20:15:43 -0000
@@ -33,6 +33,9 @@
const osiSockAddr & addr, ipAddrToAsciiEngine & engine ) :
dnsTransaction ( engine.createTransaction() ), nameLength ( 0 )
{
+ sockAddrToDottedIP ( &addr.sa, hostNameBuf, sizeof ( hostNameBuf ) );
+ hostNameBuf[ sizeof ( hostNameBuf ) - 1 ] = '
';
+ nameLength = strlen ( hostNameBuf );
this->dnsTransaction.ipAddrToAscii ( addr, *this );
}

@@ -49,12 +52,15 @@
void hostNameCache::transactionComplete ( const char * pHostNameIn )
{
epicsGuard < epicsMutex > guard ( this->mutex );
- if ( this->nameLength == 0u ) {
- strncpy ( this->hostNameBuf, pHostNameIn, sizeof ( this->hostNameBuf ) );
+ // a few legacy clients have a direct pointer to this buffer so we
+ // set the entrire string to nill terminators before we start copying
+ // in the name (this reduces the chance that another thread will see
+ // garbage characters).
+ strncpy ( this->hostNameBuf, "", sizeof ( this->hostNameBuf ) );
+ strncpy ( this->hostNameBuf, pHostNameIn, sizeof ( this->hostNameBuf ) - 1 );
this->hostNameBuf[ sizeof ( this->hostNameBuf ) - 1 ] = '
';
this->nameLength = strlen ( this->hostNameBuf );
}
-}

unsigned hostNameCache::getName (
char * pBuf, unsigned bufSize ) const

 

 

Jeff
______________________________________________________
Jeffrey O. Hill           Email       
[email protected]
LANL MS H820              Voice        505 665 1831
Los Alamos NM 87545 USA   FAX          505 665 5107

 

Message content: TSPA

 


Navigate by Date:
Prev: Re: Base R3.14.11-pre1 available for testing Andrew Johnson
Next: RE: GW status Jeff Hill
Index: 2002  2003  2004  2005  2006  2007  2008  <20092010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: epicsSnPrintf is very slow when converting string arrays in GDD's aitConvert.cc Jeff Hill
Next: RE: GW status Jeff Hill
Index: 2002  2003  2004  2005  2006  2007  2008  <20092010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024