Index: portlogger.scm ================================================================== --- portlogger.scm +++ portlogger.scm @@ -17,11 +17,12 @@ ;; lsof -i (define (portlogger:open-db fname) - (let* ((exists (file-exists? fname)) + (let* ((avail (tasks:wait-on-journal fname 10)) ;; wait up to about 10 seconds for the journal to go away + (exists (file-exists? fname)) (db (sqlite3:open-database fname)) (handler (make-busy-timeout 136000)) (canwrite (file-write-access? fname))) (sqlite3:set-busy-handler! db handler) (sqlite3:execute db "PRAGMA synchronous = 0;") @@ -34,24 +35,25 @@ fail_count INTEGER DEFAULT 0, update_time TIMESTAMP DEFAULT (strftime('%s','now')) );")) db)) (define (portlogger:open-run-close proc . params) - (let ((fname (conc "/tmp/." (current-user-name) "-portlogger.db"))) + (let* ((fname (conc "/tmp/." (current-user-name) "-portlogger.db")) + (avail (tasks:wait-on-journal fname 10))) ;; wait up to about 10 seconds for the journal to go away (handle-exceptions exn (begin - (release-dot-lock fname) + ;; (release-dot-lock fname) (debug:print 0 "ERROR: portlogger:open-run-close failed. " proc " " params) (debug:print 0 " message: " ((condition-property-accessor 'exn 'message) exn)) (debug:print 0 "exn=" (condition->list exn)) (print-call-chain)) - (let* ((lock (obtain-dot-lock fname 2 9 10)) + (let* (;; (lock (obtain-dot-lock fname 2 9 10)) (db (portlogger:open-db fname)) (res (apply proc db params))) (sqlite3:finalize! db) - (release-dot-lock fname) + ;; (release-dot-lock fname) res)))) ;; (fold-row PROC INIT DATABASE SQL . PARAMETERS) (define (portlogger:take-port db portnum) (let* ((qry1 (sqlite3:prepare db "INSERT INTO ports (port,state) VALUES (?,?);")) Index: tasks.scm ================================================================== --- tasks.scm +++ tasks.scm @@ -19,10 +19,26 @@ (include "task_records.scm") ;;====================================================================== ;; Tasks db ;;====================================================================== + +;; wait up to aprox n seconds for a journal to go away +;; +(define (tasks:wait-on-journal path n) + (let ((fullpath (conc path "-journal"))) + (let loop ((journal-exists (file-exists? fullpath)) + (count n)) ;; wait ten times ... + (if journal-exists + (if (> count 0) + #f + (begin + (thread-sleep! 1) + (loop (file-exists? fullpath) + (- count 1)))) + #t)))) + ;; If file exists AND ;; file readable ;; ==> open it ;; If file exists AND @@ -32,10 +48,11 @@ ;; ==> open in-mem version ;; (define (tasks:open-db) (let* ((linktree (configf:lookup *configdat* "setup" "linktree")) (dbpath (conc linktree "/.db/monitor.db")) + (avail (tasks:wait-on-journal dbpath 10)) ;; wait up to about 10 seconds for the journal to go away (exists (file-exists? dbpath)) (write-access (file-write-access? dbpath)) (mdb (cond ((file-write-access? *toppath*)(sqlite3:open-database dbpath)) ((file-read-access? dbpath) (sqlite3:open-database dbpath))