aboutsummaryrefslogtreecommitdiff
path: root/seatd
diff options
context:
space:
mode:
Diffstat (limited to 'seatd')
-rw-r--r--seatd/client.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/seatd/client.c b/seatd/client.c
index 6b6f3b3..0097792 100644
--- a/seatd/client.c
+++ b/seatd/client.c
@@ -14,6 +14,10 @@
#include <sys/un.h>
#endif
+#if defined(__NetBSD__)
+#include <sys/un.h>
+#endif
+
#include "client.h"
#include "linked_list.h"
#include "log.h"
@@ -34,6 +38,23 @@ static int get_peer(int fd, pid_t *pid, uid_t *uid, gid_t *gid) {
*uid = cred.uid;
*gid = cred.gid;
return 0;
+#elif defined(__NetBSD__)
+ struct unpcbid cred;
+ socklen_t len = sizeof cred;
+ if (getsockopt(fd, 0, LOCAL_PEEREID, &cred, &len) == -1) {
+ // assume builtin backend
+ if (errno == EINVAL) {
+ *pid = getpid();
+ *uid = getuid();
+ *gid = getgid();
+ return 0;
+ }
+ return -1;
+ }
+ *pid = cred.unp_pid;
+ *uid = cred.unp_euid;
+ *gid = cred.unp_egid;
+ return 0;
#elif defined(__FreeBSD__)
struct xucred cred;
socklen_t len = sizeof cred;
@@ -468,7 +489,13 @@ int client_handle_connection(int fd, uint32_t mask, void *data) {
goto fail;
}
if (len == 0) {
+// https://man.netbsd.org/poll.2
+// Sockets produce POLLIN rather than POLLHUP when the remote end is closed.
+#if defined(__NetBSD__)
+ log_info("Client disconnected");
+#else
log_error("Could not read client connection: zero-length read");
+#endif
goto fail;
}