output.read_fd() could return zero length. it needs to
be handled gracefully.
always call invoke join() if spawn() is successfully returned.
otherwise there will be assert failure in ~SubProcess().
Fixes: http://tracker.ceph.com/issues/23899
Signed-off-by: Gu Zhongyan <guzhongyan@360.cn>
lderr(cct) << "stderr:\n";
err.hexdump(*_dout);
*_dout << dendl;
- return ret;
}
if (hook.join() != 0) {
return -EINVAL;
}
+ if (ret < 0)
+ return ret;
+
std::string out;
bl.copy(0, bl.length(), out);
out.erase(out.find_last_not_of(" \n\r\t")+1);
ret = output.read_fd(smartctl.get_stdout(), 100*1024);
if (ret < 0) {
derr << "failed read from smartctl: " << cpp_strerror(-ret) << dendl;
- return ret;
+ } else {
+ *result = output.to_str();
+ dout(10) << "smartctl output is: " << *result << dendl;
}
- derr << "smartctl output is: " << output.c_str() << dendl;
- *result = output.c_str();
-
if (smartctl.join() != 0) {
derr << smartctl.err() << dendl;
return -EINVAL;
}
+ if (ret < 0)
+ return ret;
+
return 0;
}