Browse Source

Rework fdmux

It now supports m (master), cons, and consctl and is intended to be
bound MBEFORE to /dev. This way, child processes that try to mess with
cons/consctl won't break things.

Now for ^Z ...

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 8 years ago
parent
commit
218eab37d2
2 changed files with 15 additions and 8 deletions
  1. 11 4
      sys/src/9/port/devfdmux.c
  2. 4 4
      sys/src/regress/fdmux.c

+ 11 - 4
sys/src/9/port/devfdmux.c

@@ -51,12 +51,15 @@ enum
 	Qctl,
 };
 
+/* this is intended to be mounted in /dev with MBEFORE. That way programs that open
+ * /dev/cons* will get our version.
+ */
 Dirtab fdmuxdir[] =
 {
 	".",		{Qdir,0,QTDIR},	0,		DMDIR|0500,
-	"data",		{Qdata0},	0,		0600,
-	"data1",	{Qdata1},	0,		0600,
-	"ctl",		{Qctl},	0,		0600,
+	"m",		{Qdata0},	0,		0600,
+	"cons",	{Qdata1},	0,		0600,
+	"consctl",		{Qctl},	0,		0600,
 };
 #define NFDMUXDIR 4
 
@@ -426,7 +429,8 @@ fdmuxwrite(Chan *c, void *va, int32_t n, int64_t mm)
 					id = p->slpid;
 			break;
 			default:
-				error("usage: k (kill) or d (debug) or [lnps][optional number]");
+				print("usage: k (kill) or d (debug) or [lnps][optional number]");
+				break;
 		}
 		if (p->debug)
 			print("pid %d writes cmd :%s:\n", up->pid, buf);
@@ -466,6 +470,9 @@ fdmuxwrite(Chan *c, void *va, int32_t n, int64_t mm)
 				cclose(c);
 				p->pgrpid = up->pgrp->pgrpid;
 				break;
+			default:
+				print("ignoring unsupported command :%s:\n", buf);
+				break;
 		}
 		break;
 	case Qdata0:

+ 4 - 4
sys/src/regress/fdmux.c

@@ -29,14 +29,14 @@ main(void)
 		sysfatal(smprint("%r"));
 	atexit(unraw);
 
-	if (bind("#<", "/tmp", MAFTER) < 0)
+	if (bind("#<", "/dev", MBEFORE) < 0)
 		sysfatal(smprint("%r"));
 
-	if ((ctl = open("/tmp/ctl", ORDWR)) < 0)
+	if ((ctl = open("/dev/consctl", ORDWR)) < 0)
 		sysfatal(smprint("%r"));
-	if ((m = open("/tmp/data", ORDWR)) < 0)
+	if ((m = open("/dev/m", ORDWR)) < 0)
 		sysfatal(smprint("%r"));
-	if ((s = open("/tmp/data1", ORDWR)) < 0)
+	if ((s = open("/dev/cons", ORDWR)) < 0)
 		sysfatal(smprint("%r"));
 
 	pid = fork();