From 70b63d5f52010d5b286f146058573849d8b95a81 Mon Sep 17 00:00:00 2001 From: Keith Rarick Date: Wed, 23 Jun 2010 23:58:03 -0700 Subject: [PATCH] Properly update the binlog linked list pointers. Code in this file assumes that newest_binlog is always correct, so when there is no binlog at all, we must set newest_binlog to NULL. Closes gh-44. --- binlog.c | 5 +++- sh-tests/binlog-empty-oom.sh | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100755 sh-tests/binlog-empty-oom.sh diff --git a/binlog.c b/binlog.c index 06049d4b..7d54671c 100644 --- a/binlog.c +++ b/binlog.c @@ -111,6 +111,10 @@ binlog_remove_oldest() oldest_binlog = b->next; + if (newest_binlog == b) { + newest_binlog = b->next; /* == 0 */ + } + unlink(b->path); free(b); } @@ -778,7 +782,6 @@ binlog_init(job binlog_jobs) } - /* Set up for writing out new jobs */ n = ensure_free_space(1); if (!n) return twarnx("error making first writable binlog"); diff --git a/sh-tests/binlog-empty-oom.sh b/sh-tests/binlog-empty-oom.sh new file mode 100755 index 00000000..b6facad1 --- /dev/null +++ b/sh-tests/binlog-empty-oom.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +. "$SRCDIR/sh-tests/common.functions" + +server=localhost +tmpdir="$TMPDIR" +size=601 +test -z "$tmpdir" && tmpdir=/tmp +out1="${tmpdir}/bnch$$.1" +logdir="${tmpdir}/bnch$$.d" +nc="$SRCDIR/sh-tests/netcat.py" + +cleanup() { + killbeanstalkd + rm -rf "$logdir" "$out1" +} + +catch() { + echo '' Interrupted + exit 3 +} + +trap cleanup EXIT +trap catch HUP INT QUIT TERM + +if [ ! -x ./beanstalkd ]; then + echo "Executable ./beanstalkd not found; do you need to compile first?" + exit 2 +fi + +start_beanstalkd $logdir + +killbeanstalkd -9 + +start_beanstalkd $logdir + +$nc $server $port < "$out1" +put 0 0 0 0 + +quit +EOF + +diff - "$out1" <