Class SystemdFunctions

java.lang.Object
oshi.ffm.ForeignFunctions
oshi.ffm.linux.SystemdFunctions

public final class SystemdFunctions extends ForeignFunctions
FFM bindings for libsystemd session query functions.
  • Method Details

    • isAvailable

      public static boolean isAvailable()
      Returns whether libsystemd was successfully loaded.
      Returns:
      true if all systemd symbols were bound
    • sdGetSessions

      public static int sdGetSessions(MemorySegment sessionsPtr) throws Throwable
      Calls sd_get_sessions(char ***sessions).
      Parameters:
      sessionsPtr - pointer-to-pointer output segment
      Returns:
      number of sessions on success, negative errno on failure
      Throws:
      Throwable - if the native call fails
    • sdSessionGetUsername

      public static int sdSessionGetUsername(MemorySegment session, MemorySegment usernamePtr) throws Throwable
      Calls sd_session_get_username(session, &username).
      Parameters:
      session - session ID segment (null-terminated)
      usernamePtr - pointer-to-pointer output segment
      Returns:
      0 on success, negative errno on failure
      Throws:
      Throwable - if the native call fails
    • sdSessionGetStartTime

      public static int sdSessionGetStartTime(MemorySegment session, MemorySegment usecPtr) throws Throwable
      Calls sd_session_get_start_time(session, &usec).
      Parameters:
      session - session ID segment (null-terminated)
      usecPtr - pointer to uint64_t output
      Returns:
      0 on success, negative errno on failure
      Throws:
      Throwable - if the native call fails
    • sdSessionGetTty

      public static int sdSessionGetTty(MemorySegment session, MemorySegment ttyPtr) throws Throwable
      Calls sd_session_get_tty(session, &tty).
      Parameters:
      session - session ID segment (null-terminated)
      ttyPtr - pointer-to-pointer output segment
      Returns:
      0 on success, negative errno on failure
      Throws:
      Throwable - if the native call fails
    • sdSessionGetRemoteHost

      public static int sdSessionGetRemoteHost(MemorySegment session, MemorySegment remoteHostPtr) throws Throwable
      Calls sd_session_get_remote_host(session, &remote_host).
      Parameters:
      session - session ID segment (null-terminated)
      remoteHostPtr - pointer-to-pointer output segment
      Returns:
      0 on success, negative errno on failure
      Throws:
      Throwable - if the native call fails
    • free

      public static void free(MemorySegment ptr) throws Throwable
      Calls free(ptr) to release memory allocated by systemd.
      Parameters:
      ptr - the pointer to free
      Throws:
      Throwable - if the native call fails
    • readAndFreeString

      public static String readAndFreeString(MemorySegment ptr, Arena arena) throws Throwable
      Reads a null-terminated string from a pointer and frees the pointer.
      Parameters:
      ptr - the pointer to a C string allocated by systemd
      arena - arena to scope the reinterpret
      Returns:
      the Java string, or null if the pointer is NULL
      Throws:
      Throwable - if the native call fails