Kaydet (Commit) 5487fe1f authored tarafından Gürer Özen's avatar Gürer Özen

Ölen child processleri yetim bırakma.

Result'un hangi paketin betiğinden geldiğini de döndür.
üst ef40c3e6
......@@ -33,6 +33,7 @@ extern struct Proc my_proc;
void proc_init(void);
struct ProcChild *proc_fork(void (*child_func)(void));
void proc_finish(void);
int proc_listen(struct ProcChild **senderp, int *cmdp, size_t *sizep, int timeout);
int proc_send(struct ProcChild *p, int cmd, const void *data, size_t data_size);
int proc_recv(struct ProcChild *p, void *datap, size_t size);
......
......@@ -51,11 +51,16 @@ load_file(const char *fname, int *sizeptr)
static void *chan;
static int chan_id;
int bk_node;
char *bk_app;
static int
send_result(int cmd, const char *data, size_t size)
{
ipc_start(cmd, chan, chan_id, 0);
if (CMD_RESULT == cmd) {
ipc_pack_arg(bk_app, strlen(bk_app));
}
if (data) {
if (size == 0) size = strlen(data);
ipc_pack_arg(data, size);
......@@ -120,6 +125,8 @@ do_execute(int node, const char *app)
log_debug(LOG_JOB, "Execute(%s,%s)\n", model_get_path(node), app);
bk_app = (char *) app;
csl_setup();
if (0 != db_get_code(model_parent(node), app, &code, &code_size)) return -1;
......@@ -136,9 +143,6 @@ do_execute(int node, const char *app)
return e;
}
int bk_node;
char *bk_app;
static void
exec_proc(void)
{
......@@ -168,7 +172,7 @@ do_call(int node)
int cnt = 0;
size_t size;
// FIXME: package count, error msg for fork
// FIXME: package count
send_result(CMD_RESULT_START, NULL, 0);
for (t = apps; t; t = s) {
s = strchr(t, '/');
......@@ -179,7 +183,11 @@ do_call(int node)
bk_node = node;
bk_app = t;
p = proc_fork(exec_proc);
if (p) ++cnt;
if (p) {
++cnt;
} else {
send_result(CMD_ERROR, "fork failed", 11);
}
}
while(1) {
struct ipc_data *ipc;
......@@ -188,15 +196,13 @@ do_call(int node)
--cnt;
if (!cnt) break;
} else {
proc_recv(p, &ipc, size);
proc_send(TO_PARENT, cmd, ipc, size);
proc_recv(p, &ipc, size);
proc_send(TO_PARENT, cmd, ipc, size);
}
}
send_result(CMD_RESULT_END, NULL, 0);
}
free(apps);
return 0;
}
......
......@@ -69,7 +69,6 @@ main(int argc, char *argv[])
break;
}
}
// puts("tick");
}
return 0;
......
......@@ -12,6 +12,7 @@
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include "process.h"
#include "log.h"
......@@ -55,12 +56,15 @@ add_child(pid_t pid, int to, int from)
static void
rem_child(int nr)
{
int status;
waitpid(my_proc.children[nr].pid, &status, 0);
--my_proc.nr_children;
if (0 == my_proc.nr_children) return;
(my_proc.children)[nr] = (my_proc.children)[my_proc.nr_children];
}
static void
void
proc_finish(void)
{
exit(0);
......@@ -145,7 +149,7 @@ proc_listen(struct ProcChild **senderp, int *cmdp, size_t *sizep, int timeout)
*sizep = (ipc & 0x00FFFFFF);
return 1;
} else {
printf("Child %d,%d dead\n", i, my_proc.children[i].pid);
printf("Child %d,%d dead\n", i, my_proc.children[i].pid);
rem_child(i);
*senderp = NULL;
*cmdp = 0xFF;
......
......@@ -179,17 +179,38 @@ static int
write_rpc(struct connection *c, unsigned int cmd, int id, const char *buffer, size_t size)
{
unsigned char head[8];
head[4] = (id >> 24) & 0xFF;
head[5] = (id >> 16) & 0xFF;
head[6] = (id >> 8) & 0xFF;
head[7] = id & 0xFF;
if (RPC_RESULT == cmd) {
char *s;
size_t sz;
ipc_get_arg(&s, &sz);
printf("writeRPC(%d,%d,%d,%s,%d,%s)\n", cmd, id, sz, s, size, buffer);
head[0] = cmd & 0xFF;
head[1] = ((size + 1 + sz) >> 16) & 0xFF;
head[2] = ((size + 1 + sz) >> 8) & 0xFF;
head[3] = (size + 1 + sz) & 0xFF;
send(c->sock, head, 8, 0);
send(c->sock, buffer, size, 0);
send(c->sock, " ", 1, 0);
send(c->sock, s, sz, 0);
return 0;
}
printf("writeRPC(%d,%d,%d,%s)\n", cmd, id, size, buffer);
head[0] = cmd & 0xFF;
head[1] = (size >> 16) & 0xFF;
head[2] = (size >> 8) & 0xFF;
head[3] = size & 0xFF;
head[4] = (id >> 24) & 0xFF;
head[5] = (id >> 16) & 0xFF;
head[6] = (id >> 8) & 0xFF;
head[7] = id & 0xFF;
send(c->sock, head, 8, 0);
if (size) send(c->sock, buffer, size, 0);
return 0;
}
......@@ -204,7 +225,8 @@ parse_rpc(struct connection *c)
cmd = get_cmd(c->buffer);
id = get_id(c->buffer + 4);
printf("RPC cmd %d, id %d, size %d\n", cmd, id, c->data_size);
printf("RPC cmd %d, id %d, size %d\n", cmd, id, c->data_size);
args.buffer = c->buffer + 8;
args.pos = 0;
args.size = c->data_size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment