summaryrefslogtreecommitdiff
path: root/sys/src/cmd/vt/consctl.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/vt/consctl.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/vt/consctl.c')
-rwxr-xr-xsys/src/cmd/vt/consctl.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/sys/src/cmd/vt/consctl.c b/sys/src/cmd/vt/consctl.c
new file mode 100755
index 000000000..525bbb664
--- /dev/null
+++ b/sys/src/cmd/vt/consctl.c
@@ -0,0 +1,71 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include "cons.h"
+
+/*
+ * bind a pipe onto consctl and keep reading it to
+ * get changes to console state.
+ */
+Consstate*
+consctl(void)
+{
+ int i, n, fd, tries;
+ char buf[128];
+ Consstate *x;
+ char *field[10];
+
+ x = segattach(0, "shared", 0, sizeof *x);
+ if(x == (void*)-1)
+ sysfatal("segattach: %r");
+
+ /* a pipe to simulate consctl */
+ if(bind("#|", "/mnt/cons/consctl", MBEFORE) < 0
+ || bind("/mnt/cons/consctl/data1", "/dev/consctl", MREPL) < 0)
+ sysfatal("bind consctl: %r");
+
+ /* a pipe to simulate the /dev/cons */
+ if(bind("#|", "/mnt/cons/cons", MREPL) < 0
+ || bind("/mnt/cons/cons/data1", "/dev/cons", MREPL) < 0)
+ sysfatal("bind cons: %r");
+
+ switch(fork()){
+ case -1:
+ sysfatal("fork: %r");
+ case 0:
+ break;
+ default:
+ return x;
+ }
+
+ notify(0);
+
+ for(tries = 0; tries < 100; tries++){
+ x->raw = 0;
+ x->hold = 0;
+ fd = open("/mnt/cons/consctl/data", OREAD);
+ if(fd < 0)
+ break;
+ tries = 0;
+ for(;;){
+ n = read(fd, buf, sizeof(buf)-1);
+ if(n <= 0)
+ break;
+ buf[n] = 0;
+ n = getfields(buf, field, 10, 1, " ");
+ for(i = 0; i < n; i++){
+ if(strcmp(field[i], "rawon") == 0)
+ x->raw = 1;
+ else if(strcmp(field[i], "rawoff") == 0)
+ x->raw = 0;
+ else if(strcmp(field[i], "holdon") == 0)
+ x->hold = 1;
+ else if(strcmp(field[i], "holdoff") == 0)
+ x->hold = 0;
+ }
+ }
+ close(fd);
+ }
+ exits(0);
+ return 0; /* dummy to keep compiler quiet*/
+}