Refactor some xenopsd code and fix CA-101580

Would someone familiar with the xenopsd code like to check that this refactoring is vaguely sensible, please?

Note: I have manually checked that xcp-rrdd behaves in the same way for memory_internal_free data-sources, and is resilient to domains starting and stopping. I haven't checked the effect of xcp-rrdd having n xenstore watches when there are n running domains. I will try this, so I suggest not pulling this until that's verified to work okay.

I also haven't done any testing of the effect of these changes on xenopsd, but it compiles, and that's good enough for me :-)