Fakescreen (screen manager without the need for terminal devices, works with nodev)

fakescreenAs part of the effort to make my server more secure I’m moving most of my activities to separate chroot() jails. It’s going to become part of several bigger changes this year. I encountered a little issue though with software which I usually run using the screen command. As you might have noticed yourself or as any Google search will show, screen requires access to pseudo-tty devices in order to manage screen content. This is not very convenient because chroot() jails usually reside on filesystems mounted with the nodev flag, which ensures that both lusers and root alike can’t create special device files on the filesystem that would allow direct access to hardware or kernel internals. To cut the long story short – this renders both screen and tmux completely unusable. Since creating a detachable virtual terminal isn’t exactly rocket science I decided to dedicate a bit of time and quickly write one that wouldn’t depend on any special devices. Obviously it doesn’t support the same spectrum of functionality as screen, hence the name – fakescreen. It allows to launch any single process in a detached state using fakescreen command and then attach to it from the same or another terminal using fakerestore command. Internally it uses some clever forking behavior, input/output redirection via pipes, termios configuration and UNIX domain sockets to allow this. Only one process can be attached to the fakescreen at any time, and to detach you need to use Ctrl+C (therefore, Ctrl+C is not sent to the screen-ed process). To send Ctrl+C to the process inside fakescreen, you can use kill.

Compilation:

gcc fakescreen.c -o fakescreen
gcc fakerestore.c -o fakerestore

Usage:

./fakescreen /tmp/my_unix_socket rtorrent
./fakerestore /tmp/my_unix_socket

DOWNLOAD: fakescreen.zip

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *