cdev: fix copying pollhandles correctly

The pollhandle is solely implemented in libfuse and does not correspond to
some kernel-intern object. Instead, the kernel notifies us when it has
poll-waiters via a flag. If that flag is set we should notify the kernel
whenever the poll-flags change.

Therefore, we can safely copy the pollhandle all the time and delete our
temporary handles.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
cdev: introduce client 'dead' state

Files have the disadvantage that the kernel (or in this case 'we') cannot
force a client to close it. Instead, we have to mark it as 'dead' and wait
until the client closes the file theirself.
While marked as 'dead' we always return EPIPE or signal EPOLLHUP so the
client will notice that the file is dead.

This fixes a bug where when we forced an unregistration of a cdev session,
the cdev_client went away too early and the user still had the file open.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
uterm: vt: handle HUP on controlling TTY

If the controlling TTY (in our case the VT) signals us a HUP, we should
consider it closed and forward that to the caller. This does normally not
happen on real VTs, however, on fake-VTs this happens if the parent goes
away.

We forward the HUP to the controlling subsystem which then has to deal
with it. But more importantly, we disable the fd so we don't hog the CPU
by unconditionally flushing the queue.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
seat: allow asynchronous command scheduling

When an asynchronous session-deactivation is finished, we need to know
which task to do now. As we cannot let the caller decide, because we are
asynchronous, we have to remember the task.

Three tasks are defined now but this can be extended. We reset the task
after the current session got deactivated. This guarantees that we never
have pending schedules but always return to a sane default even if we
missed a notification.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
seat: schedule dummy session if no other session is available

In special situations (like forcing deactivation of a background session)
we might end up with no real registered session and no current session. In
these situations, we should allow the session-scheduler to schedule dummy
sessions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
shl: misc: add shl_string_list_count() helper

This helper counts the entries in a string-list with an option to ignore
empty elements.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
conf: improve --vt warning by allowing --seats=,all

If a seat is called "all" and we want to use it as single seat, we
currently have to pass "--seats=all," or "--seats=,all" etc. so it is not
detected as --seats=all.
However, our warning when --vt is used with it does not respect this.
Improve this warning to detect this case and correctly ignore it then.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
seat: protect kmscon_seat_remove_display() correctly

We have to check for NULL pointers like all the other public entries do.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
seat: forward HUP to caller

We now forward VT_HUP to the caller so they can react on it. Default
behavior is to shutdown this seat. In single-seat mode we also close the
application.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
seat: unref session after unregistration

Session registration does not provide a reference to the caller. Instead,
the seat itself owns the reference. Hence, we must clear this reference
during unregistration, otherwise we will never free the session structure.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
pty: free seat argument on destruction

We didn't correctly free this parameter even though we dup'ed it earlier.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
text: gltex: free atlas during destruction

If we remove an atlas, we have to correctly free its memory. Otherwise, we
will loose the memory.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
pty: simplify pty_close()

The old logic is no longer needed as we use edge-triggered fd notification
now. Therefore, simplify the helpers to make them more readable.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
shl: hook: allow callbacks to destroy the hook

If we currently dispatch a callback and they unregister themself and then
destroy the hook, we currently do not free the hook as we would free
memory that is used in the callstack.
However, it is a valid use-case for hook-callbacks to destroy the hook.
Therefore, we set a "dead" flag and destroy the hook after all callbacks
are done.

This fixes some memory-leaks inside the shared-signal callbacks of eloop.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: fix memory loop when signal registration fails

If the signal-registration fails, we need to destroy it again. Otherwise,
it will keep a reference to the current eloop-object and hence it will
never get freed.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
terminal: use "opened" logic

We already keep the open state as "opened" so we should use it instead of
always pushing the work down to the pty layer.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: add child-reaper event sources

If multiple childs die simultaneously, only a single SIGCHLD is queued.
Only after our process got scheduled and we unqueued the SIGCHLD, a next
signal can be queued. Therefore, using SIGCHLD as indicator that a
specific child died does not work reliably.

Instead, we must use waitpid() to wait for childs. Hence, we introduce a
new event-source which does that. It reports the PID/status combination
for each child to the registered callbacks.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
pty: use the new child-reaper sources

Instead of registering for SIGCHLD we should use the child-reaper sources
to avoid nasty race-conditions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
seat: fix rescheduling sessions if none is active

If no session is active, we must not choose the scheduled session as
start-place. Otherwise, we will not schedule any session because the
start-session isn't used in the iteration.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>