Currently, we set up our VT with SIGUSR1/2 signals and after that the user may connect the signal handlers to the eloop. However, if we receive a signal in between, the signal gets lost. Therefore, this simply merges the kmscon_vt_connect_eloop function into kmscon_vt_open as there is no obvious reason to split them. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
113 lines
3.0 KiB
C
113 lines
3.0 KiB
C
/*
|
|
* test_console - Test VT Layer
|
|
*
|
|
* Copyright (c) 2011 David Herrmann <dh.herrmann@googlemail.com>
|
|
* Copyright (c) 2011 University of Tuebingen
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
* a copy of this software and associated documentation files
|
|
* (the "Software"), to deal in the Software without restriction, including
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
* the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
/*
|
|
* Test VT Layer
|
|
* This opens a new VT and prints some text on it. You can then change the VT
|
|
* and change back. This is only to test the VT subsystem and event engine.
|
|
* This automatically switches to the new VT. Currently, the display gets
|
|
* freezed then because we aren't painting to the framebuffer yet. Use
|
|
* ctrl+alt+FX (or some equivalent) to switch back to X/VT.
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <signal.h>
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include "eloop.h"
|
|
#include "log.h"
|
|
#include "vt.h"
|
|
|
|
static bool terminate;
|
|
|
|
static void sig_term(struct kmscon_signal *sig, int signum, void *data)
|
|
{
|
|
terminate = true;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int ret;
|
|
struct kmscon_eloop *loop;
|
|
struct kmscon_vt *vt;
|
|
struct kmscon_signal *sig;
|
|
|
|
ret = kmscon_eloop_new(&loop);
|
|
if (ret) {
|
|
log_err("Cannot create eloop\n");
|
|
goto err_out;
|
|
}
|
|
|
|
ret = kmscon_eloop_new_signal(loop, &sig, SIGINT, sig_term, NULL);
|
|
if (ret) {
|
|
log_err("Cannot add signal\n");
|
|
goto err_loop;
|
|
}
|
|
|
|
ret = kmscon_vt_new(&vt, NULL, NULL);
|
|
if (ret) {
|
|
log_err("Cannot create vt\n");
|
|
goto err_sig;
|
|
}
|
|
|
|
ret = kmscon_vt_open(vt, KMSCON_VT_NEW, loop);
|
|
if (ret) {
|
|
log_err("Cannot open VT\n");
|
|
goto err_vt;
|
|
}
|
|
|
|
ret = kmscon_vt_enter(vt);
|
|
if (ret)
|
|
log_warning("Cannot switch to VT\n");
|
|
|
|
while (!terminate) {
|
|
ret = kmscon_eloop_dispatch(loop, -1);
|
|
if (ret) {
|
|
log_err("Dispatcher failed\n");
|
|
break;
|
|
}
|
|
}
|
|
|
|
log_debug("Terminating\n");
|
|
|
|
/* switch back to previous VT but wait for eloop to process SIGUSR0 */
|
|
ret = kmscon_vt_leave(vt);
|
|
if (ret == -EINPROGRESS)
|
|
kmscon_eloop_dispatch(loop, 1000);
|
|
|
|
err_vt:
|
|
kmscon_vt_unref(vt);
|
|
err_sig:
|
|
kmscon_eloop_rm_signal(sig);
|
|
err_loop:
|
|
kmscon_eloop_unref(loop);
|
|
err_out:
|
|
return abs(ret);
|
|
}
|