
This is a common DTrace technique described in the User Process Tracing chapter of the DTrace documentation (no link, sun.com no longer exists).Īnother common thing to keep in mind: At the moment of function entry, the file name may reside on a memory page that is not yet accessible, so we can’t necessarily read it yet. Therefore, we need to use the DTrace copyin function to copy the file name across memory spaces. But the file name resides in user space while DTrace operates in kernel space. To match the media directory with the path given to open(2), we need to look at arg0, which is a pointer to the given file name. While putting together this DTrace script, the following things came up which are probably useful to know for a variety of similar D scripts:ĭTrace already knows about the standard libc and kernel functions, so, when watching out for writes, we can just specify the O_RDWRITE and O_WRONLY flags to open(2) verbatim without knowing their actual values. Then, when new files come in or are changed we’ll send SIGHUP signals to our media server processes so they can re-scan their content directories. In the following script, we’ll ask DTrace to watch for open(2) (no link, sun.com no longer exists) events and filter out those that match the directories where we store our media.

There’s another way, more simple than coding file notification events and easy to use for any kind of media server software: DTrace.
#Firefly itunes media server code#
But this code has not been adopted by neither Firefly nor Mediatomb (yet?).
#Firefly itunes media server how to#
Darren Moffat has written a nice tutorial on how to use file notification events in your code (no link, sun.com no longer exists). The OpenSolaris way to detect changes in the file system is through file notification events. But inotify is a Linux-only API and it is therefore not portable. The typical way to solve this in the Linux world is to use inotify, and it seems to work quite well. Whenever I upload new music or videos to my OpenSolaris home server (typically by rsync-ing my laptop home directory), both Firefly and Mediatomb need to be restarted so they detect that new files are sitting in their directories, waiting to be served. In my case, I’m using the Firefly Media Server (no link, no longer exists) to serve music to my Roku Soundbridge and Mediatomb (no link, page no longer exists) for videos.

One of the most typical uses for a home server is to serve music or videos to home entertainment equipment. Before we continue with our Home Server Scripting Series, let’s throw in a simple but useful DTrace hack.
