mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-24 12:55:41 +02:00
module/i3: avoid stack-allocating large buffers
This fixes a stack-overflow issue with musl (which uses small stacks).
This commit is contained in:
parent
a827cc80d4
commit
18ba3723d4
1 changed files with 6 additions and 3 deletions
|
@ -439,7 +439,9 @@ run(struct module *mod)
|
||||||
send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
|
send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
|
||||||
send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\"]");
|
send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\"]");
|
||||||
|
|
||||||
char buf[1 * 1024 * 1024]; /* Some replies are *big*. TODO: grow dynamically */
|
/* Some replies are *big*. TODO: grow dynamically */
|
||||||
|
static const size_t reply_buf_size = 1 * 1024 * 1024;
|
||||||
|
char *buf = malloc(reply_buf_size);
|
||||||
size_t buf_idx = 0;
|
size_t buf_idx = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -458,9 +460,9 @@ run(struct module *mod)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
assert(fds[1].revents & POLLIN);
|
assert(fds[1].revents & POLLIN);
|
||||||
assert(sizeof(buf) > buf_idx);
|
assert(reply_buf_size > buf_idx);
|
||||||
|
|
||||||
ssize_t bytes = read(sock, &buf[buf_idx], sizeof(buf) - buf_idx);
|
ssize_t bytes = read(sock, &buf[buf_idx], reply_buf_size - buf_idx);
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
LOG_ERRNO("failed to read from i3's socket");
|
LOG_ERRNO("failed to read from i3's socket");
|
||||||
break;
|
break;
|
||||||
|
@ -550,6 +552,7 @@ run(struct module *mod)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
close(sock);
|
close(sock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue