aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--doc/protocols100
-rw-r--r--src/mds-kkbd.c3
-rw-r--r--src/mds-vt.c43
-rw-r--r--src/mds-vt.h16
5 files changed, 157 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index b9cb6ed..67fe54e 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,9 @@ LIBOBJ = linked-list client-list hash-table fd-table mds-message util
SERVERS = mds mds-respawn mds-server mds-echo mds-registry mds-clipboard \
mds-kkbd mds-vt
+# Servers that need setuid and root owner.
+SETUID_SERVERS = mds mds-vt
+
OBJ_mds-server_ = mds-server interception-condition client multicast \
@@ -40,8 +43,8 @@ include mk/build.mk
.PHONY: perms
perms: all
- sudo chown 'root:root' bin/mds
- sudo chmod 4755 bin/mds
+ sudo chown 'root:root' $(foreach S,$(SETUID_SERVERS),bin/$(S))
+ sudo chmod 4755 $(foreach S,$(SETUID_SERVERS),bin/$(S))
# Clean rules.
diff --git a/doc/protocols b/doc/protocols
index d40123b..54ace79 100644
--- a/doc/protocols
+++ b/doc/protocols
@@ -736,3 +736,103 @@ Compulsivity: optional
---------------------------------------------------------------------
+Command: get-vt
+ Get the index of the virtual terminal the server is display on
+ and the servers file descriptor for that tty
+
+Required header: Client ID
+ Your ID, provided by `ID assignment`
+ in response to `Command: assign-id`
+
+Response: The server will response with the header `VT index`
+ and the index of the virtual terminal the server is
+ display on in decimal format. Additionally the server
+ will respond with the header `Active` with the value
+ `yes` if the VT is in the foreground or the value
+ `no` if the VT is in the background.
+
+Purpose: Allow programs to be aware of whether the display
+ is in the foreground or the background
+Purpose: Allow programs to be aware of which VT the
+ server is running on
+Purpose: Allow programs to gain access of the TTY associated
+ with the VT such that they can use ioctl and similar
+ calls on that TTY
+
+Compulsivity: required
+
+Reference implementation: vt
+
+---------------------------------------------------------------------
+
+Command: configure-vt
+ Reconfigure the virtual terminal the server is display on
+
+Required header: Client ID
+ Your ID, provided by `ID assignment`
+ in response to `Command: assign-id`
+
+Optional header: graphical
+ yes) Set the TTY graphical mode
+ no) Set the TTY text mode
+ The server implementing this protocol should not set the
+ TTY to text mode temporarily when switching TTY. It is
+ up the the server that set the request for graphical mode
+ to temporarily switch to text mode when switching TTY.
+
+Optional header: exclusive
+ yes) The server may block other process from opening the TTY.
+ no) The server may not block other process from opening the TTY.
+
+Response: The server will response with a `Command: error`
+
+Purpose: Allow presentation servers to enter and leave graphical mode
+Purpose: Allow programs to gain access of the TTY associated
+ with the VT such that they can use ioctl and similar
+ calls on that TTY
+
+Compulsivity: required
+
+Reference implementation: vt
+
+---------------------------------------------------------------------
+
+Command: switching-vt
+ Notify servers about an ongoing virtual terminal switch
+
+Required header: Status
+ deactivating) The kernel wants to place the display in the background
+ activating) The kernel wants to place the display in the foreground
+
+Instructions: When a virtual terminal switch is requested the
+ server implementing control VT switching involving
+ the display's virtual terminal will get signaled by
+ the kernel. Upon this signal the server should
+ roadcast this command. All servers that need to
+ release or acquire resouces should intercept this
+ message with the possibility of modifying it.
+ Once a server is ready for the VT to switch it should
+ let the message pass to the next server by telling
+ the master server that it is no modification to do.
+ Once all servers are read for the switch the server
+ that emitted this message should signal the kernel
+ that it may switch VT. The server should detect
+ this by setting up secondary contection to the
+ display that intercepts this message. This connection
+ should intercept this message with priority −2³²,
+ all servers that need to perform actions before the
+ switch takes place must have a priority higher than
+ −2³², preferably 0.
+
+Purpose: Allow servers to release resources when the user switch
+ virtual terminal before the terminal actually changes and
+ to reacquire resources when the virtual terminal become
+ active again
+
+Compulsivity: required
+
+Reference implementation: vt
+Reference implementation: kkbd
+
+---------------------------------------------------------------------
+
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);