commit ee1d108f5e904a480f409dc7720c9b46edb992f2 from: Onana Onana Xavier Manuel date: Tue Aug 11 03:04:16 2026 UTC Added array to identify poll types and changed the path for storing sockets to /tmp/ria/sock instead of /tmp/ria commit - 61d67952bb7d89f33f258407967f721c83a3bdb6 commit + ee1d108f5e904a480f409dc7720c9b46edb992f2 blob - 19b99122f4a2cc2cc6a0bf3110a20d08e92dfb6c blob + 7a3236c2da5da380a45cb5aeb3bc41a0d934c474 --- prot.h +++ prot.h @@ -1,4 +1,5 @@ -#define RIA_SOCK_PATH "/tmp/ria.sock" +#define RIA_PATH "/tmp/ria" +#define RIA_SOCK_PATH RIA_PATH "/0" enum msg_type { MSG_TYPE_DRAW, blob - 0c3d3f212aa575bf622fffd69b5eb30525e9bf0a blob + 4b3b6479aea8b915720f4837aff209cb02b61261 --- ria/Makefile +++ ria/Makefile @@ -16,7 +16,7 @@ HDRS=\ event.h ${BIN}: ${OBJS} ${HDRS} - ${CC} ${OBJS} -o ${BIN} + ${CC} ${OBJS} -o ${BIN} -lutil .c.o: ${CC} -fPIE -c $< -o $@ ${CFLAGS} blob - 2c22d89edd26ebfa94da6439d811b57b062e1d00 blob + be15adcfd9ff60c0e56fd0140b0a396d78dcb904 --- ria/cursor.c +++ ria/cursor.c @@ -1,9 +1,16 @@ +#include + #include "fb.h" +#include "wsctl.h" void button_press(int button) { cursor.held[button] = 1; + + if (button == BUTTON_3) { + wsctl_fork(); + } } void blob - f3eee918ea7d3b2b6bf59106d11e3d56588550d0 blob + a8309bdc5f78d1162658f15c2d6cd903e4b40c3b --- ria/ria.c +++ ria/ria.c @@ -2,12 +2,16 @@ #include #include #include +#include +#include + #include #include "wsctl.h" #include "event.h" #include "fb.h" +#include "prot.h" static volatile sig_atomic_t running = 1; @@ -25,13 +29,30 @@ void int_handler(int); int main() { + struct stat pstat; struct event ev; int ret; signal(SIGTERM, int_handler); signal(SIGINT, int_handler); + if (mkdir(RIA_PATH, 0755) == -1 && errno != EEXIST) { + perror("failed to create directory for ria"); + return -1; + } + + if (stat(RIA_PATH, &pstat) == -1) { + perror("stat failed"); + } + + if (S_ISDIR(pstat.st_mode) == 0) { + errno = ENOTDIR; + perror("failed"); + return -1; + } + if ((fb = wsctl_init()) == NULL) { + perror("Could not initialize ria"); return -1; } blob - 9e8340f2a0f48187013f4f16af117daa104484e4 blob + 32eefef87d805428144c1408a4049ca5bad0cbad --- ria/wsctl.c +++ ria/wsctl.c @@ -29,7 +29,19 @@ static int read_mouse(void); static int read_cmd(void); static int sock_init(void); static void sock_exit(void); +static int add_fd(int, int); +enum fdtype { + FD_MOUSE, + FD_KEYBOARD, + FD_PROTOCOL, +}; + +struct fdinfo { + int fd; + enum fdtype type; +}; + static struct { int fd; struct { @@ -47,7 +59,9 @@ static struct { struct sockaddr_un addr; } sock; - struct fbinfo *fb; + size_t pflen; + struct pollfd *pfds; + struct fdinfo *pfinfo; } wsctl; struct fbinfo* @@ -153,9 +167,13 @@ wsctl_init() cursor.x = fbi->width / 2; cursor.y = fbi->height / 2; - wsctl.fb = fbi; + fb = fbi; - return fbi; + add_fd(wsctl.mouse.fd, FD_MOUSE); + add_fd(wsctl.kbd.fd, FD_KEYBOARD); + add_fd(wsctl.sock.fd, FD_PROTOCOL); + + return fb; } void @@ -168,37 +186,32 @@ wsctl_exit() else { if (mode != WSDISPLAYIO_MODE_EMUL) { mode = WSDISPLAYIO_MODE_EMUL; - munmap(wsctl.fb->dat, wsctl.fb->bytes); + munmap(fb->dat, fb->bytes); if (ioctl(wsctl.fd, WSDISPLAYIO_SMODE, &mode) == -1) perror("failed to smode to emul"); } } + free(wsctl.pfinfo); + free(wsctl.pfds); close(wsctl.mouse.fd); - free(wsctl.fb->bdat); + free(fb->bdat); close(wsctl.kbd.fd); close(wsctl.fd); - free(wsctl.fb); + free(fb); sock_exit(); } int wsctl_run() { - struct pollfd pfds[3]; + struct fdinfo *info; + struct pollfd *pfd; int ret; - pfds[0].fd = wsctl.mouse.fd; - pfds[1].fd = wsctl.kbd.fd; - pfds[2].fd = wsctl.sock.fd; + ret = poll(wsctl.pfds, wsctl.pflen, -1); - pfds[0].events = POLLIN; - pfds[1].events = POLLIN; - pfds[2].events = POLLIN; - - ret = poll(pfds, 3, -1); - if (ret == -1) { if (errno == EINTR) return 0; @@ -207,18 +220,58 @@ wsctl_run() return -1; } - if (pfds[0].revents & POLLIN) - read_mouse(); + for (int i = 0; i < wsctl.pflen; i++) { + info = &wsctl.pfinfo[i]; + pfd = &wsctl.pfds[i]; - if (pfds[1].revents & POLLIN) - read_kbd(); - if (pfds[2].revents & POLLIN) - read_cmd(); + if (pfd->revents & POLLIN) { + switch (info->type) { + case FD_MOUSE: + read_mouse(); + break; + case FD_KEYBOARD: + read_kbd(); + break; + case FD_PROTOCOL: + read_cmd(); + break; + } + } + } return 0; } +int +wsctl_fork() +{ + return 0; +} + +static int +add_fd(int fd, int type) +{ + struct fdinfo *infos; + struct pollfd *pfds; + int idx = wsctl.pflen; + + infos = reallocarray(wsctl.pfinfo, sizeof(*wsctl.pfinfo), wsctl.pflen + 1); + pfds = reallocarray(wsctl.pfds, sizeof(*wsctl.pfds), wsctl.pflen + 1); + + infos[idx].type = type; + infos[idx].fd = fd; + + pfds[idx].events = POLLIN; + pfds[idx].fd = fd; + + wsctl.pfinfo = infos; + wsctl.pfds = pfds; + wsctl.pflen++; + + return 0; +} + static int init_mouse() { blob - 53028ef6deb1cf043d22636af2f10570970397b5 blob + d1ee061316d1a1d5a64709d48c998e52b1237f7b --- ria/wsctl.h +++ ria/wsctl.h @@ -1,3 +1,6 @@ struct fbinfo *wsctl_init(void); void wsctl_exit(void); int wsctl_run(void); +int wsctl_fork(void); + +int pty_connect(void);