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/. */
10 #include "base/process_util.h"
16 static const char* gLsbReleasePath
= "/usr/bin/lsb_release";
19 GetLSBRelease(nsACString
& aDistributor
,
20 nsACString
& aDescription
,
22 nsACString
& aCodename
)
24 if (access(gLsbReleasePath
, R_OK
) != 0)
28 if (pipe(pipefd
) == -1) {
29 NS_WARNING("pipe() failed!");
33 std::vector
<std::string
> argv
= {
34 gLsbReleasePath
, "-idrc"
37 base::LaunchOptions options
;
38 options
.fds_to_remap
.push_back({ pipefd
[1], STDOUT_FILENO
});
41 base::ProcessHandle process
;
42 bool ok
= base::LaunchApp(argv
, options
, &process
);
45 NS_WARNING("Failed to spawn lsb_release!");
50 FILE* stream
= fdopen(pipefd
[0], "r");
52 NS_WARNING("Could not wrap fd!");
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!");
72 aDistributor
.Assign(dist
);
73 aDescription
.Assign(desc
);
74 aRelease
.Assign(release
);
75 aCodename
.Assign(codename
);
81 } // namespace mozilla