From: Michael King (mking@bridgew.edu)
Date: Fri Feb 07 2003 - 07:39:26 CST
I'm just wondering quickly, how was the race condition being triggered. I
would assume this condition would only occur if someone tried to register
two computers, with the same login name, pretty much at the same time. That
is pretty formidable odds, unless you are using generic login names.
-----Original Message-----
From: owner-netreg@southwestern.edu
[mailto:owner-netreg@southwestern.edu]On Behalf Of Brian Johnson
Sent: Friday, February 07, 2003 7:58 AM
To: netreg@southwestern.edu
Subject: Re: NetReg: duplicate host issues
Hi Jeff,
Thank you very much for sharing this with us! I'll definitely give it a
try!
Brian
On Thu, 6 Feb 2003, Jeff Wieland wrote:
> Since there is no locking of the dhcpd.conf.new file, there is nothing
> to prevent race conditions. I added a sub to the register.cgi script
> to use a seperate file, called "serial" that contains the serial number.
> It locks the file while it is being updated.
>
> Here is the routine:
>
> #
> # Routine to find the next serial number. We read it from a file, locking
> # the file to prevent race conditions. The old netreg method just scanned
> # through the dhcpconf file to find the highest serial (slow, slow) and
> # did no locking!
> #
> # Author: Jeff Wieland, VPIT-ITT. Purdue University
> #
> # Date: 4/29/2002
>
> sub get_serial {
> my $LOCK_SH = 1;
> my $LOCK_EX = 2;
> my $LOCK_NB = 4;
> my $LOCK_UN = 8;
>
> if (-e "$DHCPDCONFPATH/serial") {
> open SERIAL, "+<$DHCPDCONFPATH/serial" or die "ERROR: Can't open
serial
> file" ;
> flock SERIAL, $LOCK_EX;
> $serial = <SERIAL>;
> chomp $serial;
> $serial++;
> seek SERIAL, 0, 0;
> }
> else {
> open SERIAL, ">serial" or die "ERROR: Can't open serial file" ;
> flock SERIAL, $LOCK_EX;
> $serial = 0;
> }
>
> print SERIAL "$serial\n";
>
> flock SERIAL, $LOCK_UN;
> close SERIAL;
> return $serial;
> }
>
> --
> Jeff Wieland | Purdue University
> Network Analyst/Engineer | IT Telecommunications
> Voice: (765)496-8234 | 150 North University Street
> FAX: (765)494-0566 | West Lafayette, IN 47907-2067
>
> **********************************************************************
> To unsubscribe from this list, send an e-mail message to
> majordomo@southwestern.edu containing a single line with the words:
> unsubscribe netreg
> Send requests for assistance to: owner-netreg@southwestern.edu
> **********************************************************************
>
-------------
Brian Johnson
ECI Data
brian@netcom.duke.edu
919-668-6492
**********************************************************************
To unsubscribe from this list, send an e-mail message to
majordomo@southwestern.edu containing a single line with the words:
unsubscribe netreg
Send requests for assistance to: owner-netreg@southwestern.edu
**********************************************************************
**********************************************************************
To unsubscribe from this list, send an e-mail message to
majordomo@southwestern.edu containing a single line with the words:
unsubscribe netreg
Send requests for assistance to: owner-netreg@southwestern.edu
**********************************************************************
This archive was generated by hypermail 2.1.4 : Thu Aug 12 2004 - 12:01:38 CDT