SystemMaybe Fs::readKillPreferenceAt()

in src/oomd/util/Fs.cpp [779:817]


SystemMaybe<KillPreference> Fs::readKillPreferenceAt(const DirFd& path) {
  auto maybe = Fs::hasxattrAt(path, kOomdSystemPreferXAttr);
  if (!maybe) {
    return SYSTEM_ERROR(maybe.error());
  }

  if (*maybe) {
    return KillPreference::PREFER;
  }

  maybe = Fs::hasxattrAt(path, kOomdUserPreferXAttr);
  if (!maybe) {
    return SYSTEM_ERROR(maybe.error());
  }

  if (*maybe) {
    return KillPreference::PREFER;
  }

  maybe = Fs::hasxattrAt(path, kOomdSystemAvoidXAttr);
  if (!maybe) {
    return SYSTEM_ERROR(maybe.error());
  }

  if (*maybe) {
    return KillPreference::AVOID;
  }

  maybe = Fs::hasxattrAt(path, kOomdUserAvoidXAttr);
  if (!maybe) {
    return SYSTEM_ERROR(maybe.error());
  }

  if (*maybe) {
    return KillPreference::AVOID;
  }

  return KillPreference::NORMAL;
}