tmpfiles: refactor into separate executable

The tmpfiles.d spec has proven useful in systemd, enough so that some developers
are starting to ship tmpfiles.d configuration files with their software.
By splitting the tmpfiles functionality in finit out into a separate executable
we are providing a useful piece of software that package managers can hook into.
This commit is contained in:
Aaron Andersen
2025-06-02 19:27:24 -04:00
parent d318aa00c3
commit 1921b3f2c5
5 changed files with 49 additions and 49 deletions
+1 -2
View File
@@ -38,7 +38,6 @@
#include "finit.h"
#include "helpers.h"
#include "plugin.h"
#include "tmpfiles.h"
#include "util.h"
#include "utmp-api.h"
@@ -163,7 +162,7 @@ static void setup(void *arg)
kernel_links();
/* Create all system tmpfiles.d(5) */
tmpfilesd();
run_interactive(_PATH_TMPFILES, "Creating required directories and files");
/* Set BOOT_TIME UTMP entry */
utmp_set_boot();
+8 -2
View File
@@ -8,7 +8,7 @@ AM_LDFLAGS = -export-dynamic
endif
sbin_PROGRAMS = finit initctl
pkglibexec_PROGRAMS = getty logit runparts
pkglibexec_PROGRAMS = getty logit runparts tmpfiles
if SULOGIN
pkglibexec_PROGRAMS += sulogin
endif
@@ -43,6 +43,13 @@ sulogin_SOURCES = sulogin.c
sulogin_CFLAGS = -W -Wall -Wextra -std=gnu99
sulogin_LDADD = -lcrypt
tmpfiles_SOURCES = tmpfiles.c helpers.c util.c exec.c log.c \
svc.c sig.c sm.c api.c mount.c service.c schedule.c cond.c cond-w.c pid.c plugin.c \
utmp-api.c client.c cgroup.c mdadm.c tty.c iwatch.c conf.c devmon.c logrotate.c
tmpfiles_CFLAGS = -W -Wall -Wextra -std=gnu99 -D__FINIT__
tmpfiles_CFLAGS += $(lite_CFLAGS) $(uev_CFLAGS)
tmpfiles_LDADD = $(lite_LIBS) $(uev_LIBS)
logit_SOURCES = logit.c logrotate.c
logit_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
logit_CFLAGS += $(lite_CFLAGS)
@@ -66,7 +73,6 @@ finit_SOURCES = api.c cgroup.c cgroup.h \
sig.c sig.h \
sm.c sm.h \
svc.c svc.h \
tmpfiles.c tmpfiles.h \
tty.c tty.h \
util.c util.h \
utmp-api.c utmp-api.h
+1
View File
@@ -59,6 +59,7 @@
#define _PATH_RUNPARTS FINIT_EXECPATH_ "/runparts"
#define _PATH_SULOGIN FINIT_EXECPATH_ "/sulogin"
#define _PATH_GETTY FINIT_EXECPATH_ "/getty"
#define _PATH_TMPFILES FINIT_EXECPATH_ "/tmpfiles"
#define CMD_SIZE 1024
#define LINE_SIZE 1024
+39 -3
View File
@@ -23,12 +23,48 @@
#include "config.h" /* Generated by configure script */
#include <dirent.h>
#include <ftw.h>
#include <glob.h>
#include <libgen.h>
#include <grp.h>
#include <pwd.h>
#include <sys/sysmacros.h>
#include "finit.h"
#include <stdlib.h>
#include <string.h>
#ifdef _LIBITE_LITE
# include <libite/lite.h>
#else
# include <lite/lite.h>
#endif
#include "svc.h"
#include "helpers.h"
#include "tmpfiles.h"
#include "log.h"
#include "util.h"
int debug;
int runlevel;
char *osheading;
svc_t *wdog;
uev_ctx_t *ctx;
int syncsec;
int rescue;
char *network;
int cfglevel;
char *finit_rcsd;
char *sdown;
char *hostname;
int bootstrap;
int single;
int readiness;
char *finit_conf;
char *fstab;
int prevlevel;
int cmdlevel;
int kerndebug;
static int glob_do(const char *path, int (*cb)(const char *))
{
int rc = 0;
@@ -470,7 +506,7 @@ static void tmpfiles(char *line)
* before that to have Finit specific ones sorted first, and
* a configure prefix specific one after that for user needs.
*/
void tmpfilesd(void)
int main(int argc, char *argv[])
{
/* in priority order */
char *dir[] = {
-42
View File
@@ -1,42 +0,0 @@
/* Limited tmpfiles.d implementation
*
* Copyright (c) 2024 Joachim Wiberg <troglobit@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef TMPFILES_H_
#define TMPFILES_H_
#include <dirent.h>
#include <ftw.h>
#include <glob.h>
#include <libgen.h>
#include <stdlib.h>
#include <string.h>
#ifdef _LIBITE_LITE
# include <libite/lite.h>
#else
# include <lite/lite.h>
#endif
void tmpfilesd(void);
#endif /* TMPFILES_H_ */