|
|
@ -20,6 +20,8 @@ |
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define _GNU_SOURCE |
|
|
|
|
|
|
|
|
|
|
|
#include <termios.h> |
|
|
|
#include <termios.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
@ -128,6 +130,7 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func, |
|
|
|
struct wl_event_loop *loop; |
|
|
|
struct wl_event_loop *loop; |
|
|
|
struct stat buf; |
|
|
|
struct stat buf; |
|
|
|
char filename[16]; |
|
|
|
char filename[16]; |
|
|
|
|
|
|
|
uid_t saved_uid, uid, euid; |
|
|
|
|
|
|
|
|
|
|
|
tty = malloc(sizeof *tty); |
|
|
|
tty = malloc(sizeof *tty); |
|
|
|
if (tty == NULL) |
|
|
|
if (tty == NULL) |
|
|
@ -136,6 +139,8 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func, |
|
|
|
memset(tty, 0, sizeof *tty); |
|
|
|
memset(tty, 0, sizeof *tty); |
|
|
|
tty->compositor = compositor; |
|
|
|
tty->compositor = compositor; |
|
|
|
tty->vt_func = vt_func; |
|
|
|
tty->vt_func = vt_func; |
|
|
|
|
|
|
|
getresuid(&uid, &euid, &saved_uid); |
|
|
|
|
|
|
|
seteuid(saved_uid); |
|
|
|
if (tty_nr > 0) { |
|
|
|
if (tty_nr > 0) { |
|
|
|
snprintf(filename, sizeof filename, "/dev/tty%d", tty_nr); |
|
|
|
snprintf(filename, sizeof filename, "/dev/tty%d", tty_nr); |
|
|
|
fprintf(stderr, "compositor: using %s\n", filename); |
|
|
|
fprintf(stderr, "compositor: using %s\n", filename); |
|
|
@ -152,11 +157,13 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func, |
|
|
|
|
|
|
|
|
|
|
|
if (tty->fd <= 0) { |
|
|
|
if (tty->fd <= 0) { |
|
|
|
fprintf(stderr, "failed to open tty: %m\n"); |
|
|
|
fprintf(stderr, "failed to open tty: %m\n"); |
|
|
|
|
|
|
|
seteuid(euid); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (tcgetattr(tty->fd, &tty->terminal_attributes) < 0) { |
|
|
|
if (tcgetattr(tty->fd, &tty->terminal_attributes) < 0) { |
|
|
|
fprintf(stderr, "could not get terminal attributes: %m\n"); |
|
|
|
fprintf(stderr, "could not get terminal attributes: %m\n"); |
|
|
|
|
|
|
|
seteuid(euid); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -178,6 +185,7 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func, |
|
|
|
ret = ioctl(tty->fd, KDSETMODE, KD_GRAPHICS); |
|
|
|
ret = ioctl(tty->fd, KDSETMODE, KD_GRAPHICS); |
|
|
|
if (ret) { |
|
|
|
if (ret) { |
|
|
|
fprintf(stderr, "failed to set KD_GRAPHICS mode on tty: %m\n"); |
|
|
|
fprintf(stderr, "failed to set KD_GRAPHICS mode on tty: %m\n"); |
|
|
|
|
|
|
|
seteuid(euid); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -187,9 +195,12 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func, |
|
|
|
mode.acqsig = SIGUSR1; |
|
|
|
mode.acqsig = SIGUSR1; |
|
|
|
if (ioctl(tty->fd, VT_SETMODE, &mode) < 0) { |
|
|
|
if (ioctl(tty->fd, VT_SETMODE, &mode) < 0) { |
|
|
|
fprintf(stderr, "failed to take control of vt handling\n"); |
|
|
|
fprintf(stderr, "failed to take control of vt handling\n"); |
|
|
|
|
|
|
|
seteuid(euid); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
seteuid(euid); |
|
|
|
|
|
|
|
|
|
|
|
tty->vt_source = |
|
|
|
tty->vt_source = |
|
|
|
wl_event_loop_add_signal(loop, SIGUSR1, vt_handler, tty); |
|
|
|
wl_event_loop_add_signal(loop, SIGUSR1, vt_handler, tty); |
|
|
|
|
|
|
|
|
|
|
|