Merge pull request #564 from katterjohn/process-bsd-fix

(chibi process): fix process-running? on OpenBSD, NetBSD and DragonFly
This commit is contained in:
Alex Shinn 2019-08-31 22:36:49 +08:00 committed by GitHub
commit ae98680259
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -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)))

View file

@ -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__)