C++: stop RPC service
from my C++ source, I am starting an RPC service calling svc_run()
. Everything looks just fine and I can see my service running if I type rpcinfo -p
in my terminal.
Now I am working on a "cleanup" function which should stop this service and remov开发者_Python百科e it from the rpcinfo -p
list.
How can I do that? At the moment I am only able to stop it using sudo rpcinfo -d program version
in my terminal. How can I do this from my source file?
Thanks.
After some time, I found out how to do this. Actually I faced some unexpected difficulties. The standard way to do this would be to use this:
svc_unregister(PROGID, VERSION)
but somehow, it did not work for me. After lots of trial and some online help (http://www.spinics.net/lists/linux-nfs/msg05619.html) I was able to delete the RPC service calling:
pmap_unset(PROGID, VERSION);
Hope this will help :)
Try to use void svc_exit(void)
function. For more detailed description please refer to rpc_svc_calls chapter.
I tried this force stop of svc_run(), however did not find a solution, I however made the svc_run() stop from within the registered function and then it stopped - perhaps this could help you - please look at this : svc_exit Subroutine
The 'nicest' solution is to use both DevCpp's and Danilo's solution combined:
- Among the RPC functions of your server, define one function which, when called by the client, executes svc_exit(). This will let your RPC server return from the svc_run() loop. Now you can either extend your RPC client application or create a separate client application to terminate your server.
- In your RPC server's main program, right after the call to svc_run(), execute 'pmap_unset(PROGID, VERSION);'. This will let rpcbind unregister your RPC address.
- Then do the usual cleanup of your application.
This combination allows your RPC server to run as a demon, i.e. without user interaction, while still offering a clean exit without having to cancel the process.
精彩评论