aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mds-kkbd.c3
-rw-r--r--src/mds-vt.c43
-rw-r--r--src/mds-vt.h16
3 files changed, 52 insertions, 10 deletions
diff --git a/src/mds-kkbd.c b/src/mds-kkbd.c
index b699ea0..842da90 100644
--- a/src/mds-kkbd.c
+++ b/src/mds-kkbd.c
@@ -16,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mds-kkbd.h"
+/* TODO: This server should wait for `Command: get-vt` to be available,
+ query the active VT and connect to that TTY instead of stdin. */
+/* TODO: Release control on `Command: switching-vt`. */
#include <libmdsserver/macros.h>
#include <libmdsserver/util.h>
diff --git a/src/mds-vt.c b/src/mds-vt.c
index 2167fb1..a6124c9 100644
--- a/src/mds-vt.c
+++ b/src/mds-vt.c
@@ -50,7 +50,7 @@ server_characteristics_t server_characteristics =
{
.require_privileges = 1, /* we want to open the new tty (the rest is fine without root for some reason) */
.require_display = 1,
- .require_respawn_info = 0,
+ .require_respawn_info = 1,
.sanity_check_argc = 1,
.fork_for_safety = 0,
.danger_is_deadly = 0
@@ -98,9 +98,10 @@ int initialise_server(void)
const char* const message =
"Command: intercept\n"
"Message ID: 0\n"
- "Length: 14\n"
+ "Length: 38\n"
"\n"
- "Command: echo\n";
+ "Command: get-vt\n";
+ "Command: configure-vt\n";
if (full_send(message, strlen(message)))
return 1;
@@ -337,16 +338,44 @@ int vt_set_active(int vt)
/**
* Open a virtual terminal
*
- * @param vt The index of the terminal
- * @return The file descriptor for the terminal, -1 on error
+ * @param vt The index of the terminal
+ * @param old_stat Output parameter for the old file stat for the terminal
+ * @return The file descriptor for the terminal, -1 on error
*/
-int vt_open(int vt)
+int vt_open(int vt, struct stat* restrict old_stat)
{
char vtpath[64]; /* Should be small enought and large enought for any
lunatic alternative to /dev/ttyNNN, if not you
will need to apply a patch (or fix your system.) */
+ int fd;
sprintf(vtpath, VT_PATH_PATTERN, vt);
- return open(vtpath, O_RDWR);
+ fd = open(vtpath, O_RDWR);
+ if (fd < 0)
+ return -1;
+ if ((fstat(fd, old_stat) < 0) ||
+ (fchown(fd, getuid(), getgid()) < 0))
+ {
+ close(fd);
+ return -1;
+ }
+ return fd;
+}
+
+
+/**
+ * Close a virtual terminal
+ *
+ * @param vt The index of the terminal
+ * @param old_stat The old file stat for the terminal
+ */
+void vt_close(int fd, struct stat* restrict old_stat)
+{
+ if (fchown(fd, old_stat->st_uid, old_stat->st_gid) < 0)
+ {
+ xperror(*argv);
+ eprint("while resetting TTY ownership.");
+ }
+ close(fd);
}
diff --git a/src/mds-vt.h b/src/mds-vt.h
index 1f87726..60204fc 100644
--- a/src/mds-vt.h
+++ b/src/mds-vt.h
@@ -62,10 +62,20 @@ int vt_set_active(int vt);
/**
* Open a virtual terminal
*
- * @param vt The index of the terminal
- * @return The file descriptor for the terminal, -1 on error
+ * @param vt The index of the terminal
+ * @param old_stat Output parameter for the old file stat for the terminal
+ * @return The file descriptor for the terminal, -1 on error
+ */
+int vt_open(int vt, struct stat* restrict old_stat);
+
+
+/**
+ * Close a virtual terminal
+ *
+ * @param vt The index of the terminal
+ * @param old_stat The old file stat for the terminal
*/
-int vt_open(int vt);
+void vt_close(int fd, struct stat* restrict old_stat);