From: Andrew Hewus Fresh Subject: Re: Earlier /tmp cleanup in /etc/rc To: tech@openbsd.org Cc: kn@openbsd.org Date: Wed, 26 Aug 2026 18:56:38 -0700 Next iteration of this, which I think works properly (although I have thought that before). The current implementation always uses find -mindepth 1 -maxdepth 1 which lets us go back to using -name instead of -path for the set of file names to ignore. We do that, because when we use find -d to remove a few files, the depth first search makes the -path or -name ineffective, still deleting files inside of those "skipped" top-level directories. Using xargs, as we do with mv, lets us call find again to search by depth with only those top-level entries we wish to clean. Again, in comparison with what is there, instead of attempting to make inode space by deleting a likely file that might not be there, we instead use the same find arguments twice, first to delete a few entries synchronously to free inodes for mktemp -d and mv as well as the few other early things that need them, and then, as before, mv entries that are left into a directory we own that we can remove in the background. If something goes wrong and the mktemp still fails, for example all inodes live in one of the skipped directories, then it is up to the system administrator to set things right. I tested this and the early rm removes the expected number of entries without removing things inside vi.recover as well continuing to clear the excess in the background. Index: rc =================================================================== RCS file: /cvs/src/etc/rc,v diff -u -p -r1.590 rc --- rc 17 Aug 2026 22:41:38 -0000 1.590 +++ rc 27 Aug 2026 01:25:03 -0000 @@ -502,6 +502,24 @@ sysctl_conf mount -s /var >/dev/null 2>&1 # cannot be on NFS mount -s /var/log >/dev/null 2>&1 # cannot be on NFS mount -s /usr >/dev/null 2>&1 # if NFS, fstab must use IP address +mount -s /tmp >/dev/null 2>&1 # if NFS, fstab must use IP address + +# Prune /tmp before users can authenticate. A few files are removed +# immediately, but most of the deletion happens asynchronously while +# daemons are being started +( cd /tmp && { + echo clearing /tmp + skip="-mindepth 1 -maxdepth 1 ! -name lost+found ! -name quota.user + ! -name quota.group ! -name vi.recover" + find . $skip ! -perm -1000 -print0 | + xargs -r0J % find -d % -exec rm -rf -- {} \; -print | + head -50 >/dev/null 2>&1 + tmpdir=$(mktemp -d .delXXXXXXXXXX) && { + find . $skip ! -name "$tmpdir" -print0 | + xargs -r0J % mv -f -- % "$tmpdir" + rm -rf -- "$tmpdir" & + } +} ) reorder_libs 2>&1 |& @@ -597,26 +615,6 @@ if [[ -f /etc/ptmp ]]; then 'password file may be incorrect -- /etc/ptmp exists' fi -echo clearing /tmp - -# Prune /tmp before users can authenticate. A few files are removed -# immediately, but most of the deletion happens asyncronously while -# daemons are being started -clear_tmp_dir=$(cd /tmp && { - rm -rf .{X11,ICE}-unix - - set -- rm -rf - TMPDIR=$(mktemp -d /tmp/.delXXXXXXXXXX) && export TMPDIR && - set -- sh -c 'mv -f -- "$@" "$TMPDIR"' - find . -maxdepth 1 ! -name . ! -name lost+found ! -name quota.user \ - ! -name quota.group ! -name vi.recover ! -name "$(basename "$TMPDIR")" \ - -exec "$@" -- {} \+ - rm -rfv "$TMPDIR" 2>&1 | head -20 >/dev/null - echo "$TMPDIR" -} ) -rm -rf "$clear_tmp_dir" & -clear_tmp_pid=$! - # Create Unix sockets directories for X if needed and make sure they have # correct permissions. [[ -d /usr/X11R6/lib ]] && mkdir -m 1777 /tmp/.{X11,ICE}-unix @@ -666,8 +664,6 @@ start_daemon dhcp6leased rad hostapd lpd start_daemon ftpproxy ftpproxy6 tftpd tftpproxy identd inetd rarpd bootparamd start_daemon rbootd mopd vmd spamd spamlogd sndiod echo '.' - -wait $clear_tmp_pid # If rc.firsttime exists, run it just once, and make sure it is deleted. run_upgrade_script firsttime