Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Dec 2003 12:48:56 -0800 (PST)
From:      Eric Anderson <anderson@centtech.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   www/60375: [FILE] Cleans sendpr-code db by removing expired codes.
Message-ID:  <200312182048.hBIKmuu8061343@www.freebsd.org>
Resent-Message-ID: <200312182050.hBIKoDwl068066@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         60375
>Category:       www
>Synopsis:       [FILE] Cleans sendpr-code db by removing expired codes.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-www
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 18 12:50:13 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Eric Anderson
>Release:        5.2-CURRENT
>Organization:
>Environment:
5.2-CURRENT FreeBSD 5.2-CURRENT
>Description:
      Perl program that is cronable - removes stale codes from sendpr db based on an expired time. 

Ceri requested this.  
>How-To-Repeat:
No problems reported yet.. :)  

File for Ceri..
>Fix:
#!/usr/bin/perl -T
#
# 
#
# Copyright (c) 2003 Eric Anderson

use DB_File;
use Fcntl qw(:DEFAULT :flock);
use strict;

$ENV{"PATH"} = "/bin:/usr/bin";
$ENV{"TMPDIR"} = "/tmp";

my($fd, $db_obj, %db_hash, $currenttime, $randomcode, $expiretime, $dbpath);

############################################
$dbpath = "/tmp/sendpr-code.db";
$expiretime = 900;              # seconds until code expires
############################################

$currenttime = time();

# DB stuff here
$db_obj = tie(%db_hash, 'DB_File', $dbpath, O_CREAT|O_RDWR, 0644)
                    or die "dbcreate $dbpath $!";
$fd = $db_obj->fd;
open(DB_FH, "+<&=$fd") or die "fdopen $!";

unless (flock (DB_FH, LOCK_EX | LOCK_NB)) {
    unless (flock (DB_FH, LOCK_EX)) { die "flock: $!" }
}

foreach $randomcode (keys %db_hash) {
        if ( ($currenttime - $expiretime) <= $db_hash{$randomcode}) {
                delete $db_hash{"$randomcode"};
        }
}

$db_obj->sync();                   # to flush
flock(DB_FH, LOCK_UN);
undef $db_obj;

untie %db_hash;

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200312182048.hBIKmuu8061343>