コード例 #1
0
ファイル: vt.c プロジェクト: myra/kmscon
static int connect_eloop(struct kmscon_vt *vt, struct ev_eloop *eloop)
{
	int ret;

	if (!vt || !eloop || vt->fd < 0)
		return -EINVAL;

	ret = ev_eloop_register_signal_cb(eloop, SIGUSR1, vt_leave, vt);
	if (ret)
		return ret;

	ret = ev_eloop_register_signal_cb(eloop, SIGUSR2, vt_enter, vt);
	if (ret)
		goto err_sig1;

	ret = ev_eloop_new_fd(eloop, &vt->efd, vt->fd, EV_READABLE,
				vt_input, vt);
	if (ret)
		goto err_sig2;

	vt->eloop = eloop;
	ev_eloop_ref(vt->eloop);
	return 0;

err_sig2:
	ev_eloop_unregister_signal_cb(vt->eloop, SIGUSR2, vt_enter, vt);
err_sig1:
	ev_eloop_unregister_signal_cb(vt->eloop, SIGUSR1, vt_leave, vt);
	return ret;
}
コード例 #2
0
ファイル: main.c プロジェクト: mdlh/kmscon
static int setup_app(struct kmscon_app *app)
{
	int ret;

	ret = ev_eloop_new(&app->eloop);
	if (ret)
		goto err_app;

	ret = ev_eloop_register_signal_cb(app->eloop, SIGTERM,
						sig_generic, app);
	if (ret)
		goto err_app;

	ret = ev_eloop_register_signal_cb(app->eloop, SIGINT,
						sig_generic, app);
	if (ret)
		goto err_app;

	ret = ev_eloop_new_eloop(app->eloop, &app->vt_eloop);
	if (ret)
		goto err_app;

	ret = kmscon_vt_new(&app->vt, vt_switch, app);
	if (ret)
		goto err_app;

	ret = uterm_video_new(&app->video,
				app->eloop,
				UTERM_VIDEO_DRM,
				"/dev/dri/card0");
	if (ret)
		goto err_app;

	ret = uterm_video_use(app->video);
	if (ret)
		goto err_app;

	ret = kmscon_input_new(&app->input);
	if (ret)
		goto err_app;

	ret = kmscon_input_connect_eloop(app->input, app->eloop);
	if (ret)
		goto err_app;

	ret = kmscon_vt_open(app->vt, KMSCON_VT_NEW, app->vt_eloop);
	if (ret)
		goto err_app;

	ret = kmscon_ui_new(&app->ui, app->eloop, app->video, app->input);
	if (ret)
		goto err_app;

	return 0;

err_app:
	destroy_app(app);
	return ret;
}
コード例 #3
0
ファイル: pty.c プロジェクト: myra/kmscon
int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width,
							unsigned short height)
{
	int ret;
	int master;

	if (!pty)
		return -EINVAL;

	if (pty_is_open(pty))
		return -EALREADY;

	master = posix_openpt(O_RDWR | O_NOCTTY | O_CLOEXEC | O_NONBLOCK);
	if (master < 0) {
		log_err("cannot open master: %m");
		return -errno;
	}

	ret = ev_eloop_new_fd(pty->eloop, &pty->efd, master,
					EV_READABLE, pty_input, pty);
	if (ret)
		goto err_master;

	ret = ev_eloop_register_signal_cb(pty->eloop, SIGCHLD, sig_child, pty);
	if (ret)
		goto err_fd;

	ret = pty_spawn(pty, master, width, height);
	if (ret)
		goto err_sig;

	return 0;

err_sig:
	ev_eloop_unregister_signal_cb(pty->eloop, SIGCHLD, sig_child, pty);
err_fd:
	ev_eloop_rm_fd(pty->efd);
	pty->efd = NULL;
err_master:
	close(master);
	return ret;
}
コード例 #4
0
ファイル: test_input.c プロジェクト: mmonaco/kmscon
int main(int argc, char **argv)
{
	int ret;
	struct uterm_monitor *mon;
	size_t onum;

	onum = sizeof(options) / sizeof(*options);
	ret = test_prepare(options, onum, argc, argv, &eloop);
	if (ret)
		goto err_fail;

	if (!setlocale(LC_ALL, "")) {
		log_err("Cannot set locale: %m");
		ret = -EFAULT;
		goto err_exit;
	}

	ret = uterm_monitor_new(&mon, eloop, monitor_event, NULL);
	if (ret)
		goto err_exit;

	ret = ev_eloop_register_signal_cb(eloop, SIGQUIT, sig_quit, NULL);
	if (ret)
		goto err_mon;

	system("stty -echo");
	uterm_monitor_scan(mon);
	ev_eloop_run(eloop, -1);
	system("stty echo");

	ev_eloop_unregister_signal_cb(eloop, SIGQUIT, sig_quit, NULL);
err_mon:
	uterm_monitor_unref(mon);
err_exit:
	test_exit(options, onum, eloop);
err_fail:
	if (ret != -ECANCELED)
		test_fail(ret);
	return abs(ret);
}
コード例 #5
0
ファイル: uvtd_main.c プロジェクト: nachokb/kmscon
static int setup_app(struct uvtd_app *app)
{
	int ret, fd;

	shl_dlist_init(&app->seats);

	ret = ev_eloop_new(&app->eloop, log_llog, NULL);
	if (ret) {
		log_error("cannot create eloop object: %d", ret);
		goto err_app;
	}

	ret = ev_eloop_register_signal_cb(app->eloop, SIGTERM,
					  app_sig_generic, app);
	if (ret) {
		log_error("cannot register SIGTERM signal handler: %d", ret);
		goto err_app;
	}

	ret = ev_eloop_register_signal_cb(app->eloop, SIGINT,
					  app_sig_generic, app);
	if (ret) {
		log_error("cannot register SIGINT signal handler: %d", ret);
		goto err_app;
	}

	ret = ev_eloop_register_signal_cb(app->eloop, SIGPIPE,
					  app_sig_ignore, app);
	if (ret) {
		log_error("cannot register SIGPIPE signal handler: %d", ret);
		goto err_app;
	}

	ret = uterm_monitor_new(&app->mon, app->eloop, app_monitor_event, app);
	if (ret) {
		log_error("cannot create device monitor: %d", ret);
		goto err_app;
	}

	ret = uvt_ctx_new(&app->ctx, log_llog, NULL);
	if (ret) {
		log_error("cannot create UVT context: %d", ret);
		goto err_app;
	}

	fd = uvt_ctx_get_fd(app->ctx);
	if (fd >= 0) {
		ret = ev_eloop_new_fd(app->eloop, &app->ctx_fd, fd,
				      EV_READABLE, app_ctx_event, app);
		if (ret) {
			log_error("cannot create UVT ctx efd: %d", ret);
			goto err_app;
		}
	}

	log_debug("scanning for devices...");
	uterm_monitor_scan(app->mon);

	return 0;

err_app:
	destroy_app(app);
	return ret;
}
コード例 #6
0
ファイル: uterm_vt.c プロジェクト: ysangkok/kmscon
int uterm_vt_allocate(struct uterm_vt_master *vtm,
		      struct uterm_vt **out,
		      const char *seat,
		      struct uterm_input *input,
		      uterm_vt_cb cb,
		      void *data)
{
	struct uterm_vt *vt;
	int ret;

	if (!vtm || !out)
		return -EINVAL;
	if (!seat)
		seat = "seat0";

	vt = malloc(sizeof(*vt));
	if (!vt)
		return -ENOMEM;
	memset(vt, 0, sizeof(*vt));
	vt->ref = 1;
	vt->vtm = vtm;
	vt->cb = cb;
	vt->data = data;

	vt->real_fd = -1;
	vt->real_num = -1;
	vt->real_saved_num = -1;

	ret = ev_eloop_register_signal_cb(vtm->eloop, SIGUSR1, vt_sigusr1, vt);
	if (ret)
		goto err_free;

	ret = ev_eloop_register_signal_cb(vtm->eloop, SIGUSR2, vt_sigusr2, vt);
	if (ret)
		goto err_sig1;

	if (!strcmp(seat, "seat0") && vtm->vt_support) {
		vt->mode = UTERM_VT_REAL;
		ret = real_open(vt);
		if (ret)
			goto err_sig2;
	} else {
		vt->mode = UTERM_VT_FAKE;
		vt->input = input;

		ret = uterm_input_register_cb(vt->input, vt_input, vt);
		if (ret)
			goto err_sig2;

		ret = ev_eloop_register_idle_cb(vtm->eloop, vt_idle_event, vt);
		if (ret)
			goto err_input;

		uterm_input_ref(vt->input);
		uterm_input_wake_up(vt->input);
	}

	kmscon_dlist_link(&vtm->vts, &vt->list);
	*out = vt;
	return 0;

err_input:
	uterm_input_unregister_cb(vt->input, vt_input, vt);
err_sig2:
	ev_eloop_unregister_signal_cb(vtm->eloop, SIGUSR2, vt_sigusr2, vt);
err_sig1:
	ev_eloop_unregister_signal_cb(vtm->eloop, SIGUSR1, vt_sigusr1, vt);
err_free:
	free(vt);
	return ret;
}