We currently only start seats (switch to their VT) during startup but we
should also do that for hotplugged seats. Therefore, move that logic into
kmscon_seat and perform the startup after the seat is fully set up.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
We don't use the newly created objects so no need to return them.
Furthermore, we want the functions to already perform actions on the
objects so there is no guarantee the objects are still alive after
function return. Thus, simply return nothing.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Same as previous commit: Move uterm-monitor device-data handling into the
real device create/destroy functions to allow dynamic device removal.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
If we want to be able to destroy seats from anywhere, not just
uterm-monitor callbacks, we need to be able to reset the monitor-event
seat-data so we no longer access the seat memory.
Hence, move the seat-data set/reset logic into the actual seat
creation/destroy functions.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
We should handle everything --listen related in kmscon_main so pass in the
allowed-VTs mask from the caller.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Add a very basic man-page infrastructure so we can easily add new
docbook-style manpages.
Also add kmscon.1 man-page with a basic overview.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
CAP_KILL will be documented in kmscon manuals, but we should actually
check for the capability during startup.
However, this requires linking with libcap or libcap-ng and we currently
want to avoid that for such a simple task.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Ignore SIGPIPE globally. We handle HUP correctly everywhere and this
signal is just annoying.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
If we autoselect a VT and the current VT is unused, use it. This is
similar to the behavior of Weston and X-Server.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
If we run in listen mode, we are supposed to take over a seat. If a seat
supports VTs (like kernel VTs or kmscon cdev fake VTs) we assume that
there is some manager for these VTs (the one who created them). Therefore,
there is no need to run kmscon in listen mode on these seats. Instead, you
should run kmscon in default mode on these seats.
We enforce this limitation because if the VT-master on those seats dies
and causes a HUP, they have no way to notify us when they startup again.
Therefore, this kind of setup is broken. Furthermore, no-one would every
want such setups.
Instead use the startup mechanism of the VT/seat-manager to start kmscon
in default mode on those seats.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Instead of configuring everything for every kind of situation, we now
split kmscon into two modes: default-mode and listen-mode
In default-mode we run on the given seats once until we encounter a HUP or
until we are closed. It's a perfect replacement for agetty.
In listen-mode, we run only on non-VT seats and provide the full kmscon
functionality. We run as system daemon and wait for new seats and close
seats if they are destroyed. We simply provide a full system-console on
all seats.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Instead of using one option for each selection mode, we now provide a new
option --gpus. It takes as argument the selection mode to use.
We also remove the --video-devices option as it doesn't fit into the big
picture. Instead, we should provide a blacklist and users would then use
--gpu=all --blacklist-video=<blacklist> instead.
However, blacklisting is also required for input devices and until we
figure it out, we will provide no blacklisting at all.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
We want only C-source files in ./src and the documents ./docs directory is
meant to contain any other sources.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
If no VT name is explicitly given, we need to use VT_OPENQRY to find one.
This used to work until we switched to supporting fake-VTs. Fix this again
to work like it used to.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
This helper returns the VT type. This will allow external users to see
whether we have real VTs or whether we don't.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
K_OFF is not available on older kernels and it is currently discussed
whether it should be replaced on newer kernels. Therefore, set K_RAW
before trying K_OFF and then ignore errors if K_OFF cannot be set.
Reported-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
We need to set "active" to false during delayed deactivation, as
otherwise we have inconsistent state in respect to the seat subsystem.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This mode is used to start/stop blinking cursors. As vim uses this
heavily, we should simply ignore it to avoid printing useless debug
messages.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Instead of not handling the keyboard shortcuts we should ignore them but
mark them as handled. Otherwise, we might get them from the parent session
and they will end up cluttering the terminal log.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
The VT API provides a VT_WAITACTIVE ioctl which waits until the VT got
activated. We use the same technique as with blocking reads() to implement
this without threads.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
We must unregister the display callback when removing a screen. Otherwise,
we keep writing to the screen memory which becomes invalid then.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
ctrl+alt is already used by many other applications so lets use some other
unused shortcut modifiers.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
The --configdir parameter allows specifying another configuration
directory than the default /etc/kmscon.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
If kmscon is started without the --multi-session option, we no longer
provide multi-session support (now the default). This is for better
backwards compatibility to agetty and friends.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
--vt should only be used when kmscon runs on a single seat. Otherwise,
this VT will be forced on all seats and each kmscon instance _might_
collide.
If this is done with care, the --vt/--seats combination can work. However,
the use-cases are negligible and we should rather warn the ordinary user
not to do it.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
If there is already a kmscon instance running that provides fake-VTs, then
lets use it. This allows stacking kmscon processes and is very useful for
debugging.
Also other applications that use uterm can now run inside of kmscon
without any other special configuration.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
We cannot have multiple instances of kmscon running with cdev emulation,
so disable it by default. A kmscon-system-daemon now needs --cdev if you
want fake VTs to work.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>