playing with socket of systemd journal
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Some checks are pending
CodeQL / Analyze (push) Waiting to run
This commit is contained in:
parent
6299134fe9
commit
50ab831929
8 changed files with 62 additions and 13 deletions
|
@ -22,6 +22,7 @@ test {
|
|||
'--add-opens=java.base/sun.security.util=ALL-UNNAMED'
|
||||
systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties'
|
||||
environment 'NOTIFY_SOCKET', '/run/systemd/notify'
|
||||
environment 'JOURNAL_SOCKET', '/run/systemd/journal/socket'
|
||||
testLogging {
|
||||
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
|
||||
showStandardStreams = true
|
||||
|
|
|
@ -2,7 +2,6 @@ module org.xbib.net.socket {
|
|||
requires java.logging;
|
||||
requires transitive com.sun.jna;
|
||||
exports org.xbib.net.socket;
|
||||
exports org.xbib.net.socket.notify;
|
||||
exports org.xbib.net.socket.v4;
|
||||
exports org.xbib.net.socket.v4.datagram;
|
||||
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.ping;
|
||||
exports org.xbib.net.socket.v6.unix;
|
||||
exports org.xbib.net.socket.systemd;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.xbib.net.socket.notify;
|
||||
package org.xbib.net.socket.systemd;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
|
@ -19,9 +19,9 @@ public class UnixDatagramSocket extends Socket {
|
|||
|
||||
private final CLibrary.SockAddrUn sockAddrUn;
|
||||
|
||||
private InputStream is;
|
||||
private InputStream inputStream;
|
||||
|
||||
private OutputStream os;
|
||||
private OutputStream outputStream;
|
||||
|
||||
public UnixDatagramSocket(String path) throws SocketException {
|
||||
this.library = CLibrary.getInstance();
|
||||
|
@ -31,8 +31,8 @@ public class UnixDatagramSocket extends Socket {
|
|||
if (rc != 0) {
|
||||
throw new SocketException("can not connect");
|
||||
}
|
||||
this.is = new UnixSocketInputStream(this);
|
||||
this.os = new UnixSocketOutputStream(this);
|
||||
this.inputStream = new UnixSocketInputStream(this);
|
||||
this.outputStream = new UnixSocketOutputStream(this);
|
||||
}
|
||||
|
||||
private int connect(int sockfd, CLibrary.SockAddrUn sockaddr, int addrlen) throws SocketException {
|
||||
|
@ -70,22 +70,22 @@ public class UnixDatagramSocket extends Socket {
|
|||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return is;
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return os;
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdownInput() throws IOException {
|
||||
is = null;
|
||||
inputStream = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdownOutput() throws IOException {
|
||||
os = null;
|
||||
outputStream = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,7 @@ module org.xbib.net.socket.test {
|
|||
requires java.logging;
|
||||
requires transitive org.junit.jupiter.api;
|
||||
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.v6;
|
||||
exports org.xbib.net.socket.test.systemd;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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.condition.DisabledOnOs;
|
||||
import org.xbib.net.socket.notify.SystemdNotify;
|
||||
import org.xbib.net.socket.systemd.SystemdNotify;
|
||||
|
||||
import java.io.IOException;
|
||||
|
Loading…
Reference in a new issue