From ff95ebeb910ad826dc0e1296039446357e666e26 Mon Sep 17 00:00:00 2001 From: Aaron Andersen Date: Sun, 1 Jun 2025 18:54:54 -0400 Subject: [PATCH] tmpfiles: split up create & remove logic The tmpfiles.d spec contains entry types that should be acted upon in different modes of operation: create, clean, remove, and purge - split up create & remove logic to clarify the modes of operation finit supports. --- src/tmpfiles.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/tmpfiles.c b/src/tmpfiles.c index 62e7d97d..a6de512d 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -315,6 +315,43 @@ static void tmpfiles(char *line) strc = stat(path, &st); + // file and directory removal logic + switch (type[0]) { + case 'b': + case 'c': + case 'C': + case 'd': + case 'D': + case 'e': + case 'f': + case 'F': + case 'l': /* Finit extension, like 'L' but only if target exists */ + case 'L': + case 'p': + break; + case 'r': + rc = glob_do(path, erase); + if (rc && errno == ENOENT) + rc = 0; + break; + case 'R': + rc = glob_do(path, rmrf); + break; + case 'w': + break; + case 'X': + case 'x': + dbg("Unsupported x/X command, ignoring %s, no support for clean at runtime.", path); + break; + case 'Z': + case 'z': + break; + default: + errx(1, "Unsupported tmpfiles command '%s'", type); + return; + } + + // file & directory creation logic switch (type[0]) { case 'b': rc = parse_mm(arg, &major, &minor); @@ -448,12 +485,7 @@ static void tmpfiles(char *line) rc = mkfifo(path, mode ?: 0644); break; case 'r': - rc = glob_do(path, erase); - if (rc && errno == ENOENT) - rc = 0; - break; case 'R': - rc = glob_do(path, rmrf); break; case 'w': if (!arg)