chiark / gitweb /
When shutting down, kill -rescan and wait for it to finish. If -rescan outlives
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 6 Jan 2008 21:27:38 +0000 (21:27 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 6 Jan 2008 21:27:38 +0000 (21:27 +0000)
-deadlock then it can deadlock with a later processes that access the database.

lib/trackdb.c
server/rescan.c
server/state.c

index f5d58364d6dd1020e0b5091e84a281e0ebefe108..5bf2fed6d9132d7c6d744edb6c839db58b17dd96 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder
- * Copyright (C) 2005, 2006, 2007 Richard Kettlewell
+ * Copyright (C) 2005-2008 Richard Kettlewell
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -318,10 +318,18 @@ void trackdb_deinit(void) {
   if((err = trackdb_env->close(trackdb_env, 0)))
     fatal(0, "trackdb_env->close: %s", db_strerror(err));
 
-  if(rescan_pid != -1 && kill(rescan_pid, SIGTERM) < 0)
-    fatal(errno, "error killing rescanner");
+  if(rescan_pid != -1) {
+    /* shut down the rescanner */
+    if(kill(rescan_pid, SIGTERM) < 0)
+      fatal(errno, "error killing rescanner");
+    /* wait for the rescanner to finish */
+    while(waitpid(rescan_pid, &err, 0) == -1 && errno == EINTR)
+      ;
+  }
+
+  /* TODO kill any stats subprocesses */
 
-  /* terminate the deadlock manager */
+  /* finally terminate the deadlock manager */
   if(db_deadlock_pid != -1 && kill(db_deadlock_pid, SIGTERM) < 0)
     fatal(errno, "error killing deadlock manager");
   db_deadlock_pid = -1;
index 47dcf99b1f367f91186e877e380c1eeb8d1413bb..e1193c9f9a50cb65db71885ec482197c536c6a55 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder 
- * Copyright (C) 2005, 2006, 2007 Richard Kettlewell
+ * Copyright (C) 2005-2008 Richard Kettlewell
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 16fc1a31482e8b00f1a92e4975707840372fb78a..3386cd44e1dc8694ef103ec86be3306c473b7263 100644 (file)
@@ -54,10 +54,11 @@ static struct addrinfo *current_listen_addrinfo;
 static int current_listen_fd;
 
 void quit(ev_source *ev) {
+  info("shutting down...");
   quitting(ev);
   trackdb_close();
   trackdb_deinit();
-  info("terminating");
+  info("exiting");
   exit(0);
 }