Commit d5b41592 authored by Mike Hibler's avatar Mike Hibler

Add sub to return a unique index from the emulab-indicies table

and use it in mkusercert.  I need this elsewhere.
parent 3d656c8f
......@@ -281,22 +281,7 @@ open(IND, ">index.txt")
or fatal("Could not clear index.txt");
close(IND);
#
# Lock the table to avoid conflict with devel trees.
#
DBQueryFatal("lock tables emulab_indicies write");
$query_result =
DBQueryFatal("select idx from emulab_indicies ".
"where name='user_sslcerts'");
my ($curidx) = $query_result->fetchrow_array();
$curidx = 1
if (!defined($curidx));
my $nextidx = $curidx + 1;
DBQueryFatal("replace into emulab_indicies (name, idx) ".
"values ('user_sslcerts', $nextidx)");
DBQueryFatal("unlock tables");
my $curidx = TBGetUniqueIndex("user_sslcerts");
open(SER, ">serial")
or fatal("Could not create new serial file");
......
......@@ -191,6 +191,7 @@ use vars qw(@ISA @EXPORT);
TBDB_CHECKDBSLOT_NOFLAGS TBDB_CHECKDBSLOT_WARN TBDB_CHECKDBSLOT_ERROR
max min TBcheck_dbslot
hash_recurse array_recurse hash_recurse2 array_recurse2
TBGetUniqueIndex
);
# Must come after package declaration!
......@@ -4294,6 +4295,37 @@ sub TBcheck_dbslot($$$;$)
return 0;
}
#
# Return a unique index from emulab_indicies for the indicated name.
# Updates the index to be, well, unique.
# Eats flaming death on error.
#
# WARNING: this will unlock all locked tables, be careful where you call it!
#
sub TBGetUniqueIndex($)
{
my ($name) = @_;
#
# Lock the table to avoid conflicts
#
DBQueryFatal("lock tables emulab_indicies write");
my $query_result =
DBQueryFatal("select idx from emulab_indicies ".
"where name='$name'");
my ($curidx) = $query_result->fetchrow_array();
$curidx = 1
if (!defined($curidx));
my $nextidx = $curidx + 1;
DBQueryFatal("replace into emulab_indicies (name, idx) ".
"values ('$name', $nextidx)");
DBQueryFatal("unlock tables");
return $curidx;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment