|
33 | 33 | import java.lang.reflect.Method;
|
34 | 34 | import java.nio.file.Files;
|
35 | 35 | import java.nio.file.Path;
|
| 36 | +import java.util.Collections; |
36 | 37 | import java.util.HashMap;
|
37 | 38 | import java.util.List;
|
38 | 39 | import java.util.Map;
|
@@ -566,22 +567,33 @@ private String getPrettyName() throws IOException {
|
566 | 567 | }
|
567 | 568 |
|
568 | 569 | /**
|
569 |
| - * The lines from {@code /etc/os-release} or {@code /usr/lib/os-release} as a fallback. These file represents identification of the |
570 |
| - * underlying operating system. The structure of the file is newlines of key-value pairs of shell-compatible variable assignments. |
| 570 | + * The lines from {@code /etc/os-release} or {@code /usr/lib/os-release} as a fallback, with an additional fallback to |
| 571 | + * {@code /etc/system-release}. These files represent identification of the underlying operating system. The structure of the file is |
| 572 | + * newlines of key-value pairs of shell-compatible variable assignments. |
571 | 573 | *
|
572 |
| - * @return the lines from {@code /etc/os-release} or {@code /usr/lib/os-release} |
573 |
| - * @throws IOException if an I/O exception occurs reading {@code /etc/os-release} or {@code /usr/lib/os-release} |
| 574 | + * @return the lines from {@code /etc/os-release} or {@code /usr/lib/os-release} or {@code /etc/system-release} |
| 575 | + * @throws IOException if an I/O exception occurs reading {@code /etc/os-release} or {@code /usr/lib/os-release} or |
| 576 | + * {@code /etc/system-release} |
574 | 577 | */
|
575 |
| - @SuppressForbidden(reason = "access /etc/os-release or /usr/lib/os-release") |
| 578 | + @SuppressForbidden(reason = "access /etc/os-release or /usr/lib/os-release or /etc/system-release") |
576 | 579 | List<String> readOsRelease() throws IOException {
|
577 | 580 | final List<String> lines;
|
578 | 581 | if (Files.exists(PathUtils.get("/etc/os-release"))) {
|
579 | 582 | lines = Files.readAllLines(PathUtils.get("/etc/os-release"));
|
580 |
| - } else { |
| 583 | + assert lines != null && lines.isEmpty() == false; |
| 584 | + return lines; |
| 585 | + } else if (Files.exists(PathUtils.get("/usr/lib/os-release"))) { |
581 | 586 | lines = Files.readAllLines(PathUtils.get("/usr/lib/os-release"));
|
| 587 | + assert lines != null && lines.isEmpty() == false; |
| 588 | + return lines; |
| 589 | + } else if (Files.exists(PathUtils.get("/etc/system-release"))) { |
| 590 | + // fallback for older Red Hat-like OS |
| 591 | + lines = Files.readAllLines(PathUtils.get("/etc/system-release")); |
| 592 | + assert lines != null && lines.size() == 1; |
| 593 | + return Collections.singletonList("PRETTY_NAME=\"" + lines.get(0) + "\""); |
| 594 | + } else { |
| 595 | + return Collections.emptyList(); |
582 | 596 | }
|
583 |
| - assert lines != null && lines.isEmpty() == false; |
584 |
| - return lines; |
585 | 597 | }
|
586 | 598 |
|
587 | 599 | public OsStats osStats() {
|
|
0 commit comments