summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2020-08-22 18:34:29 +0000
committermillert <millert@openbsd.org>2020-08-22 18:34:29 +0000
commit03397e00e4a1117098cfed5fd064dbdf196d9ca5 (patch)
tree105659dcd99fdd71c91113f1f7dc791b42302f0c
parentConvert icmp_sysctl to sysctl_bounded_args (diff)
downloadwireguard-openbsd-03397e00e4a1117098cfed5fd064dbdf196d9ca5.tar.xz
wireguard-openbsd-03397e00e4a1117098cfed5fd064dbdf196d9ca5.zip
Support looking up unix domain sockets by file name.
The best that we can do is string comparison of the file name. Previously, "fstat /var/run/foo.sock" would return no results. The -f option still won't work for sockets since they are not file system objects. OK kn@
-rw-r--r--usr.bin/fstat/fstat.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index 7bbb1b2d4cb..60316e17056 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fstat.c,v 1.100 2020/08/21 22:13:15 millert Exp $ */
+/* $OpenBSD: fstat.c,v 1.101 2020/08/22 18:34:29 millert Exp $ */
/*
* Copyright (c) 2009 Todd C. Miller <millert@openbsd.org>
@@ -408,8 +408,7 @@ fstat_dofile(struct kinfo_file *kf)
vtrans(kf);
break;
case DTYPE_SOCKET:
- if (checkfile == 0)
- socktrans(kf);
+ socktrans(kf);
break;
case DTYPE_PIPE:
if (checkfile == 0)
@@ -750,6 +749,21 @@ socktrans(struct kinfo_file *kf)
#define STYPEMAX 5
char *stype, stypebuf[24];
+ if (checkfile) {
+ struct filearg *fa;
+
+ if (kf->so_type != AF_UNIX)
+ return;
+ SLIST_FOREACH(fa, &fileargs, next) {
+ if (fa->dev != 0)
+ continue;
+ if (strcmp(kf->unp_path, fa->name) == 0)
+ break;
+ }
+ if (fa == NULL)
+ return;
+ }
+
PREFIX(kf->fd_fd);
if (kf->so_type > STYPEMAX) {
@@ -914,12 +928,19 @@ getfname(char *filename)
}
}
}
+ if (!fuser && S_ISSOCK(sb.st_mode)) {
+ char *newname = realpath(filename, NULL);
+ if (newname != NULL)
+ filename = newname;
+ }
- if ((cur = malloc(sizeof(*cur))) == NULL)
+ if ((cur = calloc(1, sizeof(*cur))) == NULL)
err(1, NULL);
- cur->ino = sb.st_ino;
- cur->dev = sb.st_dev & 0xffff;
+ if (!S_ISSOCK(sb.st_mode)) {
+ cur->ino = sb.st_ino;
+ cur->dev = sb.st_dev & 0xffff;
+ }
cur->name = filename;
TAILQ_INIT(&cur->fusers);
SLIST_INSERT_HEAD(&fileargs, cur, next);