Module Name: src Committed By: joerg Date: Sun Jun 3 21:02:50 UTC 2012
Modified Files: src/lib/libc/cdb: cdbw.3 cdbw.c src/tools/compat: Makefile Added Files: src/tools/compat: cdbw.h Log Message: Add a special seeder for cdbw_output that gives stable results. Hook up cdbw(3) for the tool build. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/lib/libc/cdb/cdbw.3 src/lib/libc/cdb/cdbw.c cvs rdiff -u -r1.56 -r1.57 src/tools/compat/Makefile cvs rdiff -u -r0 -r1.1 src/tools/compat/cdbw.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/cdb/cdbw.3 diff -u src/lib/libc/cdb/cdbw.3:1.3 src/lib/libc/cdb/cdbw.3:1.4 --- src/lib/libc/cdb/cdbw.3:1.3 Wed Nov 3 16:17:48 2010 +++ src/lib/libc/cdb/cdbw.3 Sun Jun 3 21:02:50 2012 @@ -1,4 +1,4 @@ -.\" $NetBSD: cdbw.3,v 1.3 2010/11/03 16:17:48 plunky Exp $ +.\" $NetBSD: cdbw.3,v 1.4 2012/06/03 21:02:50 joerg Exp $ .\" .\" Copyright (c) 2010 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -28,7 +28,7 @@ .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. -.Dd November 3, 2010 +.Dd June 3, 2012 .Dt CDBW 3 .Os .Sh NAME @@ -36,6 +36,8 @@ .Nm cdbw_put , .Nm cdbw_put_data , .Nm cdbw_put_key , +.Nm cdbw_stable_seeder , +.Nm cdbw_output , .Nm cdbw_close .Nd create constant databases .Sh SYNOPSIS @@ -64,6 +66,10 @@ .Fa "size_t keylen" .Fa "uint32_t index" .Fc +.Ft uint32_t +.Fo cdbw_stable_seeder +.Fa "void" +.Fc .Ft int .Fo cdbw_output .Fa "struct cdbw *cdbw" @@ -111,8 +117,12 @@ parameter provides a human readable desc The .Fn seedgen parameter can be used to override the default PRNG. -The function should return a different value for each invokation. The bitwise layout of the output depends on the chosen seed. +The function should return a different value for each invokation. +The +.Fn cdbw_stable_seeder +can be used to create reproducable output. +It may be slower than the default. .Sh SEE ALSO .Xr cdbr 3 , .Xr cdb 5 Index: src/lib/libc/cdb/cdbw.c diff -u src/lib/libc/cdb/cdbw.c:1.3 src/lib/libc/cdb/cdbw.c:1.4 --- src/lib/libc/cdb/cdbw.c:1.3 Tue Mar 13 21:32:12 2012 +++ src/lib/libc/cdb/cdbw.c Sun Jun 3 21:02:50 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: cdbw.c,v 1.3 2012/03/13 21:32:12 joerg Exp $ */ +/* $NetBSD: cdbw.c,v 1.4 2012/06/03 21:02:50 joerg Exp $ */ /*- * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -36,11 +36,13 @@ #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: cdbw.c,v 1.3 2012/03/13 21:32:12 joerg Exp $"); +__RCSID("$NetBSD: cdbw.c,v 1.4 2012/06/03 21:02:50 joerg Exp $"); #include "namespace.h" +#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H #include <sys/endian.h> +#endif #include <sys/queue.h> #include <cdbw.h> #include <stdlib.h> @@ -270,6 +272,12 @@ cdbw_close(struct cdbw *cdbw) free(cdbw); } +uint32_t +cdbw_stable_seeder(void) +{ + return 0; +} + #define unused 0xffffffffU struct vertex { @@ -556,8 +564,13 @@ cdbw_output(struct cdbw *cdbw, int fd, c return 0; } +#if HAVE_NBTOOL_CONFIG_H + if (seedgen == NULL) + seedgen = cdbw_stable_seeder; +#else if (seedgen == NULL) seedgen = arc4random; +#endif rv = 0; @@ -581,8 +594,12 @@ cdbw_output(struct cdbw *cdbw, int fd, c goto release; } + state.seed = 0; do { - state.seed = (*seedgen)(); + if (seedgen == cdbw_stable_seeder) + ++state.seed; + else + state.seed = (*seedgen)(); } while (build_graph(cdbw, &state)); assign_nodes(&state); Index: src/tools/compat/Makefile diff -u src/tools/compat/Makefile:1.56 src/tools/compat/Makefile:1.57 --- src/tools/compat/Makefile:1.56 Sat Feb 18 17:51:21 2012 +++ src/tools/compat/Makefile Sun Jun 3 21:02:50 2012 @@ -1,9 +1,10 @@ -# $NetBSD: Makefile,v 1.56 2012/02/18 17:51:21 njoly Exp $ +# $NetBSD: Makefile,v 1.57 2012/06/03 21:02:50 joerg Exp $ HOSTLIB= nbcompat -SRCS= atoll.c basename.c dirname.c fgetln.c flock.c fparseln.c \ - fpurge.c getline.c getmode.c getopt_long.c gettemp.c \ +SRCS= atoll.c basename.c cdbw.c dirname.c \ + fgetln.c flock.c fparseln.c fpurge.c \ + getline.c getmode.c getopt_long.c gettemp.c \ heapsort.c \ issetugid.c lchflags.c lchmod.c lchown.c libyywrap.c \ md2.c md2hl.c md4c.c md4hl.c md5c.c md5hl.c \ @@ -31,7 +32,8 @@ CPPFLAGS+= -no-cpp-precomp CPPFLAGS+= -I. -I./include -I${.CURDIR} -I${.CURDIR}/sys \ -DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -.PATH: ${.CURDIR}/../../lib/libc/gen \ +.PATH: ${.CURDIR}/../../lib/libc/cdb \ + ${.CURDIR}/../../lib/libc/gen \ ${.CURDIR}/../../lib/libc/hash \ ${.CURDIR}/../../lib/libc/hash/md2 \ ${.CURDIR}/../../lib/libc/hash/md5 \ Added files: Index: src/tools/compat/cdbw.h diff -u /dev/null src/tools/compat/cdbw.h:1.1 --- /dev/null Sun Jun 3 21:02:50 2012 +++ src/tools/compat/cdbw.h Sun Jun 3 21:02:50 2012 @@ -0,0 +1,5 @@ +/* $NetBSD: cdbw.h,v 1.1 2012/06/03 21:02:50 joerg Exp $ */ + +/* We unconditionally use the NetBSD cdbw(3) in libnbcompat. */ +#include "nbtool_config.h" +#include "../../include/cdbw.h"