acozzette / BUSE

A block device in user space for Linux
GNU General Public License v2.0
240 stars 47 forks source link

Gracefully terminate server process when requested #9

Open rutsky opened 8 years ago

rutsky commented 8 years ago

I think the only correct way of terminating BUSE-based NBD server is to disconnect the NBD device:

nbd-client -d /dev/nbd0

It would be nice to properly handle Ctrl+C to achieve same result (currently Ctrl+C leads to exit code 130, i.e. terminated with SIGINT),

bandi13 commented 8 years ago

In my C++ version, I've put in some wrappers to handle this problem. It should exit gracefully when a SIGINT happens (either via Ctrl+C or kill). Take a look at those.

rutsky commented 8 years ago

Thanks for the info @bandi13!

So generally it can be implemented as

nbd = open(dev_file, O_RDWR);
...
ioctl(nbd, NBD_DISCONNECT);

in SIGINT signal handler: https://github.com/bandi13/BUSE-CPP/blob/master/buse.cpp#L208

@bandi13, I checked your implementation and think that issue #4 is related to your version too. Just don't do stuff that always should be done inside assert() macro.

SupraSummus commented 5 years ago

@acozzette can you please close this issue? In my opinion it has been resolved. Thanks ;)