summaryrefslogtreecommitdiffstats
path: root/widget/LSBUtils.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /widget/LSBUtils.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'widget/LSBUtils.cpp')
-rw-r--r--widget/LSBUtils.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/widget/LSBUtils.cpp b/widget/LSBUtils.cpp
new file mode 100644
index 000000000..fdb954425
--- /dev/null
+++ b/widget/LSBUtils.cpp
@@ -0,0 +1,81 @@
+/* -*- 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"
+
+namespace mozilla {
+namespace widget {
+namespace lsb {
+
+static const char* gLsbReleasePath = "/usr/bin/lsb_release";
+
+bool
+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"
+ };
+
+ std::vector<std::pair<int, int>> fdMap = {
+ { pipefd[1], STDOUT_FILENO }
+ };
+
+ base::ProcessHandle process;
+ base::LaunchApp(argv, fdMap, true, &process);
+ close(pipefd[1]);
+ if (!process) {
+ NS_WARNING("Failed to spawn lsb_release!");
+ close(pipefd[0]);
+ return false;
+ }
+
+ FILE* stream = fdopen(pipefd[0], "r");
+ if (!stream) {
+ NS_WARNING("Could not wrap fd!");
+ close(pipefd[0]);
+ return false;
+ }
+
+ char dist[256], desc[256], release[256], codename[256];
+ if (fscanf(stream, "Distributor ID:\t%255[^\n]\n"
+ "Description:\t%255[^\n]\n"
+ "Release:\t%255[^\n]\n"
+ "Codename:\t%255[^\n]\n",
+ dist, desc, release, codename) != 4)
+ {
+ NS_WARNING("Failed to parse lsb_release!");
+ fclose(stream);
+ close(pipefd[0]);
+ return false;
+ }
+ fclose(stream);
+ close(pipefd[0]);
+
+ aDistributor.Assign(dist);
+ aDescription.Assign(desc);
+ aRelease.Assign(release);
+ aCodename.Assign(codename);
+ return true;
+}
+
+} // namespace lsb
+} // namespace widget
+} // namespace mozilla