util: promote rmrf() from tmpfiles.c, fix silent mksubsys() skip

rmrf() is needed outside tmpfiles.c.  The move also deduplicates the
nftw callback: the contents-only removal used by tmpfiles 'D' entries
is now rmcontents(), sharing the callback with rmrf().

mksubsys() did nothing at all when the user could not be resolved, no
directory and no message, and callers had no way to tell.  Now the
directory is always created, ownership is best effort, and an unknown
user is warned about.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-07-30 15:23:37 +02:00
1 parent 6615a248ee
commit 7f8a64dd39
3 files changed
+46 -34

No files matched your search

+1 -30
View File
@@ -130,33 +130,6 @@ static int parse_mm(char *arg, int *major, int *minor)
return 0;
}
static int do_delete(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftw)
{
(void)sb;
(void)tflag;
if (ftw->level == 0)
return 1;
if (remove(fpath) && errno != EBUSY)
warn("Failed removing %s", fpath);
return 0;
}
static int rmrf(const char *path)
{
if (!fisdir(path))
return 0;
nftw(path, do_delete, 20, FTW_DEPTH | FTW_PHYS);
if (remove(path) && errno != ENOENT)
warn("Failed removing path %s", path);
return 0;
}
static void mkparent(char *path, mode_t mode)
{
mkpath(dirname(strdupa(path)), mode);
@@ -465,9 +438,7 @@ static void tmpfiles(char *line)
case 'd':
break;
case 'D':
if (fisdir(path)) {
nftw(path, do_delete, 20, FTW_DEPTH | FTW_PHYS);
}
rmcontents(path);
break;
case 'e':
case 'f':