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