From: Brian Johnson (brian@netcom.duke.edu)
Date: Fri Feb 07 2003 - 06:58:12 CST
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
**********************************************************************
This archive was generated by hypermail 2.1.4 : Thu Aug 12 2004 - 12:01:38 CDT