X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/e03c48e0ae58c3d37e03dc3eb0e89d44b07d40f9..76fe6ad7999dee19ddbe80f518c62c4685ef95b4:/src/main/java/org/asamk/signal/util/IOUtils.java diff --git a/src/main/java/org/asamk/signal/util/IOUtils.java b/src/main/java/org/asamk/signal/util/IOUtils.java index 9f220946..7f93417f 100644 --- a/src/main/java/org/asamk/signal/util/IOUtils.java +++ b/src/main/java/org/asamk/signal/util/IOUtils.java @@ -15,6 +15,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.StandardProtocolFamily; import java.net.UnixDomainSocketAddress; +import java.nio.channels.ClosedChannelException; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.nio.charset.Charset; @@ -34,7 +35,7 @@ import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE; public class IOUtils { - private final static Logger logger = LoggerFactory.getLogger(IOUtils.class); + private static final Logger logger = LoggerFactory.getLogger(IOUtils.class); private IOUtils() { } @@ -93,6 +94,9 @@ public class IOUtils { return () -> { try { return bufferedReader.readLine(); + } catch (ClosedChannelException ignored) { + logger.trace("Line supplier has been interrupted."); + return null; } catch (IOException e) { logger.error("Error occurred while reading line", e); return null; @@ -121,13 +125,13 @@ public class IOUtils { return socketAddress; } - public static UnixDomainPrincipal getUnixDomainPrincipal(final SocketChannel channel) throws IOException { + public static String getUnixDomainPrincipal(final SocketChannel channel) throws IOException { UnixDomainPrincipal principal = null; try { principal = channel.getOption(ExtendedSocketOptions.SO_PEERCRED); - } catch (UnsupportedOperationException ignored) { + } catch (UnsupportedOperationException | NoClassDefFoundError ignored) { } - return principal; + return principal == null ? null : principal.toString(); } public static ServerSocketChannel bindSocket(final SocketAddress address) throws IOErrorException { @@ -138,7 +142,7 @@ public class IOUtils { ? ServerSocketChannel.open(StandardProtocolFamily.UNIX) : ServerSocketChannel.open(); serverChannel.bind(address); - logger.info("Listening on socket: " + address); + logger.debug("Listening on socket: " + address); postBind(address); } catch (IOException e) { throw new IOErrorException("Failed to bind socket " + address + ": " + e.getMessage(), e);