netreg-devel: Re: Question about a subtle bug.

Sean Spillane sean.russell.spillane at gmail.com
Thu Nov 16 14:52:19 EST 2006


On 11/15/06, Sean Spillane <sean.russell.spillane at gmail.com> wrote:
>On 11/15/06, Sean Spillane <sean.russell.spillane at gmail.com> wrote:
>> Hi! I'm trying to make an API call to CMU::Netdb::modify_machine() and I am
>> running into trouble. I pass in the following as arguments to the function:
>>
>> A DB hash from CMU::Netdb::lw_db_connect()
>> 'netreg', which I think is the UID that the DB wants
>> The ID number for the machine. (40637 in this case)
>> The last version string for the machine.
>> A hashref containing
>> id => '40637'
>> expires => '2006-10-15' I think that this is the correct calling style, but
>> I run into trouble from a weird place. Inside the CMU::Netdb::
>> add_mod_machine_static() function (Yes, the machine is static), I get an
>> error:
>>  /home/netreg/lib/CMU/Netdb/machines_subnets.pm:1422
>> :>Couldn't find machine.ip_address_ttl!
>>  $VAR1 = {
>>           'ip_address_ttl' => '0',
>>            'mode' => 'static',
>>            'comment_lvl9' => '',
>>           'mac_address' => '000D56988A3C',
>>            'host_name_ttl' => '0',
>>            'ip_address_subnet' => 278,
>>           'id' => '40637',
>>            'ip_address' => '169.226.142.86',
>>            'comment_lvl5' => '',
>>           'flags' => '',
>>           'version' => '2004-09-24 10:05:42',
>>            'account' => '',
>>            'host_name_zone' => '143',
>>           'ip_address_zone' => '144',
>>            'created' => '2004-09-24 10:05:42',
>>            'comment_lvl1' => '',
>>           'host_name' => ' MSUTHERLANDOFF.BA.ALBANY.EDU',
>>           'fuckall.ip_address_ttl' => 42,
>>            'expires' => '2006-10-15'
>>          };
>> $VAR2 = [
>>            'id',
>>           'mac_address',
>>           'host_name',
>>            'ip_address',
>>           'mode',
>>            'flags',
>>           'comment_lvl1',
>>           'comment_lvl5',
>>            'comment_lvl9',
>>           'account',
>>           'host_name_ttl',
>>            'ip_address_ttl',
>>           'host_name_zone',
>>           'ip_address_zone',
>>            'ip_address_subnet',
>>           'version',
>>           'created',
>>            'expires'
>>         ];
>>
>> Notice how the @machine_fields array that is referenced by the function
>> ($VAR2 above) seems to have lost the " machine." prefixes on each of its
>> fields. I cannot figure out why. When I explicitly redeclare the variable as
>> a my variable and set it to
>> @CMU::Netdb::structure::machine_fields, the problem goes
>> away. I therefore suggest that, since no mention was made that no one can
>> modify @CMU::Netdb::structure::machine_fields and there is
>> at least one place in CMU::Netdb::list_machines() where an unshift does
>> modify it, that a my variable be included in the header of
>> CMU::Netdb::add_mod_machine_static(), setting it to
>> @CMU::Netdb::structure::machine_fields. Doing this seems to
>> solve the problem, though perhaps I am just calling the function
>> incorrectly. Can you folks help me? I need to know what I should do.
>>  --
>> Sean Spillane
>
>
>Sean,
>
>If you're doing somethign that is modifying the machine_fields list
>that would be causing this problem.  Note that list_machines is *not*
>modifying that structure, but prepending a reference to it onto the
>result data before returning that data, which is probably the source
>of your problem.  I suspect that you're taking the first row of a
>list_machines result and modifying it...  Try copying that array
>before modifying it.  something like:
>my @header_row = @{$result->[0]};
>
>The better thing to do would probably be to make all of the list_*
>routines copy the relevant array rather then referencing it, but thats
>the way it works right now...
>
>-David

I push the output of list_machines() through makemap(), which makes a
copy of the output rather than modifying it directly. As such, I'm
fairly certain that I'm not directly modifying @machine_fields. I also
feel that global variables are not the best idea here, so I went ahead
and changed the various functions in machines_subnets.pm to use local
copies of references to structure.pm instead of the global ones. Not
only did that fix my problem, but it strikes me as a better way to
keep functions from stepping on each other's toes. The way I figure
it: if list_machines and add_mod_machine* are using separate copies of
@machine_fields, then they can't interfere with each other. In the
hopes that you folks find these canges useful, I am adding a patch
file with those changes to this message.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: machines_subnets.pm.patch
Type: text/x-patch
Size: 11926 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/netreg-devel/attachments/20061116/6ff77c6b/machines_subnets.pm-0001.bin


More information about the Netreg-devel mailing list