Index: commonmod.scm ================================================================== --- commonmod.scm +++ commonmod.scm @@ -24,24 +24,42 @@ (declare (uses mtconfigf)) (declare (uses pkts)) (module commonmod * -(import scheme (chicken base)) +(import scheme (chicken base) + (chicken process) + (chicken format) + (chicken process-context) + (chicken process-context posix) + (chicken string) + (chicken io) + (chicken pretty-print) + (chicken file) + (chicken file posix) + (chicken pathname) + (chicken time) + (chicken sort) + (chicken condition) + (chicken time posix) -(use (prefix sqlite3 sqlite3:) posix typed-records srfi-18 - srfi-1 files format srfi-13 matchable - srfi-69 ports +) + +(import (prefix sqlite3 sqlite3:) typed-records srfi-18 + srfi-1 (chicken file) format srfi-13 matchable + srfi-69 (chicken port) (prefix base64 base64:) regex-case regex hostinfo srfi-4 (prefix dbi dbi:) stack md5 message-digest z3 directory-utils - sparse-vectors) + system-information + ;;sparse-vectors +) (import pkts) (import (prefix mtconfigf configf:)) (import (prefix mtargs args:)) @@ -237,11 +255,11 @@ (debug:check-verbosity *verbosity* debugstr) ;; if we were handed a bad verbosity rule then we will override it with 1 and continue (if (not *verbosity*)(set! *verbosity* 1)) (if (or dmode ;; (args:get-arg "-debug") (not (get-environment-variable "MT_DEBUG_MODE"))) - (setenv "MT_DEBUG_MODE" (if (list? *verbosity*) + (set-environment-variable! "MT_DEBUG_MODE" (if (list? *verbosity*) (string-intersperse (map conc *verbosity*) ",") (conc *verbosity*)))))) (define (debug:print n e . params) (if (debug:debug-mode n) @@ -596,11 +614,11 @@ (if (null? dirs) #f (let loop ((hed (car dirs)) (tal (cdr dirs))) (let ((res (or (and (directory? hed) - (file-write-access? hed) + (file-writable? hed) hed) (handle-exceptions exn (begin (debug:print-info 0 *default-log-port* "could not create " hed ", this might cause problems down the road.") @@ -672,11 +690,11 @@ (define (common:directory-writable? path-string) (handle-exceptions exn #f (if (and (directory-exists? path-string) - (file-write-access? path-string)) + (file-writable? path-string)) path-string #f))) ;;====================================================================== ;; T I M E A N D D A T E ;;====================================================================== @@ -1089,11 +1107,11 @@ (if (and (string? val) (string? key)) (handle-exceptions exn (debug:print-error 0 *default-log-port* "bad value for setenv, key=" key ", value=" val) - (setenv key val)) + (set-environment-variable! key val)) (debug:print-error 0 *default-log-port* "bad value for setenv, key=" key ", value=" val)))) (define home (getenv "HOME")) (define user (getenv "USER")) @@ -1105,11 +1123,11 @@ (val (cdr vardat))) (if (not (equal? (get-environment-variable var) val)) (handle-exceptions exn (debug:print-error 0 *default-log-port* "Failed to set " var " to " val) - (setenv var val))))) + (set-environment-variable! var val))))) all-vars)) ;; returns list of fd count, socket count (define (get-file-descriptor-count #!key (pid (current-process-id ))) (list @@ -1660,14 +1678,14 @@ -(use posix-extras pathname-expand files) +(import pathname-expand (chicken file)) ;; this plugs a hole in posix-extras in recent chicken versions > 4.9) -(let-values (( (chicken-release-number chicken-major-version) +#;(let-values (( (chicken-release-number chicken-major-version) (apply values (map string->number (take (string-split (chicken-version) ".") 2))))) @@ -1675,11 +1693,12 @@ (or (> chicken-release-number 4) (and (eq? 4 chicken-release-number) (> chicken-major-version 9))))) (if resolve-pathname-broken? (define ##sys#expand-home-path pathname-expand)))) -(define (realpath x) (resolve-pathname (pathname-expand (or x "/dev/null")) )) +;;(define (realpath x) (resolve-pathname (pathname-expand (or x "/dev/null")) )) +(define (realpath x) (pathname-expand (or x "/dev/null")) ) (define (common:get-this-exe-fullpath #!key (argv (argv))) (let* ((this-script (cond ((and (> (length argv) 2) @@ -2005,11 +2024,11 @@ (debug:print 0 *default-log-port* "ERROR: ["(common:human-time)"] Failed to read .homehost file after trying five times. Giving up and exiting, message: " ((condition-property-accessor 'exn 'message) exn)) (exit 1))) (let ((hhf (conc *toppath* "/.homehost"))) (if (common:file-exists? hhf) (with-input-from-file hhf read-line) - (if (file-write-access? *toppath*) + (if (file-writable? *toppath*) (begin (with-output-to-file hhf (lambda () (print bestadrs))) (begin @@ -2213,11 +2232,11 @@ ;; e.g. key is host and dtype is normalized-load ;; (define (common:get-cached-info key dtype #!key (age 5)) (let* ((fullpath (conc *toppath* "/logs/" key "-" dtype ".log"))) (if (and (file-exists? fullpath) - (file-read-access? fullpath)) + (file-readable? fullpath)) (handle-exceptions exn #f (debug:print 2 *default-log-port* "reading file " fullpath) (let ((real-age (- (current-seconds)(file-change-time fullpath)))) @@ -2484,11 +2503,11 @@ (freespc (cond ((not (directory? dirpath)) (if (common:low-noise-print 300 "disks not a dir " disk-num) (debug:print 0 *default-log-port* "WARNING: disk " disk-num " at path \"" dirpath "\" is not a directory - ignoring it.")) -1) - ((not (file-write-access? dirpath)) + ((not (file-writable? dirpath)) (if (common:low-noise-print 300 "disks not writeable " disk-num) (debug:print 0 *default-log-port* "WARNING: disk " disk-num " at path \"" dirpath "\" is not writeable - ignoring it.")) -1) ((not (eq? (string-ref dirpath 0) #\/)) (if (common:low-noise-print 300 "disks not a proper path " disk-num) @@ -2499,11 +2518,11 @@ (free-inodes (cond ((not (directory? dirpath)) (if (common:low-noise-print 300 "disks not a dir " disk-num) (debug:print 0 *default-log-port* "WARNING: disk " disk-num " at path \"" dirpath "\" is not a directory - ignoring it.")) -1) - ((not (file-write-access? dirpath)) + ((not (file-writable? dirpath)) (if (common:low-noise-print 300 "disks not writeable " disk-num) (debug:print 0 *default-log-port* "WARNING: disk " disk-num " at path \"" dirpath "\" is not writeable - ignoring it.")) -1) ((not (eq? (string-ref dirpath 0) #\/)) (if (common:low-noise-print 300 "disks not a proper path " disk-num) @@ -2681,11 +2700,11 @@ (val (cadr p)) (prv (get-environment-variable var))) (set! res (cons (list var prv) res)) (if val (safe-setenv var (->string val)) - (unsetenv var)))) + (unset-environment-variable! var)))) lst) res) '())) @@ -2705,17 +2724,17 @@ x)) envvars)))) (define (common:with-orig-env proc) (let ((current-env (get-environment-variables))) - (for-each (lambda (x) (unsetenv (car x))) current-env) - (for-each (lambda (x) (setenv (car x) (cdr x))) *common:orig-env*) + (for-each (lambda (x) (unset-environment-variable! (car x))) current-env) + (for-each (lambda (x) (set-environment-variable! (car x) (cdr x))) *common:orig-env*) (let ((rv (cond ((string? proc)(system proc)) (proc (proc))))) - (for-each (lambda (x) (unsetenv (car x))) *common:orig-env*) - (for-each (lambda (x) (setenv (car x) (cdr x))) current-env) + (for-each (lambda (x) (unset-environment-variable! (car x))) *common:orig-env*) + (for-each (lambda (x) (set-environment-variable! (car x) (cdr x))) current-env) rv))) (define (common:without-vars proc . var-patts) (let ((vars (make-hash-table))) (for-each @@ -2724,20 +2743,20 @@ (lambda (var-patt) (if (string-match var-patt (car vardat)) (let ((var (car vardat)) (val (cdr vardat))) (hash-table-set! vars var val) - (unsetenv var)))) + (unset-environment-variable! var)))) var-patts)) (get-environment-variables)) (cond ((string? proc)(system proc)) (proc (proc))) (hash-table-for-each vars (lambda (var val) - (setenv var val))) + (set-environment-variable! var val))) vars)) ;;====================================================================== ;; C O L O R S @@ -3060,11 +3079,11 @@ (cond ((not (common:file-exists? pktsdir)) (debug:print 0 *default-log-port* "ERROR: packets directory " pktsdir " does not exist.")) ((not (directory? pktsdir)) (debug:print 0 *default-log-port* "ERROR: packets directory path " pktsdir " is not a directory.")) - ((not (file-read-access? pktsdir)) + ((not (file-readable? pktsdir)) (debug:print 0 *default-log-port* "ERROR: packets directory path " pktsdir " is not readable.")) (else (debug:print-info 0 *default-log-port* "Loading packets found in " pktsdir) (let ((pkts (glob (conc pktsdir "/*.pkt")))) (for-each @@ -3288,26 +3307,26 @@ (new-val (let ((tmp (cdr env-pair))) (if (list? tmp) (car tmp) tmp))) (current-val (get-environment-variable env-var)) (restore-thunk (cond - ((not current-val) (lambda () (unsetenv env-var))) + ((not current-val) (lambda () (unset-environment-variable! env-var))) ((not (string? new-val)) #f) ((eq? current-val new-val) #f) (else - (lambda () (setenv env-var current-val)))))) + (lambda () (set-environment-variable! env-var current-val)))))) ;;(when (not (string? new-val)) ;; (debug:print 0 *default-log-port* " PROBLEM: not a string: "new-val"\n from env-alist:\n"delta-env-alist) ;; (pp delta-env-alist) ;; (exit 1)) (cond ((not new-val) ;; modify env here - (unsetenv env-var)) + (unset-environment-variable! env-var)) ((string? new-val) - (setenv env-var new-val))) + (set-environment-variable! env-var new-val))) restore-thunk)) delta-env-alist)))) (let ((rv (thunk))) (for-each (lambda (x) (x)) restore-thunks) ;; restore env to original state rv))) Index: ulex/ulex.scm ================================================================== --- ulex/ulex.scm +++ ulex/ulex.scm @@ -79,20 +79,22 @@ (if (ping udata (conc ipaddr ":" port)) udata (begin (remove-captain-pkt udata captn) (setup)))) - (setup-as-captain udata)) ;; this saves the thread to captain-thread and starts the thread + (begin + (setup-as-captain udata) ;; this saves the thread to captain-thread and starts the thread + (setup))) )) ;; connect to a specific dbfile (define (connect udata dbfname dbtype) udata) (define (ping udata host-port) (let ((cookie (make-cookie udata))) - (send udata host-port 'ping "just pinging" (current-seconds)) + (send udata host-port 'ping "just pinging" (conc (current-seconds))) ;; (mailbox-rec )) ;;====================================================================== ;; network utilities @@ -441,12 +443,12 @@ (send udata host:port "iamcaptain" qrykey (if (udat-my-cpkt-key udata) "yes" "no"))) (else ;; (send-ack udata host:port qrykey) - (add-to-work-queue udata (get-peer-dat udata host:port) handlerkey qrykey data))) - (else (print "BAD DATA? handler=" handlerkey " data=" data))))) + (add-to-work-queue udata (get-peer-dat udata host:port) handlerkey qrykey data)))) + (else (print "BAD DATA? controldat=" controldat " data=" data)))) (loop state))))) ;; add a proc to the handler list (define (register-handler udata key proc) (hash-table-set! (udat-handlers udata) key proc))