aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-08-22 16:54:56 +0200
committerMattias Andrée <maandree@operamail.com>2014-08-22 16:54:56 +0200
commit629a59ca698a0e3d3a0a29d5f2245c0e19808849 (patch)
tree2d78e69929dc0475eb101f2071003b33bd162389 /src
parentbeginning of mds-vt (diff)
downloadmds-629a59ca698a0e3d3a0a29d5f2245c0e19808849.tar.gz
mds-629a59ca698a0e3d3a0a29d5f2245c0e19808849.tar.bz2
mds-629a59ca698a0e3d3a0a29d5f2245c0e19808849.tar.xz
vt protocols
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-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);