static inline Eina_Bool _ecore_drm_logind_vt_get(Ecore_Drm_Device *dev) { int ret; ret = sd_session_get_vt(dev->session, &dev->vt); if (ret < 0) { ERR("Could not get systemd tty: %m"); return EINA_FALSE; } return EINA_TRUE; }
static int weston_sd_session_get_vt(const char *sid, unsigned int *out) { #ifdef HAVE_SYSTEMD_LOGIN_209 return sd_session_get_vt(sid, out); #else int r; char *tty; r = sd_session_get_tty(sid, &tty); if (r < 0) return r; r = sscanf(tty, "tty%u", out); free(tty); if (r != 1) return -EINVAL; return 0; #endif }
static bool is_managed(const char *session) { unsigned int vtnr; struct stat st; long mode; int r; /* Using logind's Controller API is highly fragile if there is already * a session controller running. If it is registered as controller * itself, TakeControl will simply fail. But if its a legacy controller * that does not use logind's controller API, we must never register * our own controller. Otherwise, we really mess up the VT. Therefore, * only run in managed mode if there's no-one else. */ if (geteuid() == 0) return false; if (!isatty(1)) return false; if (!session) return false; r = sd_session_get_vt(session, &vtnr); if (r < 0 || vtnr < 1 || vtnr > 63) return false; mode = 0; r = ioctl(1, KDGETMODE, &mode); if (r < 0 || mode != KD_TEXT) return false; r = fstat(1, &st); if (r < 0 || minor(st.st_rdev) != vtnr) return false; return true; }