In nacl_io, this is just a node, not a new mount. You can access it by opening the file "/dev/tty".
The simplest way to use this is by using the "ppapi_simple" library. It does the following:
To do it yourself, you'll have to do what the ppapi_simple library does. Basically, to feed data into the node, you use a call to ioctl:
struct tioc_nacl_input_string ioctl_message;
ioctl_message.length = message_len;
ioctl_message.buffer = message_str.data();
int ret =
ioctl(fd_tty_, TIOCNACLINPUT, reinterpret_cast<char*>(&ioctl_message));
To have the node call pp::Instance::PostMessage when you write to it, you use a different call to ioctl:
In pepper_30, this is done automatically. All messages are prefixed so you can differentiate them, though. This can be set with an ioctl (src/ppapi_simple/ps_instance.cc:210):
const char* tty_prefix = getenv("PS_TTY_PREFIX");
if (tty_prefix) {
fd_tty_ = open("/dev/tty", O_WRONLY);
if (fd_tty_ >= 0) {
ioctl(fd_tty_, TIOCNACLPREFIX, const_cast<char*>(tty_prefix));
} else {
Error("Failed to open /dev/tty.\n");
}
}
In pepper_31 and later, you must explicitly set up a callback function for the tty node. You can do that with a third ioctl (src/ppapi_simple/ps_instance.cc:221):
tioc_nacl_output handler;
handler.handler = TtyOutputHandlerStatic;
handler.user_data = this;
ioctl(tty_fd_, TIOCNACLOUTPUT, reinterpret_cast<char*>(&handler));
Finally, if you want to remap stdin/stdout to /dev/tty, you'll have to do that manually as well. This is how ppapi_simple does it (src/ppapi_simple/ps_instance:201):
int fd0 = open(getenv("PS_STDIN"), O_RDONLY);
dup2(fd0, 0);
int fd1 = open(getenv("PS_STDOUT"), O_WRONLY);
dup2(fd1, 1);
Again, the simplest way to implement this is to use ppapi_simple, or to copy the behavior from that library.
-Ben