On Fri, 14 Jan 2022, Robert Elz wrote:
If your patch makes any difference to the way ls /proc/self/fd works, that is just a fluke (relates to the way ls happens to sequence its operations) and in no way any kind of general fix.
It does not, and wasn't meant to. I noticed that d_type was being set to VREG and attached a patch for that to my reply.
If procfs is not setting d_type correctly, that should be fixed.
I think this does it: ---START--- --- sys/miscfs/procfs/procfs_vnops.c.orig 2022-01-12 03:57:25.944841288 +0000 +++ sys/miscfs/procfs/procfs_vnops.c 2022-01-14 06:12:33.154215255 +0000 @@ -162,12 +162,12 @@ { DT_DIR, N("fd"), PFSfd, NULL }, { DT_DIR, N("task"), PFStask, procfs_validfile_linux }, { DT_LNK, N("cwd"), PFScwd, NULL }, - { DT_LNK, N("emul"), PFSemul, NULL }, + { DT_REG, N("emul"), PFSemul, NULL }, { DT_LNK, N("root"), PFSchroot, NULL }, { DT_REG, N("auxv"), PFSauxv, procfs_validauxv }, { DT_REG, N("cmdline"), PFScmdline, NULL }, { DT_REG, N("environ"), PFSenviron, NULL }, - { DT_REG, N("exe"), PFSexe, procfs_validfile }, + { DT_LNK, N("exe"), PFSexe, procfs_validfile }, { DT_REG, N("file"), PFSfile, procfs_validfile }, { DT_REG, N("fpregs"), PFSfpregs, procfs_validfpregs }, { DT_REG, N("limit"), PFSlimit, NULL }, @@ -223,6 +223,7 @@ int procfs_pathconf(void *); int procfs_getpages(void *); +static uint8_t fttodt(file_t *fp); static int atoi(const char *, size_t); /* @@ -1410,7 +1411,7 @@ d.d_fileno = PROCFS_FILENO(pfs->pfs_pid, PFSfd, i - 2); d.d_namlen = snprintf(d.d_name, sizeof(d.d_name), "%lld", (long long)(i - 2)); - d.d_type = VREG; + d.d_type = fttodt(fp); if ((error = uiomove(&d, UIO_MX, uio)) != 0) break; if (cookies) @@ -1731,6 +1732,34 @@ return (EFAULT); } +/** + * convert DTYPE_XXX to corresponding DT_XXX + * matching what procfs_loadvnode() does. + */ +static uint8_t +fttodt(file_t *fp) +{ + switch (fp->f_type) { + case DTYPE_VNODE: + switch (fp->f_vnode->v_type) { + case VREG: return DT_REG; + case VDIR: return DT_LNK; /* symlink */ + case VBLK: return DT_BLK; + case VCHR: return DT_CHR; + case VLNK: return DT_LNK; + case VSOCK: return DT_SOCK; + case VFIFO: return DT_FIFO; + default: return DT_UNKNOWN; + } + case DTYPE_PIPE: return DT_FIFO; + case DTYPE_SOCKET: return DT_SOCK; + case DTYPE_KQUEUE: /*FALLTHROUGH*/ + case DTYPE_MISC: /*FALLTHROUGH*/ + case DTYPE_SEM: return DT_LNK; /* symlinks */ + default: return DT_UNKNOWN; + } +} + /* * convert decimal ascii to int */ ---END--- Thx, -RVP