Re: openat("./...", O_CREAT) fails even though the directory exists

From: Olivier Certner <olce_at_freebsd.org>
Date: Mon, 13 Oct 2025 09:57:14 UTC
> - trying to create "./df59D8I2px044288", which doesn't exist, with
>   O_CREAT|O_EXCL fails with ENOENT.

Oh, indeed, I had missed the O_CREAT|O_EXCL.  I'll grab some more caffeine...
 
> after some more debugging, i think what's going on here is that pkg(8)
> is deleting and recreating /var/spool/mqueue on upgrade, which means
> smmsp's open fd to that directory is no longer valid, and therefore
> openat() returns this unusual error.

Yes, if the directory was removed but is still open, FSes will typically return an error at lookup (which is a sub-process of creating a file there) in this directory (e.g., UFS returns ENOENT).
 
> i suspect the fix will be in pkgbase
> somewhere: for example, we could restart sendmail on upgrade, or tell
> the user to do that.

Most probably it will need too, yes.

-- 
Olivier Certner