author Johann Hofmann <jhofmann@mozilla.com>
Fri, 19 Oct 2018 14:21:41 +0000
changeset 500657 776414145c58b27c8135d102d71263164f1d329f
parent 484311 a299ae02fc4c0a7c507e4410c28414a9fdb25b90
child 508163 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
Bug 1500103 - Only test return_button_adv and exception_button for new cert error pages. r=nhnt11 exception_button can technically be clicked on the old error pages, too, but conditionally checking for the cert exception window to pop up is a bit overkill for this temporary workaround. Ideally we would remove this pref soon anyway. Differential Revision: https://phabricator.services.mozilla.com/D9243

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "LSBUtils.h"

#include <unistd.h>
#include "base/process_util.h"
#include "mozilla/FileUtils.h"

namespace mozilla {
namespace widget {
namespace lsb {

static const char* gLsbReleasePath = "/usr/bin/lsb_release";

GetLSBRelease(nsACString& aDistributor,
              nsACString& aDescription,
              nsACString& aRelease,
              nsACString& aCodename)
  if (access(gLsbReleasePath, R_OK) != 0)
    return false;

  int pipefd[2];
  if (pipe(pipefd) == -1) {
    NS_WARNING("pipe() failed!");
    return false;

  std::vector<std::string> argv = {
    gLsbReleasePath, "-idrc"

  base::LaunchOptions options;
  options.fds_to_remap.push_back({ pipefd[1], STDOUT_FILENO });
  options.wait = true;

  base::ProcessHandle process;
  bool ok = base::LaunchApp(argv, options, &process);
  if (!ok) {
    NS_WARNING("Failed to spawn lsb_release!");
    return false;

  ScopedCloseFile stream(fdopen(pipefd[0], "r"));
  if (!stream) {
    NS_WARNING("Could not wrap fd!");
    return false;

  char dist[256], desc[256], release[256], codename[256];
  if (fscanf(stream, "Distributor ID:\t%255[^\n]\n"
             dist, desc, release, codename) != 4)
    NS_WARNING("Failed to parse lsb_release!");
    return false;

  return true;

}  // namespace lsb
}  // namespace widget
}  // namespace mozilla