playing with socket of systemd journal
Some checks are pending
CodeQL / Analyze (push) Waiting to run

This commit is contained in:
Jörg Prante 2025-03-06 16:32:50 +01:00
parent 6299134fe9
commit 50ab831929
8 changed files with 62 additions and 13 deletions

View file

@ -22,6 +22,7 @@ test {
'--add-opens=java.base/sun.security.util=ALL-UNNAMED' '--add-opens=java.base/sun.security.util=ALL-UNNAMED'
systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties' systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties'
environment 'NOTIFY_SOCKET', '/run/systemd/notify' environment 'NOTIFY_SOCKET', '/run/systemd/notify'
environment 'JOURNAL_SOCKET', '/run/systemd/journal/socket'
testLogging { testLogging {
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED' events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
showStandardStreams = true showStandardStreams = true

View file

@ -2,7 +2,6 @@ module org.xbib.net.socket {
requires java.logging; requires java.logging;
requires transitive com.sun.jna; requires transitive com.sun.jna;
exports org.xbib.net.socket; exports org.xbib.net.socket;
exports org.xbib.net.socket.notify;
exports org.xbib.net.socket.v4; exports org.xbib.net.socket.v4;
exports org.xbib.net.socket.v4.datagram; exports org.xbib.net.socket.v4.datagram;
exports org.xbib.net.socket.v4.icmp; exports org.xbib.net.socket.v4.icmp;
@ -14,4 +13,5 @@ module org.xbib.net.socket {
exports org.xbib.net.socket.v6.icmp; exports org.xbib.net.socket.v6.icmp;
exports org.xbib.net.socket.v6.ping; exports org.xbib.net.socket.v6.ping;
exports org.xbib.net.socket.v6.unix; exports org.xbib.net.socket.v6.unix;
exports org.xbib.net.socket.systemd;
} }

View file

@ -0,0 +1,26 @@
package org.xbib.net.socket.systemd;
import org.xbib.net.socket.v4.unix.UnixDatagramSocket;
import java.io.IOException;
import java.net.SocketException;
import java.util.Objects;
public class SystemdJournal implements AutoCloseable {
private final UnixDatagramSocket socket;
public SystemdJournal() throws SocketException {
String socketName = Objects.requireNonNull(System.getenv("JOURNAL_SOCKET"));
this.socket = new UnixDatagramSocket(socketName);
}
public UnixDatagramSocket getSocket() {
return socket;
}
@Override
public void close() throws IOException {
socket.close();
}
}

View file

@ -1,4 +1,4 @@
package org.xbib.net.socket.notify; package org.xbib.net.socket.systemd;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;

View file

@ -19,9 +19,9 @@ public class UnixDatagramSocket extends Socket {
private final CLibrary.SockAddrUn sockAddrUn; private final CLibrary.SockAddrUn sockAddrUn;
private InputStream is; private InputStream inputStream;
private OutputStream os; private OutputStream outputStream;
public UnixDatagramSocket(String path) throws SocketException { public UnixDatagramSocket(String path) throws SocketException {
this.library = CLibrary.getInstance(); this.library = CLibrary.getInstance();
@ -31,8 +31,8 @@ public class UnixDatagramSocket extends Socket {
if (rc != 0) { if (rc != 0) {
throw new SocketException("can not connect"); throw new SocketException("can not connect");
} }
this.is = new UnixSocketInputStream(this); this.inputStream = new UnixSocketInputStream(this);
this.os = new UnixSocketOutputStream(this); this.outputStream = new UnixSocketOutputStream(this);
} }
private int connect(int sockfd, CLibrary.SockAddrUn sockaddr, int addrlen) throws SocketException { private int connect(int sockfd, CLibrary.SockAddrUn sockaddr, int addrlen) throws SocketException {
@ -70,22 +70,22 @@ public class UnixDatagramSocket extends Socket {
@Override @Override
public InputStream getInputStream() throws IOException { public InputStream getInputStream() throws IOException {
return is; return inputStream;
} }
@Override @Override
public OutputStream getOutputStream() throws IOException { public OutputStream getOutputStream() throws IOException {
return os; return outputStream;
} }
@Override @Override
public void shutdownInput() throws IOException { public void shutdownInput() throws IOException {
is = null; inputStream = null;
} }
@Override @Override
public void shutdownOutput() throws IOException { public void shutdownOutput() throws IOException {
os = null; outputStream = null;
} }
@Override @Override

View file

@ -2,7 +2,7 @@ module org.xbib.net.socket.test {
requires java.logging; requires java.logging;
requires transitive org.junit.jupiter.api; requires transitive org.junit.jupiter.api;
requires org.xbib.net.socket; requires org.xbib.net.socket;
exports org.xbib.net.socket.test.notify;
exports org.xbib.net.socket.test.v4; exports org.xbib.net.socket.test.v4;
exports org.xbib.net.socket.test.v6; exports org.xbib.net.socket.test.v6;
exports org.xbib.net.socket.test.systemd;
} }

View file

@ -0,0 +1,22 @@
package org.xbib.net.socket.test.systemd;
import org.junit.jupiter.api.Test;
import org.xbib.net.socket.systemd.SystemdJournal;
import java.io.IOException;
import java.io.InputStream;
public class SystemdJournalTest {
public SystemdJournalTest() {
}
@Test
public void testSystemdJournal() throws IOException {
try (SystemdJournal systemdJournal = new SystemdJournal()) {
InputStream inputStream = systemdJournal.getSocket().getInputStream();
int ch = inputStream.read();
System.err.println(ch);
};
}
}

View file

@ -1,8 +1,8 @@
package org.xbib.net.socket.test.notify; package org.xbib.net.socket.test.systemd;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.DisabledOnOs;
import org.xbib.net.socket.notify.SystemdNotify; import org.xbib.net.socket.systemd.SystemdNotify;
import java.io.IOException; import java.io.IOException;