From 960cc8392da291eaf6c90d2101b721f6c20488f3 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 8 Aug 2013 14:36:50 -0500 Subject: Update tdehw-based media manager for new mount API Allow active VT to be queried from tdm Only display media notification messages on active VT Hide logout action buttons if logout process unstalls --- tdm/backend/CMakeLists.txt | 2 +- tdm/backend/ctrl.c | 18 +++++++++++ tdm/backend/getfd.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++ tdm/backend/getfd.h | 1 + 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tdm/backend/getfd.c create mode 100644 tdm/backend/getfd.h (limited to 'tdm/backend') diff --git a/tdm/backend/CMakeLists.txt b/tdm/backend/CMakeLists.txt index cd98b3a9c..625c8e85b 100644 --- a/tdm/backend/CMakeLists.txt +++ b/tdm/backend/CMakeLists.txt @@ -38,7 +38,7 @@ endif() tde_add_executable( tdm SOURCES access.c auth.c bootman.c choose.c client.c consolekit.c - ctrl.c daemon.c dm.c dpylist.c error.c genauth.c + ctrl.c daemon.c dm.c dpylist.c error.c genauth.c getfd.c inifile.c krb5auth.c mitauth.c netaddr.c policy.c process.c protodpy.c reset.c resource.c rpcauth.c server.c session.c sessreg.c socket.c streams.c diff --git a/tdm/backend/ctrl.c b/tdm/backend/ctrl.c index 622c9370d..4e10309e6 100644 --- a/tdm/backend/ctrl.c +++ b/tdm/backend/ctrl.c @@ -42,6 +42,9 @@ from the copyright holder. #include #include +#include +#include "getfd.h" + static void acceptSock( CtrlRec *cr ) { @@ -582,6 +585,21 @@ processCtrl( const char *string, int len, int fd, struct display *d ) ListSessions( flags, d, (void *)fd, emitXSessC, emitTTYSessC ); Reply( "\n" ); goto bust; + } else if (fd >= 0 && !strcmp( ar[0], "activevt" )) { +#ifdef HAVE_VTS + Reply( "ok" ); + int vt_fd = getfd(NULL); + if (vt_fd > 0) { + struct vt_stat vtstat; + if (!ioctl(vt_fd, VT_GETSTATE, &vtstat)) { + Writer( fd, cbuf, sprintf( cbuf, "\t%d", vtstat.v_active ) ); + } + } + Reply( "\n" ); +#else + Reply( "notsup\tvirtual terminal support not available\n" ); +#endif + goto bust; } else if (!strcmp( ar[0], "reserve" )) { int lt = 60; /* XXX make default timeout configurable? */ if (ar[1]) { diff --git a/tdm/backend/getfd.c b/tdm/backend/getfd.c new file mode 100644 index 000000000..3632161d3 --- /dev/null +++ b/tdm/backend/getfd.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include +#include "getfd.h" + +/* + * getfd.c + * + * Get an fd for use with kbd/console ioctls. + * We try several things because opening /dev/console will fail + * if someone else used X (which does a chown on /dev/console). + */ + +static int +is_a_console(int fd) { + char arg; + + arg = 0; + return (ioctl(fd, KDGKBTYPE, &arg) == 0 + && ((arg == KB_101) || (arg == KB_84))); +} + +static int +open_a_console(const char *fnam) { + int fd; + + /* + * For ioctl purposes we only need some fd and permissions + * do not matter. But setfont:activatemap() does a write. + */ + fd = open(fnam, O_RDWR); + if (fd < 0 && errno == EACCES) + fd = open(fnam, O_WRONLY); + if (fd < 0 && errno == EACCES) + fd = open(fnam, O_RDONLY); + if (fd < 0) + return -1; + if (!is_a_console(fd)) { + close(fd); + return -1; + } + return fd; +} + +int getfd() { + int fd; + + fd = open_a_console("/dev/tty"); + if (fd >= 0) + return fd; + + fd = open_a_console("/dev/tty0"); + if (fd >= 0) + return fd; + + fd = open_a_console("/dev/vc/0"); + if (fd >= 0) + return fd; + + fd = open_a_console("/dev/console"); + if (fd >= 0) + return fd; + + for (fd = 0; fd < 3; fd++) + if (is_a_console(fd)) + return fd; + + // "Couldnt get a file descriptor referring to the console + return -1; +} + diff --git a/tdm/backend/getfd.h b/tdm/backend/getfd.h new file mode 100644 index 000000000..b0b33a892 --- /dev/null +++ b/tdm/backend/getfd.h @@ -0,0 +1 @@ +extern int getfd(); -- cgit v1.2.1