Skip to content

Commit

Permalink
Spawn now minimally works. Busybox can invoke "ls".
Browse files Browse the repository at this point in the history
  • Loading branch information
tbfleming committed Oct 25, 2015
1 parent f282158 commit 6adbb39
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 33 deletions.
13 changes: 8 additions & 5 deletions boot-worker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
importScripts('jspm_packages/system.js', 'config.js');

var main;

System.import('js/worker.js').then(function (m) {
main = m;
importScripts('bin/busybox');
var Module;
addEventListener('message', function (e) {
if (!e.isTrusted || Module)
return;
Module = {};
System.import('js/worker.js').then(function (m) {
m.start(Module, e.data);
});
});
2 changes: 1 addition & 1 deletion js/build-busybox
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mkdir -p bin

export CFLAGS="-include `readlink -f runtime/em-shell.h` -g"
export EM_LDFLAGS="--pre-js ../em-shell/js/pre.js --js-opts 0 `readlink -f runtime/em-shell.c` --js-library `readlink -f runtime/em-shell.js`"
export EM_LDFLAGS="--js-opts 0 `readlink -f runtime/em-shell.c` --js-library `readlink -f runtime/em-shell.js`"
export KBUILD_VERBOSE=1
export ARCH=em
export CROSS_COMPILE=em
Expand Down
11 changes: 9 additions & 2 deletions js/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ function startService() {
}
}

function spawn(file, args) {
let w = new Worker("boot-worker.js");
w.postMessage({file: file, args: args});
}

function serviceConnected() {
log('Connecting console to service');

Expand All @@ -79,15 +84,17 @@ function serviceConnected() {
if (e.data.command == 'writeConsole')
term.write(e.data.msg.replace('\n', '\r\n'));
else if(e.data.command == 'spawn') {
e.data.port.postMessage(9);
spawn('/bin/busybox', e.data.args); // TODO: process e.data.file
e.data.port.postMessage(0); // TODO: report real status
}
};

navigator.serviceWorker.controller.postMessage({
'command': 'setMasterPort',
'port': messageChannel.port2},
[messageChannel.port2]);

new Worker("boot-worker.js");
spawn('/bin/busybox', ['/bin/sh']);
}

term.open(document.getElementById('console'));
Expand Down
22 changes: 0 additions & 22 deletions js/pre.js

This file was deleted.

31 changes: 28 additions & 3 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,37 @@ function syncPost(url, data) {
req.send(data);
}

export function print(x) {
function print(x) {
syncPost('service/writeConsole', x);
}

export function stdin() {
function stdin() {
return syncGet('service/readConsole');
}

print('Worker started\r\n');
let Module;
export function start(m, msg) {
Module = m;
Module.thisProgram = msg.args.shift();
Module.arguments = msg.args;
Module.print = print;
Module.printErr = print;
Module.preInit = () => {
TTY.ttys[FS.makedev(5, 0)].ops = {
get_char: tty => {
if (!tty.input.length) {
var result = stdin();
if (!result)
return null;
tty.input = intArrayFromString(result, true);
}
return tty.input.shift();
}, put_char: (tty, val) => {
print(String.fromCharCode(val));
}, flush: tty => {
}
};
};

importScripts(msg.file);
}

0 comments on commit 6adbb39

Please sign in to comment.