]> Sergey Matveev's repositories - public-inbox.git/commit
emergency: modernize and reduce syscalls
authorEric Wong <e@80x24.org>
Fri, 19 Feb 2021 00:58:32 +0000 (00:58 +0000)
committerEric Wong <e@80x24.org>
Fri, 19 Feb 2021 19:25:20 +0000 (19:25 +0000)
commit3e821621a5a423e0b3266e7979cb57566a79b95a
tree92de97908721e6cf5d4ad212d0ae7cd5718d9aca
parent427552fcb34d117635225bb30836bbbae7d61590
emergency: modernize and reduce syscalls

As with LeiToMail, we'll exclusively rely on O_EXCL and EEXIST
instead of "-f" (stat(2)) for file name collision checking.
Furthermore, we can rely on link(2) error handling instead of
using stat(2) to check the result of link(2).

We'll still keep the hostname in these filenames, but memoize it
on a per-instance basis since hostname changes are rare and we
can assume it won't change between "tmp" and "cur".

We'll also start embedding the PID as {"tmp.$$"} into the fiel
name to guard against accidental deletion in child processes,
instead of requiring an extra hash lookup.

Finally, avoid multiple getpid(2) syscalls in internal subs
since glibc no longer caches in getpid(3).

We'll also favor constant comparison of $! against EEXIST for
inlining. and stop doing ->autoflush when we only have a single
print + flush.
lib/PublicInbox/Emergency.pm