Ejemplo n.º 1
0
ErrorCode PlatformSessionImpl::onLaunchDebugServer(Session &session,
                                                   std::string const &host,
                                                   uint16_t &port,
                                                   ProcessId &pid) {
  ProcessSpawner ps;
  StringCollection args;

  ps.setExecutable(Platform::GetSelfExecutablePath());
  args.push_back("slave");
  if (GetLogLevel() == kLogLevelDebug) {
    args.push_back("--debug");
  } else if (GetLogLevel() == kLogLevelPacket) {
    args.push_back("--debug-remote");
  }
  ps.setArguments(args);
  ps.redirectInputToNull();
  ps.redirectOutputToBuffer();

  ErrorCode error;
  error = ps.run();
  if (error != kSuccess)
    return error;
  error = ps.wait();
  if (error != kSuccess)
    return error;

  if (ps.exitStatus() != 0)
    return kErrorInvalidArgument;

  std::istringstream ss;
  ss.str(ps.output());
  ss >> port >> pid;

  return kSuccess;
}
Ejemplo n.º 2
0
Archivo: ProcFS.cpp Proyecto: cosql/ds2
bool ProcFS::GetProcessArguments(pid_t pid, StringCollection &args) {
  FILE *fp = ProcFS::OpenFILE(pid, "cmdline");
  if (fp == nullptr)
    return false;

  args.clear();

  std::string arg;
  for (;;) {
    char buf[1024], *end, *bp;
    size_t nread = fread(buf, 1, sizeof(buf), fp);
    if (nread == 0) {
      if (!arg.empty()) {
        args.push_back(arg);
      }
      break;
    }

    bp = buf, end = buf + nread;
    while (bp < end) {
      while (*bp != '\0') {
        arg += *bp++;
      }
      bp++;
      args.push_back(arg);
      arg.clear();
    }
  }

  std::fclose(fp);
  return true;
}
Ejemplo n.º 3
0
    GameAsset* Script::Create(StreamReader& reader, GameAsset* /*existingInstance*/)
    {
        const int length = reader.ReadInt();

        Buffer buffer;
        buffer.resize(length);

        reader.Read(&buffer[0], length);
        const int numberOfFunctions = reader.ReadInt();
        FunctionTable functionTable;
        functionTable.resize(numberOfFunctions);
        for (int i = 0; i < numberOfFunctions; i++)
        {
            Function& item = functionTable[i];
            item.Name = reader.ReadString();
            item.Position = reader.ReadInt();
            item.ArgumentStackSize = reader.ReadInt();
            item.ReturnTypes.resize(reader.ReadInt());
            for (std::vector<AnyType>::size_type i = 0; i < item.ReturnTypes.size(); i++)
                item.ReturnTypes[i] = static_cast<AnyType>(reader.ReadInt());
            item.ParameterTypes.resize(reader.ReadInt());
            for (std::vector<AnyType>::size_type i = 0; i < item.ParameterTypes.size(); i++)
                item.ParameterTypes[i] = static_cast<AnyType>(reader.ReadInt());
        }

        const int numberOfStrings = reader.ReadInt();
        StringCollection stringTable;
        stringTable.reserve(numberOfStrings);
        for (int i = 0; i < numberOfStrings; i++)
            stringTable.push_back(reader.ReadString());

        return new Script(buffer, functionTable, stringTable, MoveTag());
    }