Score:2

Why are tmp files in /var/tmp/systemd-private-* excluded from automatic deletion?

in flag
DMJ

I'm running a CGI application on an Apache instance, and lately I've been noticing errors like the following, which appear to be causing some issues:

ERR012: Unable to create temporary file "/var/tmp/023711.000001.tmp": File exists

(This is the application in question, in case it's relevant: HTMLDOC)

Upon investigating the issue, I found that /var/tmp/systemd-private-*-httpd.service-*/ is filled with tens of thousands of tmp files, some nearly a year old, most of which seem to be PDFs generated by the application.

Since tmp files should be deleted automatically, I spent some time researching how tmp file deletion works. The systemd-tmpfiles-clean server appears to be running nightly:

[xxx@yyy~]$ systemctl status systemd-tmpfiles-clean
● systemd-tmpfiles-clean.service - Cleanup of Temporary Directories
   Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-clean.service; static; vendor preset: disabled)
   Active: inactive (dead) since Thu 2023-03-23 23:25:48 UTC; 17h ago
     Docs: man:tmpfiles.d(5)
           man:systemd-tmpfiles(8)
  Process: 32584 ExecStart=/usr/bin/systemd-tmpfiles --clean (code=exited, status=0/SUCCESS)
 Main PID: 32584 (code=exited, status=0/SUCCESS)

However, I did find this, which I think might be why that particular tmp folder isn't getting cleaned:

[xxx@yyy~]$ cat /usr/lib/tmpfiles.d/tmp.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d
v /var/tmp 1777 root root 30d

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp

It seems to me like deleting those last two lines would probably solve the issue. However, I assume they're there for some good reason I'm just not aware of, and I don't want to break the system. Obviously I could also just periodically delete the files manually, or set up a cron job to do it periodically as well.

However, my biggest question is: why are those specific tmp folder being excluded in the first place? Is there a reason I shouldn't be deleting those files? Why would there be tmp folders if the tmp files inside them are never deleted? Isn't the whole idea of tmp files that they should be safe to delete basically as soon as the application closes the file?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.