cleanup, fix ctl write
This commit is contained in:
parent
5040da40fc
commit
4ed8a026bb
8 changed files with 38 additions and 132 deletions
|
@ -8,7 +8,6 @@ OFILES=\
|
||||||
client.$O\
|
client.$O\
|
||||||
util.$O\
|
util.$O\
|
||||||
node.$O\
|
node.$O\
|
||||||
nodetable.$O\
|
|
||||||
|
|
||||||
HFILES=dat.h\
|
HFILES=dat.h\
|
||||||
fns.h\
|
fns.h\
|
||||||
|
|
18
dat.h
18
dat.h
|
@ -10,7 +10,9 @@
|
||||||
#include <keyboard.h>
|
#include <keyboard.h>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CTL = 1
|
CTL = 0,
|
||||||
|
CPU = 1,
|
||||||
|
MEMORY = 2
|
||||||
} FileType;
|
} FileType;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -87,16 +89,4 @@ typedef struct {
|
||||||
Handler* handlers;
|
Handler* handlers;
|
||||||
KuroMemory* memory;
|
KuroMemory* memory;
|
||||||
Channel* status; /* chan(WidowStatus) */
|
Channel* status; /* chan(WidowStatus) */
|
||||||
} Node;
|
} Node;
|
||||||
|
|
||||||
typedef struct NodeRef NodeRef;
|
|
||||||
|
|
||||||
struct NodeRef {
|
|
||||||
int fd[2];
|
|
||||||
uvlong id;
|
|
||||||
NodeRef* next;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
NodeRef* data[256];
|
|
||||||
} NodeTable;
|
|
5
fns.h
5
fns.h
|
@ -3,15 +3,12 @@ char* strcsw(char* s, char a, char b);
|
||||||
char* uvlong_to_hex(uvlong input, char* buf);
|
char* uvlong_to_hex(uvlong input, char* buf);
|
||||||
int ensure(char* path);
|
int ensure(char* path);
|
||||||
|
|
||||||
void start_9p();
|
void start_9p(Node* n);
|
||||||
|
|
||||||
void kuro9p_set_mtpt(char* mtpt);
|
void kuro9p_set_mtpt(char* mtpt);
|
||||||
void kuro9p_write(char* path, char* data, int len);
|
void kuro9p_write(char* path, char* data, int len);
|
||||||
char* kuro9p_read(char* path, char* buf, int len);
|
char* kuro9p_read(char* path, char* buf, int len);
|
||||||
|
|
||||||
void nodetbl_add(NodeTable* self, NodeRef* node);
|
|
||||||
void nodetbl_del(NodeTable* self, uvlong id);
|
|
||||||
|
|
||||||
void node_setup(Node* self, Handler* handlers, KuroMemory* memory);
|
void node_setup(Node* self, Handler* handlers, KuroMemory* memory);
|
||||||
void node_execute(Node* self);
|
void node_execute(Node* self);
|
||||||
void node_loop(void* data);
|
void node_loop(void* data);
|
||||||
|
|
16
kuro.c
16
kuro.c
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
static char* mtpt;
|
static char* mtpt;
|
||||||
|
|
||||||
int threadmaybackground(void) {
|
void srvthread(void* arg) {
|
||||||
return 1;
|
Node* vm = (Node*)arg;
|
||||||
|
start_9p(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void threadmain(int argc, char **argv)
|
void threadmain(int argc, char **argv)
|
||||||
|
@ -13,15 +14,14 @@ void threadmain(int argc, char **argv)
|
||||||
if (mtpt == nil) {
|
if (mtpt == nil) {
|
||||||
sysfatal("KURO_MTPT not set");
|
sysfatal("KURO_MTPT not set");
|
||||||
}
|
}
|
||||||
|
|
||||||
kuro9p_set_mtpt(mtpt);
|
|
||||||
print("KURO_MTPT=%s\n", mtpt);
|
print("KURO_MTPT=%s\n", mtpt);
|
||||||
|
|
||||||
ARGBEGIN{
|
/* ARGBEGIN{
|
||||||
|
|
||||||
}ARGEND
|
}ARGEND */
|
||||||
|
|
||||||
threadcreate(start_9p, nil, 4096);
|
Node* vm = create_node(argc > 0 ? argv[0] : nil);
|
||||||
supervise_node(create_node(argc > 1 ? argv[0] : nil));
|
proccreate(srvthread, (void*)vm, 4096);
|
||||||
|
supervise_node(vm);
|
||||||
threadexitsall(0);
|
threadexitsall(0);
|
||||||
}
|
}
|
||||||
|
|
1
mkfile
1
mkfile
|
@ -9,7 +9,6 @@ OFILES=\
|
||||||
client.$O\
|
client.$O\
|
||||||
util.$O\
|
util.$O\
|
||||||
node.$O\
|
node.$O\
|
||||||
nodetable.$O\
|
|
||||||
|
|
||||||
HFILES=dat.h\
|
HFILES=dat.h\
|
||||||
fns.h\
|
fns.h\
|
||||||
|
|
11
node.c
11
node.c
|
@ -37,7 +37,6 @@ void node_execute(Node* self) {
|
||||||
Node* create_node(char* filename) {
|
Node* create_node(char* filename) {
|
||||||
|
|
||||||
initdraw(nil, nil, "kuro");
|
initdraw(nil, nil, "kuro");
|
||||||
unlockdisplay(display);
|
|
||||||
|
|
||||||
KuroMemory* self = (KuroMemory*)malloc(sizeof(KuroMemory));
|
KuroMemory* self = (KuroMemory*)malloc(sizeof(KuroMemory));
|
||||||
Node* node = (Node*)malloc(sizeof(Node));
|
Node* node = (Node*)malloc(sizeof(Node));
|
||||||
|
@ -66,7 +65,7 @@ void supervise_node(Node* self) {
|
||||||
WindowStatus status;
|
WindowStatus status;
|
||||||
Rune kbd;
|
Rune kbd;
|
||||||
|
|
||||||
if ((mctl = initmouse(nil, screen)) == nil) {
|
if ((mctl = initmouse(nil, self->memory->img)) == nil) {
|
||||||
sysfatal("couldn't initialize mctl");
|
sysfatal("couldn't initialize mctl");
|
||||||
}
|
}
|
||||||
if ((kctl = initkeyboard(nil)) == nil) {
|
if ((kctl = initkeyboard(nil)) == nil) {
|
||||||
|
@ -84,20 +83,20 @@ void supervise_node(Node* self) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (alt(alts)) {
|
switch (alt(alts)) {
|
||||||
case PORT_MOUSE:
|
case PORT_MOUSE:
|
||||||
print("got a mouse event");
|
print("got a mouse event\n");
|
||||||
break;
|
break;
|
||||||
case PORT_RESIZE:
|
case PORT_RESIZE:
|
||||||
/*if (getwindow(display, Refnone) < 0)
|
/*if (getwindow(display, Refnone) < 0)
|
||||||
sysfatal("couldn't resize");*/
|
sysfatal("couldn't resize");*/
|
||||||
print("got a resize event");
|
print("got a resize event\n");
|
||||||
break;
|
break;
|
||||||
case PORT_KBD:
|
case PORT_KBD:
|
||||||
print("got a keypress");
|
print("got a keypress\n");
|
||||||
break;
|
break;
|
||||||
case PORT_STATUS:
|
case PORT_STATUS:
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case KURO_QUITS:
|
case KURO_QUITS:
|
||||||
print("VM died - let's clean up the data");
|
print("VM died - let's clean up the data\n");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
42
nodetable.c
42
nodetable.c
|
@ -1,42 +0,0 @@
|
||||||
#include "dat.h"
|
|
||||||
#include "fns.h"
|
|
||||||
|
|
||||||
void nodetbl_add(NodeTable* self, NodeRef* node) {
|
|
||||||
int i;
|
|
||||||
NodeRef* n;
|
|
||||||
if (self && node) {
|
|
||||||
i = (int)(node->id%256);
|
|
||||||
n = self->data[i];
|
|
||||||
if (n && n->next) {
|
|
||||||
n = n->next;
|
|
||||||
}
|
|
||||||
if (n) {
|
|
||||||
n->next = node;
|
|
||||||
} else {
|
|
||||||
n = node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void nodetbl_del(NodeTable* self, uvlong id) {
|
|
||||||
NodeRef* n;
|
|
||||||
NodeRef* nprev;
|
|
||||||
|
|
||||||
if (self) {
|
|
||||||
for(int i = 0; i <= 255; i++) {
|
|
||||||
n = self->data[i];
|
|
||||||
|
|
||||||
while (n && n->id != id && n->next) {
|
|
||||||
nprev = n;
|
|
||||||
n = n->next;
|
|
||||||
}
|
|
||||||
if (n->id == id) {
|
|
||||||
if (nprev) {
|
|
||||||
nprev->next = n->next;
|
|
||||||
}
|
|
||||||
free(n);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
76
srv.c
76
srv.c
|
@ -1,17 +1,7 @@
|
||||||
#include "dat.h"
|
#include "dat.h"
|
||||||
#include "fns.h"
|
#include "fns.h"
|
||||||
|
|
||||||
static NodeTable nodes;
|
static Node* node;
|
||||||
static QLock id_lock;
|
|
||||||
|
|
||||||
static uvlong get_next_id(void) {
|
|
||||||
static uvlong id = 0;
|
|
||||||
uvlong next;
|
|
||||||
qlock(&id_lock);
|
|
||||||
next = ++id;
|
|
||||||
qunlock(&id_lock);
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
|
|
||||||
Aux* create_aux(FileType t) {
|
Aux* create_aux(FileType t) {
|
||||||
Aux* self = (Aux*)malloc(sizeof(Aux));
|
Aux* self = (Aux*)malloc(sizeof(Aux));
|
||||||
|
@ -35,42 +25,13 @@ void kuro_read(Req* r) {
|
||||||
Aux* a = (Aux*)r->fid->file->aux;
|
Aux* a = (Aux*)r->fid->file->aux;
|
||||||
switch (a->type) {
|
switch (a->type) {
|
||||||
case CTL:
|
case CTL:
|
||||||
|
case MEMORY:
|
||||||
default:
|
default:
|
||||||
respond(r, nil);
|
respond(r, nil);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void new_window(char* filename, int new) {
|
|
||||||
int rw_fd[2];
|
|
||||||
char client_fd[32] = {0};
|
|
||||||
char client_id[32] = {0};
|
|
||||||
uvlong id;
|
|
||||||
NodeRef* noderef;
|
|
||||||
|
|
||||||
pipe(rw_fd);
|
|
||||||
id = get_next_id();
|
|
||||||
|
|
||||||
noderef = (NodeRef*)malloc(sizeof(NodeRef));
|
|
||||||
noderef->id = id;
|
|
||||||
noderef->fd[0] = rw_fd[0];
|
|
||||||
noderef->fd[1] = rw_fd[1];
|
|
||||||
nodetbl_add(&nodes, noderef);
|
|
||||||
|
|
||||||
sprintf(client_fd, "%d", rw_fd[1]);
|
|
||||||
sprintf(client_id, "%d", id);
|
|
||||||
|
|
||||||
rfork(RFNAMEG);
|
|
||||||
char* a[] = { "kuro", "-p", client_fd, "-i", client_id, new ? "-n" : filename, new ? filename : 0, 0 };
|
|
||||||
exec("./kuro", a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void newwindowthread(void* arg) {
|
|
||||||
char* filename = (char*)arg;
|
|
||||||
new_window(filename, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_ctl(Req* r) {
|
void write_ctl(Req* r) {
|
||||||
char cmd[16] = {0};
|
char cmd[16] = {0};
|
||||||
char* c = r->ifcall.data;
|
char* c = r->ifcall.data;
|
||||||
|
@ -92,13 +53,11 @@ void write_ctl(Req* r) {
|
||||||
print("cmd: %s\n", cmd);
|
print("cmd: %s\n", cmd);
|
||||||
print("arg: %s\n", c);
|
print("arg: %s\n", c);
|
||||||
|
|
||||||
if (strequ(cmd, "new")) {
|
|
||||||
threadcreate(newwindowthread, c, 256);
|
|
||||||
respond(r, nil);
|
|
||||||
} else {
|
|
||||||
print("unknown command...\n");
|
print("unknown command...\n");
|
||||||
|
r->ofcall.count = r->ifcall.count;
|
||||||
respond(r, nil);
|
respond(r, nil);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void kuro_write(Req* r) {
|
void kuro_write(Req* r) {
|
||||||
|
@ -107,6 +66,7 @@ void kuro_write(Req* r) {
|
||||||
case CTL:
|
case CTL:
|
||||||
write_ctl(r);
|
write_ctl(r);
|
||||||
break;
|
break;
|
||||||
|
case CPU:
|
||||||
default:
|
default:
|
||||||
respond(r, nil);
|
respond(r, nil);
|
||||||
break;
|
break;
|
||||||
|
@ -119,21 +79,25 @@ char* mk_mtpt(char* parent, char* buf) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_9p() {
|
void start_9p(Node* n) {
|
||||||
|
node = n;
|
||||||
char* mtpt_base = getenv("KURO_MTPT");
|
char* mtpt_base = getenv("KURO_MTPT");
|
||||||
if (mtpt_base) {
|
|
||||||
char mtpt[256] = "TESTING LIKE THIS SHOULD NOT BE NECESSARY; AYEYEYEYEYE";
|
if (mtpt_base && n) {
|
||||||
|
char mtpt[256] = {0};
|
||||||
mk_mtpt(mtpt_base, mtpt);
|
mk_mtpt(mtpt_base, mtpt);
|
||||||
int i = ensure(mtpt);
|
|
||||||
print("%d result of ensure\n", i);
|
if (ensure(mtpt)) {
|
||||||
print("%s\n", mtpt);
|
print("kuro fsys: %s\n", mtpt);
|
||||||
|
} else {
|
||||||
|
sysfatal("couldn't create fsys at %s\n", mtpt);
|
||||||
|
}
|
||||||
|
|
||||||
Srv srv = { .read = kuro_read, .write = kuro_write };
|
Srv srv = { .read = kuro_read, .write = kuro_write };
|
||||||
Tree* tree = alloctree(nil, nil, DMDIR | 0777, fs_destroy_file);
|
Tree* tree = alloctree(nil, nil, DMDIR | 0777, fs_destroy_file);
|
||||||
srv.tree = tree;
|
srv.tree = tree;
|
||||||
closefile(createfile(tree->root, "ctl", nil, DMAPPEND | 0600, create_aux(CTL)));
|
closefile(createfile(tree->root, "ctl", nil, 0600, create_aux(CTL)));
|
||||||
closefile(tree->root);
|
|
||||||
/* TODO: figure out how to kill the server cleanly so we don't need MREPL */
|
|
||||||
threadpostmountsrv(&srv, nil, mtpt, MREPL | MCREATE);
|
threadpostmountsrv(&srv, nil, mtpt, MREPL | MCREATE);
|
||||||
threadexits(0);
|
threadexits(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue