The code that ultimately worked is here. For what it’s worth, I abandoned this idea due to this nightmare of dropping privileges which caused other issues down the track interfacing with hardware etc.
It may work for you, but I ended up rewriting the project in Qt.