Root/src/launcher.cpp

Source at commit 00d3c3b57008bddf8770c51271db9d766acaf854 created 7 years 5 months ago.
By Maarten ter Huurne, Gave Layer class a protected constructor
1#include "launcher.h"
2
3#include "debug.h"
4
5#include <cerrno>
6#include <cstring>
7#include <unistd.h>
8
9#include <sys/ioctl.h>
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <fcntl.h>
13
14// Bind and activate the framebuffer console on selected platforms.
15#define BIND_CONSOLE \
16        defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
17
18#if BIND_CONSOLE
19#include <linux/vt.h>
20#endif
21
22using namespace std;
23
24
25Launcher::Launcher(vector<string> const& commandLine, bool consoleApp)
26    : commandLine(commandLine)
27    , consoleApp(consoleApp)
28{
29}
30
31Launcher::Launcher(vector<string> && commandLine, bool consoleApp)
32    : commandLine(commandLine)
33    , consoleApp(consoleApp)
34{
35}
36
37void Launcher::exec()
38{
39    if (consoleApp) {
40#if BIND_CONSOLE
41        /* Enable the framebuffer console */
42        char c = '1';
43        int fd = open("/sys/devices/virtual/vtconsole/vtcon1/bind", O_WRONLY);
44        if (fd < 0) {
45            WARNING("Unable to open fbcon handle\n");
46        } else {
47            write(fd, &c, 1);
48            close(fd);
49        }
50
51        fd = open("/dev/tty1", O_RDWR);
52        if (fd < 0) {
53            WARNING("Unable to open tty1 handle\n");
54        } else {
55            if (ioctl(fd, VT_ACTIVATE, 1) < 0)
56                WARNING("Unable to activate tty1\n");
57            close(fd);
58        }
59#endif
60    }
61
62    vector<const char *> args;
63    args.reserve(commandLine.size() + 1);
64    for (auto arg : commandLine) {
65        args.push_back(arg.c_str());
66    }
67    args.push_back(nullptr);
68    execvp(commandLine[0].c_str(), (char* const*)&args[0]);
69    WARNING("Failed to exec '%s': %s\n",
70            commandLine[0].c_str(), strerror(errno));
71}
72

Archive Download this file



interactive