From 9a601884193dda4fd259d715392889402e477419 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 11 Feb 2021 23:03:49 +0100 Subject: Added msging --- libgui/msg.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 libgui/msg.c (limited to 'libgui/msg.c') diff --git a/libgui/msg.c b/libgui/msg.c new file mode 100644 index 0000000..6898121 --- /dev/null +++ b/libgui/msg.c @@ -0,0 +1,25 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#include +#include +#include +#include + +int msg_send(u32 pid, enum message_type type, void *data) +{ + assert((signed)pid != -1); + char path[32] = { 0 }; + sprintf(path, "/proc/%d/msg", pid); + struct message msg = { .magic = MSG_MAGIC, .src = getpid(), .type = type, .data = data }; + return write(path, &msg, 0, sizeof(msg)); +} + +int msg_receive(struct message *msg) +{ + int ret = read("/proc/self/msg", msg, 0, sizeof(*msg)); + assert(msg->magic == MSG_MAGIC); + if (msg->magic == MSG_MAGIC && ret == sizeof(*msg)) + return ret; + else + return -1; +} -- cgit v1.2.3