From: Richard Kettlewell Date: Thu, 22 Nov 2007 13:17:54 +0000 (+0000) Subject: sync with trunk X-Git-Tag: debian-1_5_99dev9~1^2~9 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/f0c20432f8c9dffd049c785f21cc85d98ff628fd?hp=ad2f8275a5fc0dba29ca97bc02342d1f1627e590 sync with trunk --- diff --git a/server/disorderd.c b/server/disorderd.c index e8e1046..758907c 100644 --- a/server/disorderd.c +++ b/server/disorderd.c @@ -289,8 +289,11 @@ int main(int argc, char **argv) { /* ignore SIGPIPE */ signal(SIGPIPE, SIG_IGN); /* start a rescan straight away */ - if(initial_rescan) - trackdb_rescan(ev); + if(initial_rescan) { + trackdb_rescan(0/*ev*/); + /* No ev -> the rescan will block. Since we called reconfigure() already + * any clients will also be forced to block. */ + } rescan_after(86400); /* periodically tidy up the database */ dbgc_after(60); diff --git a/server/trackdb.c b/server/trackdb.c index c977b6a..cb6b45a 100644 --- a/server/trackdb.c +++ b/server/trackdb.c @@ -1981,9 +1981,9 @@ static int reap_rescan(ev_source attribute((unused)) *ev, void attribute((unused)) *u) { if(pid == rescan_pid) rescan_pid = -1; if(status) - error(0, "disorderd-rescan: %s", wstat(status)); + error(0, RESCAN": %s", wstat(status)); else - D(("disorderd-rescan terminate: %s", wstat(status))); + D((RESCAN" terminated: %s", wstat(status))); /* Our cache of file lookups is out of date now */ cache_clean(&cache_files_type); eventlog("rescanned", (char *)0); @@ -1991,14 +1991,22 @@ static int reap_rescan(ev_source attribute((unused)) *ev, } void trackdb_rescan(ev_source *ev) { + int w; + if(rescan_pid != -1) { error(0, "rescan already underway"); return; } rescan_pid = subprogram(ev, RESCAN, -1); - ev_child(ev, rescan_pid, 0, reap_rescan, 0); - D(("started rescanner")); - + if(ev) { + ev_child(ev, rescan_pid, 0, reap_rescan, 0); + D(("started rescanner")); + } else { + /* This is the first rescan, we block until it is complete */ + while(waitpid(rescan_pid, &w, 0) < 0 && errno == EINTR) + ; + reap_rescan(0, rescan_pid, w, 0, 0); + } } int trackdb_rescan_cancel(void) { diff --git a/tests/alltests b/tests/alltests index b115f7d..812b53a 100755 --- a/tests/alltests +++ b/tests/alltests @@ -56,7 +56,7 @@ for f in os.listdir(testdir): tests.sort() # let's have a consistent order for test in tests: - print "Test '%s'" % test + print "-------- Test '%s' --------" % test dtest.run(test, report=False) print "%d tests" % dtest.tests diff --git a/tests/dbversion.py b/tests/dbversion.py index 78788b1..d7f58a5 100755 --- a/tests/dbversion.py +++ b/tests/dbversion.py @@ -28,13 +28,11 @@ def test(): dtest.copyfile(config, configsave) open(config, "a").write("dbversion 1\n") dtest.start_daemon() - time.sleep(2) dtest.stop_daemon() # Revert to default configuration dtest.copyfile(configsave, config) print "Testing daemon manages to upgrade..." dtest.start_daemon() - time.sleep(4) assert dtest.check_files() == 0 if __name__ == '__main__': diff --git a/tests/dtest.py b/tests/dtest.py index 00c5ead..ab76991 100644 --- a/tests/dtest.py +++ b/tests/dtest.py @@ -21,7 +21,7 @@ """Utility module used by tests""" -import os,os.path,subprocess,sys,re,unicodedata +import os,os.path,subprocess,sys,re,time,unicodedata def fatal(s): """Write an error message and exit""" @@ -177,10 +177,32 @@ Start the daemon.""" global daemon, errs assert daemon == None print " starting daemon" + # remove the socket if it exists + socket = "%s/socket" % testroot + try: + os.remove(socket) + except: + pass daemon = subprocess.Popen(["disorderd", "--foreground", "--config", "%s/config" % testroot], stderr=errs) + # Wait for the socket to be created + waited = 0 + while not os.path.exists(socket): + rc = daemon.poll() + if rc is not None: + print "FATAL: daemon failed to start up" + sys.exit(1) + waited += 1 + if waited == 1: + print " waiting for socket..." + elif waited >= 60: + print "FATAL: took too long for socket to appear" + sys.exit(1) + time.sleep(1) + if waited > 0: + print " took about %ds for socket to appear" % waited def stop_daemon(): """stop_daemon() @@ -193,8 +215,11 @@ Stop the daemon if it has not stopped already""" if rc == None: print " stopping daemon" os.kill(daemon.pid, 15) + print " waiting for daemon" rc = daemon.wait() - print " daemon has stopped" + print " daemon has stopped" + else: + print " daemon already stopped" daemon = None def run(module=None, report=True): diff --git a/tests/files.py b/tests/files.py index 24d4ea4..3fc19f4 100755 --- a/tests/files.py +++ b/tests/files.py @@ -23,7 +23,6 @@ import dtest,time,disorder,sys def test(): """Check that the file listing comes out right""" dtest.start_daemon() - time.sleep(2) # give rescan a chance assert dtest.check_files() == 0 if __name__ == '__main__': diff --git a/tests/nothing.py b/tests/nothing.py index f3bdeb9..c12443e 100755 --- a/tests/nothing.py +++ b/tests/nothing.py @@ -21,9 +21,8 @@ import dtest,time def test(): - """Just start the server and then stop it a few seconds later""" + """Just start the server and then stop it""" dtest.start_daemon() - time.sleep(2) if __name__ == '__main__': dtest.run() diff --git a/tests/version.py b/tests/version.py index dbb0df6..9ec922c 100755 --- a/tests/version.py +++ b/tests/version.py @@ -23,7 +23,6 @@ import dtest,time,disorder def test(): """Ask the server its version number""" dtest.start_daemon() - time.sleep(2) # give the daemon a chance to start up c = disorder.client() v = c.version() print "Server version: %s" % v