jLuger.de - Owncloud in a container: device files

As I've mentioned in the previous post there was a problem in my container that prevented it from starting the webserver. After some debugging I've found that it was missing a random device and the null device file in the /dev directory.

My first solution was to try a mound bind of my real dev directory to the one of my Owncloud runtime. That didn't work as /dev folder is a special filesystem that you can't mound bind as a normal user (yes, the real root can do a mount bind on /dev but I didn't want to use the real root). Then I've tried the bindfs tool. It did the mount but the files weren't accessible.

It took me some time but I've figured out that all access to the /dev files were like a normal file access and that all communication was unidirectional. That meant I've could use named pipes backed up by a program.
I've created named the named pipes with the mkfifo command in the dev folder of my runtime.

For the random pipes it is important to open it in WRONLY mode (write only) or you create a deadlock. To put in data you need two for loops. The outer loop opens the "file" while the inner for loops writes data to it. After a client reads the random pipe it will close the connection not only for the client but also for your provider program. So the inner for loop will end and you need to reopen the "file". That's why you have the outer for loop for.

The implementation of the null pipe is pretty easy. Just open the pipe for read in a for loop and throw away all data you've read. You need the for loop for the same reasen as for the random device. You have to reopen the "file" after a client stops using the pipe.


This post is part of a series: