Skip to content

Commit

Permalink
Merge pull request #12443 from chadlwilson/disable-oshi-udev
Browse files Browse the repository at this point in the history
Disable use of udev for the OSHI system information library
  • Loading branch information
chadlwilson committed Jan 12, 2024
2 parents af0328a + bb372ee commit 7e5972c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import oshi.software.os.OperatingSystem;
import oshi.util.GlobalConfig;
import oshi.util.Util;

import java.util.Optional;

import static oshi.util.GlobalConfig.OSHI_OS_LINUX_ALLOWUDEV;

public class SystemInfo {
private static final Logger LOG = LoggerFactory.getLogger(SystemInfo.class);
private static final String OS_COMPLETE_NAME = determineOperatingSystemCompleteName();
Expand Down Expand Up @@ -54,6 +57,11 @@ private static void useAgentTmpDirIfNecessary() {
}

static oshi.SystemInfo newSystemInfo() {
// Allowing OSHI to load information from udev causes issues on Alpine due to use of glibc JVMs,
// if the musl udev is installed. Since we don't rely on this hardware info, we can disable it
// but better to remove this if Alpine is no longer supported for agents, or we have a more MUSL
// Alpine environment.
GlobalConfig.set(OSHI_OS_LINUX_ALLOWUDEV, "false");
return new oshi.SystemInfo();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,27 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.MockedStatic;
import oshi.util.GlobalConfig;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import uk.org.webcompere.systemstubs.properties.SystemProperties;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mockStatic;
import static oshi.util.GlobalConfig.OSHI_OS_LINUX_ALLOWUDEV;

@ExtendWith(SystemStubsExtension.class)
class SystemInfoTest {

@SystemStub
SystemProperties props;

@Test
public void shouldDisableUdevUsage() {
SystemInfo.determineOperatingSystemCompleteName();
assertThat(GlobalConfig.get(OSHI_OS_LINUX_ALLOWUDEV, true)).isFalse();
}

@Test
public void shouldDefaultJnaTmpDirIfUnset() {
SystemInfo.determineOperatingSystemCompleteName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ enum Distro implements DistroBehavior {
return alpine.getInstallPrerequisitesCommands(v) +
[
'apk add --no-cache sudo',
'rm -rf /lib/libudev.so*', // btrfs is installed by Docker, but requires eudev-libs, which causes issues with OSHI JNA libary on Alpine with glibc and JVM crashes. Dont think we need udev as it's only needed by btrfs for multipath support.
]
}

Expand Down
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final Map<String, String> libraries = [
mysql : 'com.mysql:mysql-connector-j:8.2.0',
objenesis : 'org.objenesis:objenesis:3.3',
oscache : 'opensymphony:oscache:2.4.1',
oshi : 'com.github.oshi:oshi-core-java11:6.4.10',
oshi : 'com.github.oshi:oshi-core-java11:6.4.11',
postgresql : 'org.postgresql:postgresql:42.7.1',
quartz : 'org.quartz-scheduler:quartz:2.3.2',
rack : 'org.jruby.rack:jruby-rack:1.1.22',
Expand Down

0 comments on commit 7e5972c

Please sign in to comment.