}
case CEPH_TOOL_MODE_CLI_INPUT: {
- vector<string> cmd;
- for (unsigned int i = 0; i < nargs.size(); ++i) {
- cmd.push_back(string(nargs[i]));
- }
- if (cmd.empty()) {
+ if (nargs.empty()) {
if (ceph_tool_do_cli(ctx))
ret = 1;
}
else {
- if (ceph_tool_cli_input(ctx, cmd, out_file, indata))
- ret = 1;
+ while (!nargs.empty()) {
+ vector<string> cmd;
+ for (vector<const char*>::iterator n = nargs.begin();
+ n != nargs.end(); ) {
+ std::string np(*n);
+ n = nargs.erase(n);
+ if (np == ";")
+ break;
+ cmd.push_back(np);
+ }
+
+ if (ceph_tool_cli_input(ctx, cmd, out_file, indata))
+ ret = 1;
+ }
}
if (ceph_tool_messenger_shutdown())
ret = 1;
#include "msg/SimpleMessenger.h"
#include "tools/common.h"
+#include "common/errno.h"
#include "common/Cond.h"
#include "common/Mutex.h"
#include "common/Timer.h"
return 0;
}
- // write to file
- odata.write_file(outfile);
- derr << " wrote " << len << " byte payload to "
- << outfile << dendl;
+ // Write to a file. Don't truncate the file.
+ int fd = TEMP_FAILURE_RETRY(::open(outfile, O_WRONLY|O_CREAT, 0644));
+ if (fd < 0) {
+ int err = errno;
+ derr << " failed to create file '" << outfile << "': "
+ << cpp_strerror(err) << dendl;
+ return 1;
+ }
+ ret = odata.write_fd(fd);
+ if (ret) {
+ derr << " error writing file: " << cpp_strerror(ret) << dendl;
+ close(fd);
+ return 1;
+ }
+ derr << " wrote " << len << " byte payload to " << outfile << dendl;
+ if (close(fd)) {
+ int err = errno;
+ derr << " error while closing file '" << outfile << "': "
+ << cpp_strerror(err) << dendl;
+ return 1;
+ }
return 0;
}