8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;; PURPOSE.
(require-extension (srfi 18) extras tcp s11n)
(use sqlite3 srfi-1 posix srfi-69 hostinfo dot-locking z3)
(import (prefix sqlite3 sqlite3:))
(declare (unit portlogger))
(declare (uses db))
;; lsof -i
(define (portlogger:open-db fname)
(let* ((avail (tasks:wait-on-journal fname 5 remove: #t)) ;; wait up to about 10 seconds for the journal to go away
(exists (file-exists? fname))
(db (if avail
(sqlite3:open-database fname)
(begin
(system (conc "rm -f " fname))
(sqlite3:open-database fname))))
(handler (make-busy-timeout 136000))
(canwrite (file-write-access? fname)))
;; (db-init (lambda ()
;; (sqlite3:execute
;; db
;; "CREATE TABLE IF NOT EXISTS ports (
;; port INTEGER PRIMARY KEY,
;; state TEXT DEFAULT 'not-used',
;; fail_count INTEGER DEFAULT 0,
;; update_time TIMESTAMP DEFAULT (strftime('%s','now')) );"))))
(sqlite3:set-busy-handler! db handler)
(db:set-sync db) ;; (sqlite3:execute db "PRAGMA synchronous = 0;")
;; (if (not exists) ;; needed with IF NOT EXISTS?
(sqlite3:execute
db
"CREATE TABLE IF NOT EXISTS ports (
port INTEGER PRIMARY KEY,
state TEXT DEFAULT 'not-used',
fail_count INTEGER DEFAULT 0,
update_time TIMESTAMP DEFAULT (strftime('%s','now')) );")
db))
|
>
>
|
|
|
|
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
;; implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;; PURPOSE.
(require-extension (srfi 18) extras tcp s11n)
(use sqlite3 srfi-1 posix srfi-69 hostinfo dot-locking z3)
(import (prefix sqlite3 sqlite3:))
(import (prefix dbi dbi:))
(declare (unit portlogger))
(declare (uses db))
;; lsof -i
(define (portlogger:open-db fname)
(let* ((avail (tasks:wait-on-journal fname 5 remove: #t)) ;; wait up to about 10 seconds for the journal to go away
(exists (file-exists? fname))
(db (if avail
(dbi:open 'sqlite3 '((dbname . fname)))
(begin
(system (conc "rm -f " fname))
(dbi:open 'sqlite3 '((dbname . fname))))))
(handler (make-busy-timeout 136000))
(canwrite (file-write-access? fname)))
;; (db-init (lambda ()
;; (sqlite3:execute
;; db
;; "CREATE TABLE IF NOT EXISTS ports (
;; port INTEGER PRIMARY KEY,
;; state TEXT DEFAULT 'not-used',
;; fail_count INTEGER DEFAULT 0,
;; update_time TIMESTAMP DEFAULT (strftime('%s','now')) );"))))
;;(sqlite3:set-busy-handler! db handler)
(db:set-sync db) ;; (sqlite3:execute db "PRAGMA synchronous = 0;")
;; (if (not exists) ;; needed with IF NOT EXISTS?
(dbi:exec
db
"CREATE TABLE IF NOT EXISTS ports (
port INTEGER PRIMARY KEY,
state TEXT DEFAULT 'not-used',
fail_count INTEGER DEFAULT 0,
update_time TIMESTAMP DEFAULT (strftime('%s','now')) );")
db))
|