kuro/kuro.c

75 lines
1.7 KiB
C

#include "dat.h"
#include "fns.h"
static char* mtpt;
int threadmaybackground(void) {
return 1;
}
void threadmain(int argc, char **argv)
{
/* we want to strip any path elements off the executable name */
char exe_name[256] = {0};
char* exe_base;
uvlong node_id = 0;
int client_fd = -1;
int newwin = 0;
char client_9p_str[256] = {0};
strcpy(exe_name, argv[0]);
exe_base = utfrrune(exe_name, '/');
if (exe_base) {
exe_base++;
} else {
exe_base = exe_name;
}
/* if we are the server, serve the filetree on 9p */
if (strequ(exe_base, "kurosrvr")) {
if (argc > 1) {
start_9p(argv[1]);
} else {
sysfatal("usage: kurosrvr mtpt");
}
} else if (strequ(exe_base, "kuro")) {
mtpt = getenv("KURO_MTPT");
if (mtpt == nil) {
sysfatal("KURO_MTPT not set");
}
kuro9p_set_mtpt(mtpt);
print("KURO_MTPT=%s\n", mtpt);
ARGBEGIN{
case 'n':
newwin=1;
break;
case 'i':
sscanf(ARGF(), "%d", &node_id);
break;
case 'p':
sscanf(ARGF(), "%d", &client_fd);
break;
}ARGEND
strcpy(client_9p_str, "new");
if (argv[0]) {
strcat(client_9p_str, " ");
strcat(client_9p_str, argv[0]);
}
if (node_id > 0 && client_fd >= 0) {
supervise_node(create_node(node_id, client_fd, newwin, argv[0]));
} else {
/* if node_id or client_id are missing, ask the server to fork us with them, and forward the filename */
print("9pstr=%s\n", client_9p_str);
kuro9p_write("/ctl", client_9p_str, strlen(client_9p_str));
}
} else {
sysfatal("invoke as kurosrvr to start the background service or kuro to start an application window");
}
}