/* 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);
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);
}
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) {
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
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__':
"""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"""
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()
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):
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__':
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()
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