Allocate pollfd array rather than using a VLA

This commit is contained in:
C. McEnroe 2021-09-26 18:11:38 -04:00
parent 55c4755943
commit b5437a42f9

View File

@ -312,6 +312,14 @@ int main(int argc, char *argv[]) {
} }
setTitle(); setTitle();
struct pollfd *fds = calloc(1 + 2 * services.len, sizeof(*fds));
if (!fds) {
syslog(LOG_ERR, "calloc: %m");
goto shutdown;
}
fds[0].fd = fifo;
fds[0].events = POLLIN;
sigset_t mask; sigset_t mask;
sigemptyset(&mask); sigemptyset(&mask);
for (;;) { for (;;) {
@ -331,6 +339,11 @@ int main(int argc, char *argv[]) {
} }
if (signals[SIGHUP]) { if (signals[SIGHUP]) {
parseConfig(configPath); parseConfig(configPath);
fds = reallocarray(fds, 1 + 2 * services.len, sizeof(*fds));
if (!fds) {
syslog(LOG_ERR, "reallocarray: %m");
goto shutdown;
}
setTitle(); setTitle();
signals[SIGHUP] = 0; signals[SIGHUP] = 0;
} }
@ -340,10 +353,6 @@ int main(int argc, char *argv[]) {
signals[SIGINFO] = 0; signals[SIGINFO] = 0;
} }
struct pollfd fds[1 + 2 * services.len];
fds[0].fd = fifo;
fds[0].events = POLLIN;
struct timespec deadline = {0}; struct timespec deadline = {0};
for (size_t i = 0; i < services.len; ++i) { for (size_t i = 0; i < services.len; ++i) {
struct Service *service = &services.ptr[i]; struct Service *service = &services.ptr[i];
@ -414,6 +423,7 @@ int main(int argc, char *argv[]) {
} }
} }
shutdown:
close(fifo); close(fifo);
unlink(fifoPath); unlink(fifoPath);