From f1ce6f6a40a45a719eb1bc3069f81127e5814dd8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 23 Apr 2020 06:54:45 -0700 Subject: poll: allow execution of async signal handlers. * sysif.c (poll_wrap): Allocate poll array using alloca so it will be disposed of naturally if an exception occurs. Place sig_save_enable and sig_restore_disable around poll call to allow non-deferred handler execution. --- sysif.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sysif.c b/sysif.c index 4bf76a38..dcea7964 100644 --- a/sysif.c +++ b/sysif.c @@ -1311,7 +1311,7 @@ static val poll_wrap(val poll_list, val timeout_in) { nfds_t i, len = c_num(length(poll_list)); val iter; - struct pollfd *pfd = coerce(struct pollfd *, chk_calloc(len, sizeof *pfd)); + struct pollfd *pfd = coerce(struct pollfd *, alloca(len * sizeof *pfd)); val timeout = default_arg(timeout_in, negone); int res; @@ -1346,18 +1346,18 @@ static val poll_wrap(val poll_list, val timeout_in) } } + sig_save_enable; + res = poll(pfd, len, c_num(timeout)); - if (res < 0) { - free(pfd); + sig_restore_enable; + + if (res < 0) uw_throwf(file_error_s, lit("poll failed: ~d/~s"), num(errno), string_utf8(strerror(errno)), nao); - } - if (res == 0) { - free(pfd); + if (res == 0) return nil; - } { list_collect_decl (out, ptail); @@ -1368,7 +1368,6 @@ static val poll_wrap(val poll_list, val timeout_in) ptail = list_collect(ptail, cons(car(pair), num(pfd[i].revents))); } - free(pfd); return out; } } -- cgit v1.2.3