weston-launch: Always use sd_session_get_vt

This commit is contained in:
Jasper St. Pierre 2014-03-11 17:10:39 -04:00
parent 81025e37ea
commit 7314cdac94
2 changed files with 7 additions and 42 deletions

View File

@ -142,11 +142,6 @@ AM_GLIB_GNU_GETTEXT
PKG_CHECK_MODULES(ALL, glib-2.0 >= 2.14.0) PKG_CHECK_MODULES(ALL, glib-2.0 >= 2.14.0)
PKG_CHECK_MODULES(MUTTER_LAUNCH, libdrm libsystemd-login) PKG_CHECK_MODULES(MUTTER_LAUNCH, libdrm libsystemd-login)
saved_LIBS="$LIBS"
LIBS="$LIBS $MUTTER_LAUNCH"
AC_CHECK_FUNCS([sd_session_get_vt])
LIBS="$saved_LIBS"
# Unconditionally use this dir to avoid a circular dep with gnomecc # Unconditionally use this dir to avoid a circular dep with gnomecc
GNOME_KEYBINDINGS_KEYSDIR="${datadir}/gnome-control-center/keybindings" GNOME_KEYBINDINGS_KEYSDIR="${datadir}/gnome-control-center/keybindings"
AC_SUBST(GNOME_KEYBINDINGS_KEYSDIR) AC_SUBST(GNOME_KEYBINDINGS_KEYSDIR)

View File

@ -552,7 +552,8 @@ setup_tty(struct weston_launch *wl)
struct stat buf; struct stat buf;
struct termios raw_attributes; struct termios raw_attributes;
struct vt_mode mode = { 0 }; struct vt_mode mode = { 0 };
char *session, *tty; char *session;
unsigned vt;
char path[PATH_MAX]; char path[PATH_MAX];
int ok; int ok;
@ -560,44 +561,13 @@ setup_tty(struct weston_launch *wl)
if (ok < 0) if (ok < 0)
error(1, -ok, "could not determine current session"); error(1, -ok, "could not determine current session");
ok = sd_session_get_tty(session, &tty); ok = sd_session_get_vt(session, &vt);
if (ok == 0) { if (ok < 0)
/* Old systemd only has the tty name in the TTY
field, new one has the full char device path.
Check what we have and fix it properly.
*/
if (strncmp(tty, "/dev", strlen("/dev")) == 0) {
strncpy(path, tty, PATH_MAX);
path[PATH_MAX-1] = 0;
} else {
snprintf(path, PATH_MAX, "/dev/%s", tty);
}
wl->tty = open(path, O_RDWR | O_NOCTTY | O_CLOEXEC);
free(tty);
#ifdef HAVE_SD_SESSION_GET_VT
} else if (ok == -ENOENT) {
unsigned vt;
/* Negative errnos are cool, right?
So cool that we can't distinguish "session not found"
from "key does not exist in the session file"!
Let's assume the latter, as we got the value
from sd_pid_get_session()...
*/
ok = sd_session_get_vt(session, &vt);
if (ok < 0)
error(1, -ok, "could not determine current TTY");
snprintf(path, PATH_MAX, "/dev/tty%u", vt);
wl->tty = open(path, O_RDWR | O_NOCTTY | O_CLOEXEC);
free(tty);
#endif
} else
error(1, -ok, "could not determine current TTY"); error(1, -ok, "could not determine current TTY");
snprintf(path, PATH_MAX, "/dev/tty%u", vt);
wl->tty = open(path, O_RDWR | O_NOCTTY | O_CLOEXEC);
if (wl->tty < 0) if (wl->tty < 0)
error(1, errno, "failed to open tty"); error(1, errno, "failed to open tty");