When a client disconnects from the nbd device (triggered via nbd-client
-d <nbd device>) the ioctl(nbd, NBD_DO_IT) returns with an error.
nbd-client checks errno to figure out whether it was disconnected and
whether it should terminate or not. Unfortunatly it invokes fprintf()
before checking errno and fprintf overwrites the current value of errno.
The attached patch saves the current value of errno and checks the saved
value.
#endif
if (ioctl(nbd, NBD_DO_IT) < 0) {
- fprintf(stderr, "Kernel call returned: %m");
- if(errno==EBADR) {
+ int error = errno;
+ fprintf(stderr, "nbd,%d: Kernel call returned: %d", getpid(), error);
+ if(error==EBADR) {
/* The user probably did 'nbd-client -d' on us.
* quit */
cont=0;