uterm: vt: move kmscon_vt_supported() to uterm-vt

Instead of having a global symbol, we simply move the check to uterm-vt
and can remove it from global namespace. Furthermore, we cache the result
so we can reuse it on the VT-master if required.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-08-12 09:04:54 +02:00
parent 31188d4c79
commit 891400ad91
3 changed files with 12 additions and 11 deletions

View File

@ -31,6 +31,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "eloop.h"
#include "log.h"
#include "static_misc.h"
@ -56,9 +57,18 @@ struct uterm_vt_master {
unsigned long ref;
struct ev_eloop *eloop;
bool vt_support;
struct kmscon_dlist vts;
};
static bool check_vt_support(void)
{
if (!access("/dev/tty", F_OK))
return true;
else
return false;
}
static int vt_call(struct uterm_vt *vt, unsigned int event)
{
int ret;
@ -141,7 +151,7 @@ int uterm_vt_allocate(struct uterm_vt_master *vtm,
vt->cb = cb;
vt->data = data;
if (!strcmp(seat, "seat0") && kmscon_vt_supported()) {
if (!strcmp(seat, "seat0") && vtm->vt_support) {
ret = kmscon_vt_new(&vt->vt, vt_event, vt);
if (ret)
goto err_free;
@ -238,6 +248,7 @@ int uterm_vt_master_new(struct uterm_vt_master **out,
vtm->ref = 1;
vtm->eloop = eloop;
kmscon_dlist_init(&vtm->vts);
vtm->vt_support = check_vt_support();
ev_eloop_ref(vtm->eloop);
*out = vtm;

View File

@ -89,14 +89,6 @@ struct kmscon_vt {
struct ev_fd *efd;
};
bool kmscon_vt_supported(void)
{
if (access("/dev/tty", F_OK))
return false;
else
return true;
}
int kmscon_vt_new(struct kmscon_vt **out, kmscon_vt_cb cb, void *data)
{
struct kmscon_vt *vt;

View File

@ -56,8 +56,6 @@ typedef bool (*kmscon_vt_cb) (struct kmscon_vt *vt,
enum kmscon_vt_action action,
void *data);
bool kmscon_vt_supported(void);
int kmscon_vt_new(struct kmscon_vt **out, kmscon_vt_cb cb, void *data);
void kmscon_vt_ref(struct kmscon_vt *vt);
void kmscon_vt_unref(struct kmscon_vt *vt);