*
* Data Differential YATL (i.e. libtest) library
*
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
#include <unistd.h>
#include <algorithm>
+#include <stdexcept>
#ifndef __USE_GNU
static char **environ= NULL;
iter != built_argv.end();
++iter)
{
- arg_buffer << *iter << " ";
+ if (*iter)
+ {
+ arg_buffer << *iter << " ";
+ }
}
return arg_buffer.str();
{
if (libtool() == NULL)
{
- FATAL("libtool requested, but know libtool was found");
+ FATAL("libtool requested, but no libtool was found");
}
}
}
else
{
- spawn_ret= posix_spawn(&_pid, built_argv[0], &file_actions, &spawnattr, &built_argv[0], NULL);
+ spawn_ret= posix_spawn(&_pid, built_argv[0], &file_actions, &spawnattr, &built_argv[0], environ);
}
posix_spawn_file_actions_destroy(&file_actions);
{
if (_will_fail == false)
{
- Error << strerror(spawn_ret) << "(" << spawn_ret << ")";
+ std::string sb;
+ char buf[1024];
+
+ std::for_each(built_argv.begin(), built_argv.end()-1, [&sb](const char *a) {
+ if (sb.size()) {
+ sb.append(" ");
+ }
+ sb.append(a);
+ });
+ Error << strerror(spawn_ret) << "(" << spawn_ret << "): " << sb << " cwd:" << getcwd(buf, sizeof(buf)-1);
}
_pid= -1;
return Application::INVALID_POSIX_SPAWN;
int error;
switch ((error= errno))
{
-#ifdef TARGET_OS_LINUX
+#ifdef __linux
case ERESTART:
#endif
case EINTR:
return data_was_read;
}
+std::pair<std::string, std::string> Application::output()
+{
+ slurp();
+ return {
+ std::string {
+ stdout_result().data(),
+ stdout_result().size()
+ },
+ std::string {
+ stderr_result().data(),
+ stderr_result().size()
+ }
+ };
+
+}
+
Application::error_t Application::join()
{
- pid_t waited_pid= waitpid(_pid, &_status, 0);
+ pid_t waited_pid= waitpid(_pid, &_status, WUNTRACED);
slurp();
if (waited_pid == _pid and WIFEXITED(_status) == false)
{
}
else if (waited_pid == -1)
{
+ std::string error_string;
+ if (stdout_result_length())
+ {
+ error_string+= " stdout: ";
+ error_string+= stdout_c_str();
+ }
+
+ if (stderr_result_length())
+ {
+ error_string+= " stderr: ";
+ error_string+= stderr_c_str();
+ }
+ Error << "waitpid() returned errno:" << strerror(errno) << " " << error_string;
_app_exit_state= Application::UNKNOWN;
- Error << "waitpid() returned errno:" << strerror(errno);
}
else
{
vchar::append(built_argv, *ptr);
}
}
- built_argv.push_back(NULL);
+ built_argv.push_back(nullptr);
}
std::string Application::print()
Application::error_t ret= app.run(args);
+ if (Application::SUCCESS == ret) {
+ ret = app.join();
+ }
+
if (ret != Application::SUCCESS)
{
- return int(ret);
+ auto out = app.output();
+ Error << command << " stdout: " << out.first;
+ Error << command << " stderr: " << out.second;
}
- return int(app.join());
-}
-
-const char *gearmand_binary()
-{
- return GEARMAND_BINARY;
-}
-
-const char *drizzled_binary()
-{
- return DRIZZLED_BINARY;
+ return int(ret);
}
} // namespace exec_cmdline