Allow parent to send msgs to workers via kore_msg.

It wasn't possible for the parent process to send messages
directly via kore_msg_send() to other worker processes.

This is now rectified to from the parent process one can call
kore_msg_send() with a worker destination and it'll work.
This commit is contained in:
Joris Vink 2022-02-01 10:36:07 +01:00
parent b3f54e290a
commit 23d762d682
3 changed files with 40 additions and 8 deletions

View File

@ -774,6 +774,7 @@ int kore_worker_keymgr_response_verify(struct kore_msg *,
void kore_worker_entry(struct kore_worker *) __attribute__((noreturn));
struct kore_worker *kore_worker_data(u_int8_t);
struct kore_worker *kore_worker_data_byid(u_int16_t);
void kore_platform_init(void);
void kore_platform_sandbox(void);

View File

@ -154,17 +154,33 @@ void
kore_msg_send(u_int16_t dst, u_int8_t id, const void *data, size_t len)
{
struct kore_msg m;
struct connection *c;
struct kore_worker *kw;
m.id = id;
m.dst = dst;
m.length = len;
m.src = worker->id;
net_send_queue(worker->msg[1], &m, sizeof(m));
if (worker == NULL) {
m.src = KORE_MSG_PARENT;
if ((kw = kore_worker_data_byid(dst)) == NULL) {
kore_log(LOG_NOTICE, "no such worker by id %u", dst);
return;
}
c = kw->msg[0];
m.dst = kw->id;
} else {
m.src = worker->id;
c = worker->msg[1];
}
net_send_queue(c, &m, sizeof(m));
if (data != NULL && len > 0)
net_send_queue(worker->msg[1], data, len);
net_send_queue(c, data, len);
net_send_flush(worker->msg[1]);
net_send_flush(c);
}
static int

View File

@ -262,12 +262,27 @@ kore_worker_spawn(u_int16_t idx, u_int16_t id, u_int16_t cpu)
}
struct kore_worker *
kore_worker_data(u_int8_t id)
kore_worker_data(u_int8_t idx)
{
if (id >= worker_count)
fatal("id %u too large for worker count", id);
if (idx >= worker_count)
fatal("idx %u too large for worker count", idx);
return (WORKER(id));
return (WORKER(idx));
}
struct kore_worker *
kore_worker_data_byid(u_int16_t id)
{
struct kore_worker *kw;
u_int16_t idx;
for (idx = 0; idx < worker_count; idx++) {
kw = WORKER(idx);
if (kw->id == id)
return (kw);
}
return (NULL);
}
void