chiark / gitweb /
namespace: include boot id in private tmp directories
authorLennart Poettering <lennart@poettering.net>
Fri, 13 Dec 2013 01:05:04 +0000 (02:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 13 Dec 2013 03:06:43 +0000 (04:06 +0100)
This way it is easy to only exclude directories from the current boot
from automatic clean up in /var/tmp.

Also, pick a longer name for the directories so that are globs in
tmp.conf can be simpler yet equally accurate.

src/core/namespace.c
src/test/test-namespace.c
tmpfiles.d/tmp.conf

index 926ff71..85147be 100644 (file)
@@ -278,12 +278,22 @@ fail:
 
 static int setup_one_tmp_dir(const char *id, const char *prefix, char **path) {
         _cleanup_free_ char *x = NULL;
+        char bid[SD_ID128_STRING_MAX];
+        sd_id128_t boot_id;
+        int r;
 
         assert(id);
         assert(prefix);
         assert(path);
 
-        x = strjoin(prefix, "/systemd-", id, "-XXXXXX", NULL);
+        /* We include the boot id in the directory so that after a
+         * reboot we can easily identify obsolete directories. */
+
+        r = sd_id128_get_boot(&boot_id);
+        if (r < 0)
+                return r;
+
+        x = strjoin(prefix, "/systemd-private-", sd_id128_to_string(boot_id, bid), "-", id, "-XXXXXX", NULL);
         if (!x)
                 return -ENOMEM;
 
index 6454a1b..5b76b9e 100644 (file)
@@ -119,13 +119,25 @@ static void test_netns(void) {
 }
 
 int main(int argc, char *argv[]) {
-        test_tmpdir("abcd.service",
-                    "/tmp/systemd-abcd.service-",
-                    "/var/tmp/systemd-abcd.service-");
+        sd_id128_t bid;
+        char boot_id[SD_ID128_STRING_MAX];
+        _cleanup_free_ char *x = NULL, *y = NULL, *z = NULL, *zz = NULL;
 
-        test_tmpdir("sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device",
-                    "/tmp/systemd-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-",
-                    "/var/tmp/systemd-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
+        assert_se(sd_id128_get_boot(&bid) >= 0);
+        sd_id128_to_string(bid, boot_id);
+
+        x = strjoin("/tmp/systemd-private-", boot_id, "-abcd.service-", NULL);
+        y = strjoin("/var/tmp/systemd-private-", boot_id, "-abcd.service-", NULL);
+        assert_se(x && y);
+
+        test_tmpdir("abcd.service", x, y);
+
+        z = strjoin("/tmp/systemd-private-", boot_id, "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-", NULL);
+        zz = strjoin("/var/tmp/systemd-private-", boot_id, "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-", NULL);
+
+        assert_se(z && zz);
+
+        test_tmpdir("sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device", z, zz);
 
         test_netns();
 
index f0312ef..b80dab4 100644 (file)
@@ -12,24 +12,7 @@ d /tmp 1777 root root 10d
 d /var/tmp 1777 root root 30d
 
 # Exclude namespace mountpoints created with PrivateTmp=yes
-x /tmp/systemd-*.service-*
-x /var/tmp/systemd-*.service-*
-X /tmp/systemd-*.service-*/tmp
-X /var/tmp/systemd-*.service-*/tmp
-x /tmp/systemd-*.socket-*
-x /var/tmp/systemd-*.socket-*
-X /tmp/systemd-*.socket-*/tmp
-X /var/tmp/systemd-*.socket-*/tmp
-x /tmp/systemd-*.mount-*
-x /var/tmp/systemd-*.mount-*
-X /tmp/systemd-*.mount-*/tmp
-X /var/tmp/systemd-*.mount-*/tmp
-x /tmp/systemd-*.swap-*
-x /var/tmp/systemd-*.swap-*
-X /tmp/systemd-*.swap-*/tmp
-X /var/tmp/systemd-*.swap-*/tmp
-# keep those for compatibility during upgrades
-x /tmp/systemd-private-*
-x /var/tmp/systemd-private-*
-X /tmp/systemd-private-*/tmp
-X /var/tmp/systemd-private-*/tmp
+x /tmp/systemd-private-%b-*
+X /tmp/systemd-private-%b-*/tmp
+x /var/tmp/systemd-private-%b-*
+X /var/tmp/systemd-private-%b-*/tmp