#include <boost/exception/diagnostic_information.hpp>
#include <chrono>
#include <cstdlib>
namespace
{
auto connection(int fd) -> std::string
{
char connect_string[64] = {0};
sprintf(connect_string, "fd://%d", dup(fd));
return connect_string;
}
{
static const char* const launch_child_opt = "launch-client";
static const char* const launch_client_descr = "system() command to launch client";
{
if (options->is_set(launch_child_opt))
{
unsetenv("DISPLAY");
setenv("GDK_BACKEND", "mir", true);
setenv("QT_QPA_PLATFORM", "ubuntumirclient", true);
unsetenv("QT_QPA_PLATFORMTHEME");
setenv("SDL_VIDEODRIVER", "mir", true);
auto const value = options->get<std::string>(launch_child_opt);
for (
auto i =
begin(value); i !=
end(value); )
{
auto const j = find(i,
end(value),
'&');
std::string{i, j} + "&";
auto ignore = std::system(cmd.c_str());
(void)(ignore);
if ((i = j) !=
end(value)) ++i;
}
}
});
}
{
static const char* const timeout_opt = "timeout";
static const char* const timeout_descr = "Seconds to run before exiting";
{
if (options->is_set(timeout_opt))
{
static auto const exit_action = server.
the_main_loop()->create_alarm([&server] { server.
stop(); });
exit_action->reschedule_in(std::chrono::seconds(options->get<int>(timeout_opt)));
}
});
}
void exception_handler()
try
{
throw;
}
{
}
catch (std::exception
const&
error)
{
char const command_fmt[] = "/usr/share/apport/recoverable_problem --pid %d";
char command[sizeof(command_fmt)+32];
snprintf(command, sizeof(command), command_fmt, getpid());
char const options[] = "we";
char const key[] = "UnhandledException";
auto const value = boost::diagnostic_information(error);
if (auto const output = popen(command, options))
{
fwrite(key, sizeof(key), 1, output);
fwrite(value.c_str(), value.size(), 1, output);
pclose(output);
}
}
catch (...)
{
}
}
int main(
int argc,
char const* argv[])
try
{
add_launcher_option_to(server);
add_timeout_option_to(server);
{
return EXIT_FAILURE;
}
}
catch (...)
{
return EXIT_FAILURE;
}