NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/60729: incosistent st_ino from the first stat(2) on a socket
>Number: 60729
>Category: kern
>Synopsis: incosistent st_ino from the first stat(2) on a socket
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Sep 14 22:30:00 +0000 2026
>Originator: Valery Ushakov
>Release: NetBSD 11.99
>Organization:
>Environment:
>Description:
Came across this blog post on lobsters:
https://yuvalino.com/how-can-you-not-be-romantic-about-unix-domain-sockets
The absolutely first call of stat(2) on a socket returns st_ino of zero.
The next call of stat(2) on the same socket will return a different st_ino.
>How-To-Repeat:
# cat sockino.c
#include <sys/socket.h>
#include <sys/stat.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
int
main()
{
int status;
int sock[2];
status = socketpair(PF_UNIX, SOCK_DGRAM, 0, sock);
if (status < 0)
err(EXIT_FAILURE, "socketpair");
struct stat st;
status = fstat(sock[0], &st);
if (status < 0)
err(EXIT_FAILURE, "fstat");
printf("%lld/%llu\n",
(signed long long)st.st_dev,
(unsigned long long)st.st_ino);
status = fstat(sock[0], &st);
if (status < 0)
err(EXIT_FAILURE, "fstat");
printf("%lld/%llu\n",
(signed long long)st.st_dev,
(unsigned long long)st.st_ino);
return 0;
}
# ./sockino
-1/0
-1/1
# ./sockino
-1/2
-1/2
>Fix:
A comment on lobsters
https://lobste.rs/s/uauns9/how_can_you_not_be_romantic_about_unix
pointed to
https://cgit.freebsd.org/src/commit/sys/kern/uipc_usrreq.c?id=6f782c4636672e40c45ef9c9f17635e6c110d290
https://cgit.freebsd.org/src/commit/sys/kern/uipc_usrreq.c?id=f218ac5087c7697321d3866d68c037cc88b0b005
Home |
Main Index |
Thread Index |
Old Index