2014-08-07 17:48:30 +03:00
|
|
|
#include "launcher.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <cerrno>
|
|
|
|
#include <cstring>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2014-08-08 03:04:05 +03:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
// Bind and activate the framebuffer console on selected platforms.
|
|
|
|
#define BIND_CONSOLE \
|
|
|
|
defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
|
|
|
|
|
|
|
|
#if BIND_CONSOLE
|
|
|
|
#include <linux/vt.h>
|
|
|
|
#endif
|
|
|
|
|
2014-08-07 17:48:30 +03:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2014-08-08 03:04:05 +03:00
|
|
|
Launcher::Launcher(vector<string> const& commandLine, bool consoleApp)
|
2014-08-07 17:48:30 +03:00
|
|
|
: commandLine(commandLine)
|
2014-08-08 03:04:05 +03:00
|
|
|
, consoleApp(consoleApp)
|
2014-08-07 17:48:30 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-08 03:04:05 +03:00
|
|
|
Launcher::Launcher(vector<string> && commandLine, bool consoleApp)
|
2014-08-07 17:48:30 +03:00
|
|
|
: commandLine(commandLine)
|
2014-08-08 03:04:05 +03:00
|
|
|
, consoleApp(consoleApp)
|
2014-08-07 17:48:30 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Launcher::exec()
|
|
|
|
{
|
2014-08-08 03:04:05 +03:00
|
|
|
if (consoleApp) {
|
|
|
|
#if BIND_CONSOLE
|
|
|
|
/* Enable the framebuffer console */
|
|
|
|
char c = '1';
|
|
|
|
int fd = open("/sys/devices/virtual/vtconsole/vtcon1/bind", O_WRONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
WARNING("Unable to open fbcon handle\n");
|
|
|
|
} else {
|
|
|
|
write(fd, &c, 1);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open("/dev/tty1", O_RDWR);
|
|
|
|
if (fd < 0) {
|
|
|
|
WARNING("Unable to open tty1 handle\n");
|
|
|
|
} else {
|
|
|
|
if (ioctl(fd, VT_ACTIVATE, 1) < 0)
|
|
|
|
WARNING("Unable to activate tty1\n");
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-08-07 17:48:30 +03:00
|
|
|
vector<const char *> args;
|
|
|
|
args.reserve(commandLine.size() + 1);
|
|
|
|
for (auto arg : commandLine) {
|
|
|
|
args.push_back(arg.c_str());
|
|
|
|
}
|
|
|
|
args.push_back(nullptr);
|
|
|
|
execvp(commandLine[0].c_str(), (char* const*)&args[0]);
|
|
|
|
WARNING("Failed to exec '%s': %s\n",
|
|
|
|
commandLine[0].c_str(), strerror(errno));
|
|
|
|
}
|