| 27 | #define LEMON_MODULE_NAME "ProcessRunner" |
| 28 | |
| 29 | ProcessRunnerResult UnixProcessRunner::run() { |
| 30 | ProcessRunnerResult res; |
| 31 | res.result = CorrectAnswer; |
| 32 | int extraTime = qCeil(qMax(2000, config.timeLimit * 2) * config.extraTimeRatio); |
| 33 | |
| 34 | #ifdef Q_OS_LINUX |
| 35 | // TODO: rewrite with cgroup |
| 36 | QFile watcher(config.workingDirectory + QUuid::createUuid().toString(QUuid::Id128)); |
| 37 | |
| 38 | if (config.interpreterAsWatcher) { |
| 39 | QFile::copy(config.executableFile, watcher.fileName()); |
| 40 | } else { |
| 41 | QFile::copy(":/watcher/watcher_unix", watcher.fileName()); |
| 42 | } |
| 43 | |
| 44 | watcher.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner); |
| 45 | auto *runner = new QProcess(); |
| 46 | QStringList argumentsList; |
| 47 | |
| 48 | argumentsList << "--dev" << "/dev"; |
| 49 | argumentsList << "--proc" << "/proc"; |
| 50 | argumentsList << "--ro-bind" << "/usr" << "/usr"; |
| 51 | argumentsList << "--symlink" << "/usr/lib" << "/lib"; |
| 52 | argumentsList << "--symlink" << "/usr/lib64" << "/lib64"; |
| 53 | argumentsList << "--symlink" << "/usr/bin" << "/bin"; |
| 54 | argumentsList << "--symlink" << "/usr/sbin" << "/sbin"; |
| 55 | argumentsList << "--tmpfs" << "/tmp"; |
| 56 | |
| 57 | argumentsList << "--unshare-all" << "--die-with-parent"; |
| 58 | |
| 59 | argumentsList << "--chdir" << config.workingDirectory; |
| 60 | |
| 61 | argumentsList << "--bind" << config.workingDirectory << config.workingDirectory; |
| 62 | |
| 63 | if (config.standardInputCheck) { |
| 64 | argumentsList << "--ro-bind" << QFileInfo(config.inputFile).absoluteFilePath() |
| 65 | << QFileInfo(config.inputFile).absoluteFilePath(); |
| 66 | } |
| 67 | |
| 68 | argumentsList << watcher.fileName(); |
| 69 | |
| 70 | argumentsList << config.executableFile; |
| 71 | argumentsList << config.arguments; |
| 72 | |
| 73 | if (config.standardInputCheck) { |
| 74 | argumentsList << QFileInfo(config.inputFile).absoluteFilePath(); |
| 75 | } else { |
| 76 | argumentsList << ""; |
| 77 | } |
| 78 | |
| 79 | if (config.standardOutputCheck) { |
| 80 | argumentsList << "_tmpout"; |
| 81 | } else { |
| 82 | argumentsList << ""; |
| 83 | } |
| 84 | |
| 85 | argumentsList << "_tmperr"; |
| 86 | argumentsList << QString("%1").arg(config.timeLimit); |
nothing calls this directly
no test coverage detected