Skip to content

Commit 8887075

Browse files
author
Noam Preil
committed
plan9: working process support
1 parent 7d06fac commit 8887075

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

mkfile

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TARG=janet
44
HFILES=src/include/janet.h src/conf/janetconf.h
55
JANET_PATH=/sys/lib/janet
66
BIN=/$objtype/bin/
7-
DISABLED=PROCESSES EV NET ASSEMBLER FFI UTC_MKTIME REALPATH DYNAMIC_MODULES THREADS SYMLINKS LOCALES UMASK
7+
DISABLED=EV NET ASSEMBLER FFI UTC_MKTIME REALPATH DYNAMIC_MODULES THREADS SYMLINKS LOCALES UMASK SPAWN
88
JANET_CONFIG=JANET_SINGLE_THREADED JANET_OS_NAME=plan9 JANET_ARCH_NAME=$objtype JANET_API='' JANET_NO_RETURN='' JANET_SIMPLE_GETLINE `{echo JANET_NO_^$DISABLED} PLAN9_`{echo -n $objtype}
99
CFLAGS=-FTVBNcwp -D _POSIX_SOURCE -DJANET_PLAN9 -D_BSD_EXTENSION -D_LIMITS_EXTENSION -Isrc/include -Isrc/conf -I/sys/include/npe -Dtypestr=janettypestr -DJANET_API `{echo '-D'^$JANET_CONFIG}
1010
BOOT_CFLAGS=$CFLAGS -DJANET_BOOTSTRAP

src/core/os.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
#define environ (*_NSGetEnviron())
7676
#include <AvailabilityMacros.h>
7777
int chroot(const char *dirname);
78-
#else
78+
#elif !defined(JANET_PLAN9)
7979
extern char **environ;
8080
#endif
8181
#ifdef JANET_THREADS
@@ -305,21 +305,17 @@ JANET_CORE_FN(os_cpu_count,
305305
"Get an approximate number of CPUs available on for this process to use. If "
306306
"unable to get an approximation, will return a default value dflt.") {
307307
janet_arity(argc, 0, 1);
308-
Janet dflt = argc > 0 ? argv[0] : janet_wrap_nil();
309308
#ifdef JANET_WINDOWS
310-
(void) dflt;
311309
SYSTEM_INFO info;
312310
GetSystemInfo(&info);
313311
return janet_wrap_integer(info.dwNumberOfProcessors);
314312
#elif defined(JANET_LINUX)
315-
(void) dflt;
316313
cpu_set_t cs;
317314
CPU_ZERO(&cs);
318315
sched_getaffinity(0, sizeof(cs), &cs);
319316
int count = CPU_COUNT(&cs);
320317
return janet_wrap_integer(count);
321318
#elif defined(JANET_BSD) && defined(HW_NCPUONLINE)
322-
(void) dflt;
323319
const int name[2] = {CTL_HW, HW_NCPUONLINE};
324320
int result = 0;
325321
size_t len = sizeof(int);
@@ -328,7 +324,6 @@ JANET_CORE_FN(os_cpu_count,
328324
}
329325
return janet_wrap_integer(result);
330326
#elif defined(JANET_BSD) && defined(HW_NCPU)
331-
(void) dflt;
332327
const int name[2] = {CTL_HW, HW_NCPU};
333328
int result = 0;
334329
size_t len = sizeof(int);
@@ -337,7 +332,6 @@ JANET_CORE_FN(os_cpu_count,
337332
}
338333
return janet_wrap_integer(result);
339334
#elif defined(JANET_ILLUMOS)
340-
(void) dflt;
341335
long result = sysconf(_SC_NPROCESSORS_CONF);
342336
if (result < 0) {
343337
return dflt;
@@ -346,7 +340,7 @@ JANET_CORE_FN(os_cpu_count,
346340
#elif defined(JANET_PLAN9)
347341
return janet_wrap_integer(atoi(getenv("NPROC")));
348342
#else
349-
return dflt;
343+
return argc > 0 ? argv[0] : janet_wrap_nil();
350344
#endif
351345
}
352346

@@ -1355,6 +1349,9 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, JanetExecuteMode mode) {
13551349
/* exec mode */
13561350
if (mode == JANET_EXECUTE_EXEC) {
13571351
int status;
1352+
#ifdef JANET_PLAN9
1353+
status = exec(cargv[0], cargv);
1354+
#else
13581355
if (!use_environ) {
13591356
environ = envp;
13601357
}
@@ -1365,9 +1362,11 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, JanetExecuteMode mode) {
13651362
status = execv(cargv[0], cargv);
13661363
}
13671364
} while (status == -1 && errno == EINTR);
1365+
#endif
13681366
janet_panicf("%p: %s", cargv[0], janet_strerror(errno ? errno : ENOENT));
13691367
}
13701368

1369+
#ifndef JANET_NO_SPAWN
13711370
/* Use posix_spawn to spawn new process */
13721371

13731372
/* Posix spawn setup */
@@ -1436,6 +1435,8 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, JanetExecuteMode mode) {
14361435
}
14371436

14381437
#endif
1438+
#endif
1439+
#ifndef JANET_NO_SPAWN
14391440
JanetProc *proc = janet_abstract(&ProcAT, sizeof(JanetProc));
14401441
proc->return_code = -1;
14411442
#ifdef JANET_WINDOWS
@@ -1473,6 +1474,7 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, JanetExecuteMode mode) {
14731474
return os_proc_wait_impl(proc);
14741475
#endif
14751476
}
1477+
#endif
14761478
}
14771479

14781480
JANET_CORE_FN(os_execute,
@@ -1533,17 +1535,21 @@ JANET_CORE_FN(os_posix_exec,
15331535
JANET_CORE_FN(os_posix_fork,
15341536
"(os/posix-fork)",
15351537
"Make a `fork` system call and create a new process. Return nil if in the new process, otherwise a core/process object (as returned by os/spawn). "
1536-
"Not supported on all systems (POSIX only).") {
1538+
"Not supported on all systems (POSIX and Plan 9 only).") {
15371539
janet_sandbox_assert(JANET_SANDBOX_SUBPROCESS);
15381540
janet_fixarity(argc, 0);
15391541
(void) argv;
15401542
#ifdef JANET_WINDOWS
15411543
janet_panic("not supported on Windows");
15421544
#else
15431545
pid_t result;
1546+
#ifdef JANET_PLAN9
1547+
result = fork();
1548+
#else
15441549
do {
15451550
result = fork();
15461551
} while (result == -1 && errno == EINTR);
1552+
#endif
15471553
if (result == -1) {
15481554
janet_panic(janet_strerror(errno));
15491555
}
@@ -1564,9 +1570,9 @@ JANET_CORE_FN(os_posix_chroot,
15641570
"Not supported on all systems (POSIX only).") {
15651571
janet_sandbox_assert(JANET_SANDBOX_CHROOT);
15661572
janet_fixarity(argc, 1);
1567-
#ifdef JANET_WINDOWS
1573+
#if defined(JANET_WINDOWS) || defined(JANET_PLAN9)
15681574
(void) argv;
1569-
janet_panic("not supported on Windows");
1575+
janet_panic("not supported on Windows or Plan 9");
15701576
#else
15711577
const char *root = janet_getcstring(argv, 0);
15721578
int result;

0 commit comments

Comments
 (0)