shlist

share and manage lists between multiple people
Log | Files | Refs

commit d2802a486822805f5025095b5855bfc50885db93
parent e8e30e29e17fa14c6d1220e0366086d82f7cba1c
Author: kyle <kyle@getaddrinfo.net>
Date:   Wed,  9 Dec 2015 23:24:04 -0700

sl: replace -d with -t

- -t will create a new temporary db and destroy it when the program finishes
- now we don't have to keep track of a temporary db
- this is mainly used for testing

Diffstat:
Mrun_tests.sh | 4+---
Msl | 15+++++++--------
2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/run_tests.sh b/run_tests.sh @@ -22,14 +22,13 @@ ok() { passed=0 failed=0 count=0 -tmp_file=`mktemp` for t in `ls tests/*/Makefile`; do count=`expr $count + 1` test_dir=`dirname ${t}` export TEST_DIR="$test_dir" make -s -C $test_dir clean - perl sl -p $PORT -d $tmp_file > $test_dir/server.log & + perl sl -p $PORT -t > $test_dir/server.log & server_pid=$! # run test, complain if it failed @@ -53,7 +52,6 @@ for t in `ls tests/*/Makefile`; do make -s -C $test_dir clean ok $test_dir done -rm -f $tmp_file echo if [ $passed -ne 0 ]; then diff --git a/sl b/sl @@ -4,6 +4,7 @@ use strict; use BSD::arc4random qw(:all); use DBI; +use File::Temp; use Digest::SHA qw(sha256_base64); use Getopt::Std; use IO::Socket; @@ -16,17 +17,15 @@ require "msgs.pl"; our (%msg_num, @msg_str, @msg_func, $protocol_ver); my %args; -getopts("p:d:", \%args); +getopts("p:t", \%args); + +$SIG{TERM} = sub { exit }; my $db_file = "db"; -if ($args{d}) { - $db_file = $args{d}; - unlink $db_file; -} -elsif (! -e $db_file) { - log_print_bare("creating new database '$db_file'\n"); -} +# EXLOCK needs to be 0 because SQLite expects it to be +$db_file = File::Temp->new(SUFFIX => '.db', EXLOCK => 0) if ($args{t}); +log_print_bare("creating new database '$db_file'\n") unless (-e $db_file); create_tables(); my $listen_sock = new IO::Socket::INET (