[OPEN-ILS-DEV] transport_session.c: use of $HOSTNAME

Bill Erickson erickson at esilibrary.com
Sun Mar 9 18:10:48 EDT 2008


Scott McKellar wrote:
> Similar questions apply to two other cases where we look for $HOSTNAME:
>
> 1. osrfChatMkAuthKey(), in osrf_chat.c
>
> 2. osrfSystemBootstrapClientResc(), in osrf_system.c
>
> Scott McKellar
> http://home.swbell.net/mck9/ct/
>
> --- Scott McKellar <mck9 at swbell.net> wrote:
>
>   
>> In session_connect() we have have the following fragment:
>>
>>     /* the first Jabber connect stanza */
>>     char* our_hostname = getenv("HOSTNAME");
>>     size1 = 150 + strlen( server );
>>     char stanza1[ size1 ]; 
>>     snprintf( stanza1, sizeof(stanza1),
>>         "<long message abbreviated here> %s %s",
>>         username, our_hostname );
>>
>> My first observation is that in calculating size1 we presumably
>> should
>> have used strlen(our_hostname), not strlen(server), since server is
>> not included in the formatted stanza that we build.
>>
>> I could fix that myself.  But what I'm writing about is the use of
>> the environmental variable $HOSTNAME.
>>
>> Is there a reason why we don't get the host name by calling
>> gethostname()?
>>
>> Normally the two methods will yield the same result.  The difference
>> is that the user can change the value of $HOSTNAME to anything he
>> likes, or even unset it entirely.  The resulting stanza that we
>> build here will then be different accordingly.  But gethostname() is
>> not affected by changes in $HOSTNAME, as I confirmed by a little
>> experimentation.
>>
>> Unless we want the user to be able to change the contents of this
>> stanza, I suggest that we use gethostname().  Give me the go-ahead
>> and I'll prepare a patch to do so

Hi Scott,

In each of these cases, the hostname is used for informational purpose 
or to seed a random string.  gethostname() matches the original intent 
and, to me, looks cleaner.  I say go for it for all of the mentioned 
instances.

Thanks,

-bill

-- 
Bill Erickson
| VP, Software Development & Integration
| Equinox Software, Inc. / The Evergreen Experts
| phone: 877-OPEN-ILS (673-6457)
| email: erickson at esilibrary.com
| web: http://esilibrary.com



More information about the Open-ils-dev mailing list