From 13d4bbf1d1cbce8d3a4ed009cb9ce484d6fdf77a Mon Sep 17 00:00:00 2001 From: Robert Fisher Date: Thu, 29 Aug 2019 09:16:36 -0500 Subject: [PATCH 1/3] Change snow-chibi to work with Chicken 5 The method snow-chibi used to get the version of Chicken installed doesn't work with Chicken 5. Adding "-R chicken.platform" would make it work with Chicken 5, but then it wouldn't work with Chicken 4. In both Chicken 4 & 5, however, csi has a -release option that will just give the version number. So, I've changed the Chicken version detection in snow-chibi to use this option. Testing with... ./chibi-scheme tools/snow-chibi.scm implementations ...then seemed to work with both Chicken 4 & 5. --- lib/chibi/snow/commands.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chibi/snow/commands.scm b/lib/chibi/snow/commands.scm index c2fe54ef..f4ef2aa3 100644 --- a/lib/chibi/snow/commands.scm +++ b/lib/chibi/snow/commands.scm @@ -5,7 +5,7 @@ (define known-implementations '((chibi "chibi-scheme" (chibi-scheme -V) "0.7.3") - (chicken "chicken" (csi -p "(chicken-version)") "4.9.0") + (chicken "chicken" (csi -release) "4.9.0") (cyclone "cyclone" (icyc -vn) "0.5.3") (foment "foment") (gauche "gosh" (gosh -E "print (gauche-version)" -E exit) "0.9.4") From 7f3d322407da3f21a05adf199dff5027c6842885 Mon Sep 17 00:00:00 2001 From: Robert Fisher Date: Thu, 29 Aug 2019 11:42:21 -0500 Subject: [PATCH 2/3] Fix installation for Chicken 5 To get the repository path in Chicken 5, we not only have to require the chicken.platform module, we also need to take the car of the result since it now returns a list. --- lib/chibi/snow/commands.scm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/chibi/snow/commands.scm b/lib/chibi/snow/commands.scm index f4ef2aa3..7369c203 100644 --- a/lib/chibi/snow/commands.scm +++ b/lib/chibi/snow/commands.scm @@ -1287,6 +1287,16 @@ (string->number (process->string '(csi -p "(##sys#fudge 42)"))) 8)) +(define (get-chicken-repo-path) + (let ((release (string-trim (process->string '(csi -release)) + char-whitespace?))) + (string-trim + (if (string-prefix? "4." release) + (process->string '(csi -p "(repository-path)")) + (process->string + '(csi -R chicken.platform -p "(car (repository-path))"))) + char-whitespace?))) + (define (get-install-dirs impl cfg) (define (guile-eval expr) (guard (exn (else #f)) @@ -1304,9 +1314,7 @@ (cons share-dir (delete share-dir dirs)) dirs))) ((chicken) - (let ((dir (string-trim - (process->string '(csi -p "(repository-path)")) - char-whitespace?))) + (let ((dir (get-chicken-repo-path))) (list (if (file-exists? dir) ; repository-path should always exist dir From 3da3f3cab3edc9d48f72de9873633ab35e1ba7ca Mon Sep 17 00:00:00 2001 From: Kris Katterjohn Date: Fri, 30 Aug 2019 13:05:32 -0500 Subject: [PATCH 3/3] (chibi process): fix process-running? on OpenBSD, NetBSD and DragonFly tl;dr process-running? would always return #f on OpenBSD and NetBSD, and in the one-argument case it would always return #t on DragonFly. To get the process information from the process table on OpenBSD and NetBSD, we need to pass 6 level names to sysctl instead of 4. Passing the wrong number of level names to sysctl has caused it to always fail, which in turn caused process-running? to always return #f: (process-running? 1) => #f (process-running? (current-process-id)) => #f and so on. After the above fix, we also need to check the amount of data actually filled in by sysctl. It appears that on OpenBSD, NetBSD and DragonFly, if the requested process doesn't exist then sysctl will return with a return value of 0 and just not actually fill in the given structure. This caused process-running? to return #t when no process with the given PID existed: (process-running? -1) => #t (process-running? ) => #t and so on. I have tested on OpenBSD, NetBSD, DragonFly BSD and FreeBSD, and process-running? now behaves as expected on all of them. --- lib/chibi/process-test.sld | 1 + lib/chibi/signal.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/chibi/process-test.sld b/lib/chibi/process-test.sld index 34b8896a..0e8bdc0f 100644 --- a/lib/chibi/process-test.sld +++ b/lib/chibi/process-test.sld @@ -6,6 +6,7 @@ (test-begin "processes") (test #t (process-running? (current-process-id))) (test #t (process-running? (parent-process-id))) + (test #f (process-running? -1)) (test #f (signal-set-contains? (current-signal-mask) signal/alarm)) (test #t (signal-set? (make-signal-set))) (test #t (signal-set? (current-signal-mask))) diff --git a/lib/chibi/signal.c b/lib/chibi/signal.c index 587223b1..74eedcf7 100644 --- a/lib/chibi/signal.c +++ b/lib/chibi/signal.c @@ -83,8 +83,14 @@ static sexp sexp_pid_cmdline (sexp ctx, int pid) { int id = KERN_PROC; #endif size_t reslen = sizeof(res); +#if defined(__NetBSD__) || defined(__OpenBSD__) + int name[6] = {CTL_KERN, id, KERN_PROC_PID, pid, reslen, 1}; + unsigned namelen = 6; +#else int name[4] = {CTL_KERN, id, KERN_PROC_PID, pid}; - if (sysctl(name, 4, &res, &reslen, NULL, 0) >= 0) { + unsigned namelen = 4; +#endif + if (sysctl(name, namelen, &res, &reslen, NULL, 0) >= 0 && reslen > 0) { #if defined(__APPLE__) return sexp_c_string(ctx, res.kp_proc.p_comm, -1); #elif defined(__NetBSD__) || defined(__OpenBSD__)