lib/waiter: handle -EINTR Now that we're handing non-fatal signals (i.e., SIGCHLD in the process lib), we need to gracefully handle -EINTR from poll(). Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter: remove waitset_destroy We can rely on the ctx free to destroy the waitset. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter: talloc waiters from waitset context We can lose a reference to the first waiter allocated, as set->waiters may be NULL. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter: fix talloc_realloc context Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter: merge time & io waiter init loops Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter: move type-specific members to a union Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter: Defer free of removed waiters We may end up calling remove()-d time waiters if the timeout expires as we're processing an IO waiter. Instead of freeing the waiter in waiter_remove, mark the waiter as inactive, and defer the free until the end of waiter_poll(). Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter: Add timeout waiters Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter: Ensure waiters are consistent during waiter_poll We have a bug at the moment: if the waitset's->waiters array is updated duing waiter_poll() (eg, a client connection is closed, and the client's callback performs a waiter_remove()), then we may invoke callbacks for incorrect waiters. This change uses a consistent waiters array duing execution of waiter_poll, so that any pollfds returned from poll() will result in correct callback invocations. This assumes that a waiter will only ever remove *itself* from the waitset; otherwise, we may call a free()ed waiter. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/waiter: allocate waiters separately from set->waiters Since we reallocate set->waiters, we can't hand out pointers to within that array. Instead, this change allocates the 'struct waiter's separately from the set->waiters array. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
waiter: Don't rely on global variables to keep waiter state Rather than defining the set of waiters (and pollfds) in waiter.c, add a struct waitset to contain these. A waitset is created with waitset_create, which is passed to the waiter_* functions. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Geoff Levand <geoff@infradead.org>
Fix waiter_register return value
Fix memmove size Correct the byte count for several memmove calls. Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Fix waiter alloc Add the missing assignment of the global n_pollfds variable. Fix a minor memory leak in waiter_poll(). Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Move waiter to library Move the waiter routines into the petitboot library. The waiter routines are generic enough to be used for both server and client. Does not change the waiter source. jk: move to lib/waiter/ instead of lib/ Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>