summaryrefslogtreecommitdiff
path: root/src/tty.c
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-01-30 14:04:04 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-04-06 14:01:19 +0200
commitbfeda130de340c090895d23ea0a5742521ff0078 (patch)
tree4b989a3e5e1472b644f690be28cc519666810d62 /src/tty.c
parent1a36156972f14bb8d481abd71cb4210eb226a7ba (diff)
downloadweston-bfeda130de340c090895d23ea0a5742521ff0078.tar.gz
weston-bfeda130de340c090895d23ea0a5742521ff0078.tar.bz2
weston-bfeda130de340c090895d23ea0a5742521ff0078.zip
Introduce weston-launch
weston-launch starts weston and provides mechanism for weston to set/drop drm master, open a tty, and read input devices without being root. Execution is allowed for local-active sessions or users in the group weston-launch.
Diffstat (limited to 'src/tty.c')
-rw-r--r--src/tty.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/tty.c b/src/tty.c
index 85c16d8a..651c5cd2 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -81,7 +81,6 @@ try_open_vt(struct tty *tty)
{
int tty0, fd;
char filename[16];
- struct vt_stat vts;
tty0 = open("/dev/tty0", O_WRONLY | O_CLOEXEC);
if (tty0 < 0) {
@@ -102,18 +101,6 @@ try_open_vt(struct tty *tty)
if (fd < 0)
return fd;
- if (ioctl(fd, VT_GETSTATE, &vts) == 0)
- tty->starting_vt = vts.v_active;
- else
- tty->starting_vt = tty->vt;
-
- if (ioctl(fd, VT_ACTIVATE, tty->vt) < 0 ||
- ioctl(fd, VT_WAITACTIVE, tty->vt) < 0) {
- fprintf(stderr, "failed to swtich to new vt\n");
- close(fd);
- return -1;
- }
-
return fd;
}
@@ -128,6 +115,7 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
struct wl_event_loop *loop;
struct stat buf;
char filename[16];
+ struct vt_stat vts;
tty = malloc(sizeof *tty);
if (tty == NULL)
@@ -136,14 +124,22 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
memset(tty, 0, sizeof *tty);
tty->compositor = compositor;
tty->vt_func = vt_func;
+
+ tty->fd = weston_environment_get_fd("WESTON_TTY_FD");
+ if (tty->fd < 0)
+ tty->fd = STDIN_FILENO;
+
if (tty_nr > 0) {
snprintf(filename, sizeof filename, "/dev/tty%d", tty_nr);
fprintf(stderr, "compositor: using %s\n", filename);
tty->fd = open(filename, O_RDWR | O_NOCTTY | O_CLOEXEC);
+ tty->vt = tty_nr;
} else if (fstat(tty->fd, &buf) == 0 &&
major(buf.st_rdev) == TTY_MAJOR &&
minor(buf.st_rdev) > 0) {
- tty->fd = fcntl(0, F_DUPFD_CLOEXEC, 0);
+ if (tty->fd == STDIN_FILENO)
+ tty->fd = fcntl(STDIN_FILENO, F_DUPFD_CLOEXEC, 0);
+ tty->vt = minor(buf.st_rdev);
} else {
/* Fall back to try opening a new VT. This typically
* requires root. */
@@ -156,6 +152,19 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
return NULL;
}
+ if (ioctl(tty->fd, VT_GETSTATE, &vts) == 0)
+ tty->starting_vt = vts.v_active;
+ else
+ tty->starting_vt = tty->vt;
+
+ if (tty->starting_vt != tty->vt) {
+ if (ioctl(tty->fd, VT_ACTIVATE, tty->vt) < 0 ||
+ ioctl(tty->fd, VT_WAITACTIVE, tty->vt) < 0) {
+ fprintf(stderr, "failed to swtich to new vt\n");
+ return NULL;
+ }
+ }
+
if (tcgetattr(tty->fd, &tty->terminal_attributes) < 0) {
fprintf(stderr, "could not get terminal attributes: %m\n");
goto err;