summaryrefslogtreecommitdiffstats
path: root/widget/LSBUtils.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /widget/LSBUtils.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/LSBUtils.cpp')
-rw-r--r--widget/LSBUtils.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/widget/LSBUtils.cpp b/widget/LSBUtils.cpp
new file mode 100644
index 0000000000..bcadddef12
--- /dev/null
+++ b/widget/LSBUtils.cpp
@@ -0,0 +1,70 @@
+/* -*- 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"
+#include "mozilla/Result.h"
+#include "mozilla/ResultVariant.h"
+#include "mozilla/ipc/LaunchError.h"
+
+namespace mozilla::widget::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"};
+
+ base::LaunchOptions options;
+ options.fds_to_remap.push_back({pipefd[1], STDOUT_FILENO});
+ options.wait = true;
+
+ base::ProcessHandle process;
+ Result<Ok, ipc::LaunchError> err = base::LaunchApp(argv, options, &process);
+ close(pipefd[1]);
+ if (err.isErr()) {
+ NS_WARNING("Failed to spawn lsb_release!");
+ close(pipefd[0]);
+ return false;
+ }
+
+ ScopedCloseFile 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!");
+ return false;
+ }
+
+ aDistributor.Assign(dist);
+ aDescription.Assign(desc);
+ aRelease.Assign(release);
+ aCodename.Assign(codename);
+ return true;
+}
+
+} // namespace mozilla::widget::lsb