Bug 1452643 [wpt PR 10327] - [css-multicol] column-gap normal is 1em per spec now...
[gecko.git] / widget / LSBUtils.cpp
blob344fea4d0b67a94b9c52106864ed9042946ce6a4
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "LSBUtils.h"
9 #include <unistd.h>
10 #include "base/process_util.h"
12 namespace mozilla {
13 namespace widget {
14 namespace lsb {
16 static const char* gLsbReleasePath = "/usr/bin/lsb_release";
18 bool
19 GetLSBRelease(nsACString& aDistributor,
20 nsACString& aDescription,
21 nsACString& aRelease,
22 nsACString& aCodename)
24 if (access(gLsbReleasePath, R_OK) != 0)
25 return false;
27 int pipefd[2];
28 if (pipe(pipefd) == -1) {
29 NS_WARNING("pipe() failed!");
30 return false;
33 std::vector<std::string> argv = {
34 gLsbReleasePath, "-idrc"
37 base::LaunchOptions options;
38 options.fds_to_remap.push_back({ pipefd[1], STDOUT_FILENO });
39 options.wait = true;
41 base::ProcessHandle process;
42 bool ok = base::LaunchApp(argv, options, &process);
43 close(pipefd[1]);
44 if (!ok) {
45 NS_WARNING("Failed to spawn lsb_release!");
46 close(pipefd[0]);
47 return false;
50 FILE* stream = fdopen(pipefd[0], "r");
51 if (!stream) {
52 NS_WARNING("Could not wrap fd!");
53 close(pipefd[0]);
54 return false;
57 char dist[256], desc[256], release[256], codename[256];
58 if (fscanf(stream, "Distributor ID:\t%255[^\n]\n"
59 "Description:\t%255[^\n]\n"
60 "Release:\t%255[^\n]\n"
61 "Codename:\t%255[^\n]\n",
62 dist, desc, release, codename) != 4)
64 NS_WARNING("Failed to parse lsb_release!");
65 fclose(stream);
66 close(pipefd[0]);
67 return false;
69 fclose(stream);
70 close(pipefd[0]);
72 aDistributor.Assign(dist);
73 aDescription.Assign(desc);
74 aRelease.Assign(release);
75 aCodename.Assign(codename);
76 return true;
79 } // namespace lsb
80 } // namespace widget
81 } // namespace mozilla