From owner-freebsd-questions@FreeBSD.ORG Thu May 4 06:37:08 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 037D016A400 for ; Thu, 4 May 2006 06:37:08 +0000 (UTC) (envelope-from parv@pair.com) Received: from mta13.adelphia.net (mta13.adelphia.net [68.168.78.44]) by mx1.FreeBSD.org (Postfix) with ESMTP id 88DE443D49 for ; Thu, 4 May 2006 06:37:07 +0000 (GMT) (envelope-from parv@pair.com) Received: from default.chvlva.adelphia.net ([69.160.66.115]) by mta13.adelphia.net (InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id <20060504063706.KIWT27153.mta13.adelphia.net@default.chvlva.adelphia.net>; Thu, 4 May 2006 02:37:06 -0400 Received: by default.chvlva.adelphia.net (Postfix, from userid 1000) id 92B46BB0F; Thu, 4 May 2006 02:37:28 -0400 (EDT) Date: Thu, 4 May 2006 02:37:28 -0400 From: Parv To: mark Message-ID: <20060504063728.GA8820@holestein.holy.cow> Mail-Followup-To: mark , freebsd-questions@freebsd.org References: <200605032149.24248.mark.rowlands@mypost.se> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200605032149.24248.mark.rowlands@mypost.se> Cc: freebsd-questions@freebsd.org Subject: Re: "Inappropriate file type or format" error when accessing berkely DB file via perl X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 May 2006 06:37:08 -0000 in message <200605032149.24248.mark.rowlands@mypost.se>, wrote mark thusly... > I am trying to access my squidguard berkely db files via perl and > DB_File (as per the SquidGuard docs) ... > #!/usr/bin/perl > use DB_File; > my (%url,%domain); > > $DB_BTREE->{compare} = \&domainmatch; ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ I suppose you have domainmatch() sub defined somewhere used in this file but omitted from your post? > my $domain_db = > tie(%domain, "DB_File", "/var/db/squidGuard/warez/domains.db", O_CREAT| > O_RDWR, 0664, $DB_BTREE) || die("domains.db: $!\n"); ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ > $domain_db->put(".six.com","") unless(exists($domain{"six.com"})); > $domain_db->sync; # Seems to only sync the last change. > > undef($domain_db); # Destroy the object > untie(%domain); # Sync and close the file and undef the hash > > The following is returned > > domains.db: Inappropriate file type or format ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ So the program is dying due to failure in tie()ing. Did you check if both SquidGuard & DB_File are linked with the same db library? > When I do a file /var/db/squidGuard/warez/domains.db ... > /var/db/squidGuard/warez/domains.db: Berkeley DB > (Btree, version 8, native byte-order) ... > When I create a db with perl > > #!/usr/bin/perl -w > use strict; > use DB_File; > my %database; > tie %database, 'DB_File', "createdb.dat" > or die "Can't initialize database: $!\n"; > untie %database; ... > file createdb.dat ... > createdb.dat: Berkeley DB 1.85 (Hash, version 2, native byte-order) ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ > I suspect the version 2 / version 8 is the srouce of my > innappropriate file type or format error! mach::DB_File(3) lists ... Using DB_File with Berkeley DB version 2 or greater Although DB_File is intended to be used with Berkeley DB version 1, it can also be used with version 2, 3 or 4. In this case the interface is limited to the functionality provided by Berkeley DB 1.x. Anywhere the version 2 or greater interface differs, DB_File arranges for it to work like version 1. ... so it is not surprising that, in your second case, the db file created is of version 1.x. (Note also that since you had not specified that you wanted a BTree db type, the type is hash.) > I tried reinstalling DB_file guessing that it had some kind of > dependency on DB3.. Thsi had no effect. I tried reinstalling Perl > itself. Also no effect. ... > Relevant Ports installed > > db3-3.3.11_2,1 > bsdpan-DB_File-1.814 ... > perl-5.8.8 DB_File (same version that you had installed separately) is included w/ Perl (at least in 5.8.8). Well, i just searched "Google Groups" for 'perl DB_File db3 "Inappropriate file type or format"' which presented ... http://groups.google.com/group/fa.freebsd.questions/browse_thread/thread/783254b63fbba089/3a8af6e2d78282f9 - Parv --