Plan 9 from Bell Labs’s /usr/web/sources/contrib/nemo/octopus/port/mero/meroox.b

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


implement Meroox;
include "sys.m";
	sys: Sys;
	fprint, pctl: import sys;
include "styx.m";
	styx: Styx;
	Rmsg, Tmsg: import styx;
include "styxservers.m";
	styxs: Styxservers;
	Styxserver, readstr: import styxs;
include "error.m";
	err: Error;
	stderr: import err;
include "string.m";
include "dat.m";
	dat: Dat;
	mnt, debug: import dat;
include "wait.m";
	wait: Wait;
include "meroox.m";

oxc: chan of string;

oxproc()
{
	(pid, wc) := wait->monitor();
	pidc := chan of int;
	spaceid := 0;
	for(;;){
		alt {
		panel := <- sc =>
			if (debug)
				fprint(stderr, "start ox for %s\n", panel);
			args := list of {string spaceid, panel};
			spaceid++;
			spawn runox(args, pidc);
			oxpid := <- pidc;
		(pid, nil, sts) := <- oxc =>
			if (debug)
				fprint(stderr, "o/x pid %d: exited '%s'\n", pid, sts);
		}
	}
}

runox(args: list of string, pidc: chan of int)
{
	pidc <-= pctl(NEWFD|FORKNS|NEWPGRP|FORKENV, list of {0, 1, 2});
	cmd := load Command Ox;
	if (cmd == nil)
		error(sprint("runox: load ox: %r"));
	cmd->init(nil, args);
}

init(d: Dat)
{
	dat = d;
	sys = d->sys;
	err = d->err;
	names = d->names;
	wait = checkload(Wait Wait->PATH, Wait->PATH);
	wait->init();
	oxc = chan of string;
	spawn oxproc();
}

start(panel: string)
{
	if (oxc == nil)
		return;
	rel := names->relative(mnt, panel);
	els := names->elements(rel);
	scr := names->rooted(mnt, hd els);
	oxc <-= scr;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.