mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
tmpfiles: run boot-only entries only at boot
A ! after the type marks an entry that is only safe to run at boot.
Finit's own files have them, like this one in x11.conf:
D! /tmp/.X11-unix 1777 root root
tmpfiles ignored the ! and ran these entries on every call, so this
emptied the directory under a running X server:
tmpfiles --remove
Only the character right after the type was looked at, and only for
a +.
Read all the modifiers after the type, in any order, and skip an
entry with ! unless the new --boot option is given. Finit gives it
at boot, together with --remove. Before this the r, R, and D entries
were never run at boot, so "r! /forcefsck" in legacy.conf left the
file in place.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
7 files changed
+108
-34
No files matched your search
+25
-7
@@ -55,6 +55,7 @@ int debug;
|
||||
int create_flag = 0;
|
||||
int clean_flag = 0;
|
||||
int remove_flag = 0;
|
||||
int boot_flag = 0;
|
||||
|
||||
/* Set for the first of two passes, the second one does the complaining */
|
||||
static int quiet;
|
||||
@@ -717,6 +718,7 @@ static void tmpfiles(char *line)
|
||||
struct stat st, ast;
|
||||
int major, minor;
|
||||
int strc, rc = 0;
|
||||
int plus = 0, boot = 0;
|
||||
mode_t mode = 0;
|
||||
FILE *fp = NULL;
|
||||
char buf[1024];
|
||||
@@ -726,6 +728,15 @@ static void tmpfiles(char *line)
|
||||
if (!type)
|
||||
return;
|
||||
|
||||
for (char *mod = &type[1]; *mod; mod++) {
|
||||
if (*mod == '+')
|
||||
plus = 1;
|
||||
else if (*mod == '!')
|
||||
boot = 1;
|
||||
}
|
||||
if (boot && !boot_flag)
|
||||
return;
|
||||
|
||||
path = strtok(NULL, "\t ");
|
||||
if (!path)
|
||||
return;
|
||||
@@ -837,14 +848,14 @@ static void tmpfiles(char *line)
|
||||
switch (type[0]) {
|
||||
case 'a':
|
||||
case 'A':
|
||||
rc = acl_entry(path, arg, type[0] == 'A', type[1] == '+');
|
||||
rc = acl_entry(path, arg, type[0] == 'A', plus);
|
||||
break;
|
||||
case 'b':
|
||||
rc = parse_mm(arg, &major, &minor);
|
||||
if (rc)
|
||||
break;
|
||||
if (!strc) {
|
||||
if (type[1] != '+')
|
||||
if (!plus)
|
||||
break;
|
||||
erase(path);
|
||||
}
|
||||
@@ -856,7 +867,7 @@ static void tmpfiles(char *line)
|
||||
if (rc)
|
||||
break;
|
||||
if (!strc) {
|
||||
if (type[1] != '+')
|
||||
if (!plus)
|
||||
break;
|
||||
erase(path);
|
||||
}
|
||||
@@ -926,7 +937,7 @@ static void tmpfiles(char *line)
|
||||
int flags = O_WRONLY | O_CREAT | O_NOFOLLOW | O_CLOEXEC;
|
||||
int fd, uid, gid;
|
||||
|
||||
if (type[1] == '+' || type[0] == 'F') {
|
||||
if (plus || type[0] == 'F') {
|
||||
flags |= O_TRUNC; /* create or truncate */
|
||||
} else {
|
||||
if (!strc)
|
||||
@@ -980,7 +991,7 @@ static void tmpfiles(char *line)
|
||||
/* fallthrough */
|
||||
case 'L':
|
||||
if (!strc) {
|
||||
if (type[1] != '+')
|
||||
if (!plus)
|
||||
break;
|
||||
if (fisdir(path))
|
||||
rmrf(path);
|
||||
@@ -998,7 +1009,7 @@ static void tmpfiles(char *line)
|
||||
break;
|
||||
case 'p':
|
||||
if (!strc) {
|
||||
if (type[1] != '+')
|
||||
if (!plus)
|
||||
break;
|
||||
erase(path);
|
||||
}
|
||||
@@ -1016,7 +1027,7 @@ static void tmpfiles(char *line)
|
||||
break;
|
||||
|
||||
for (size_t i = 0; i < gl.gl_pathc; i++) {
|
||||
fp = fopen(gl.gl_pathv[i], type[1] == '+' ? "a" : "w");
|
||||
fp = fopen(gl.gl_pathv[i], plus ? "a" : "w");
|
||||
if (fp) {
|
||||
write_arg(fp, arg);
|
||||
rc = fclose(fp);
|
||||
@@ -1141,6 +1152,7 @@ static int usage(int rc)
|
||||
"Usage: tmpfiles [OPTIONS] [CONFIGFILE...]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" --boot Also run boot-only entries, marked with !\n"
|
||||
" -C, --clean Clean files and directories based on age\n"
|
||||
" -c, --create Create files and directories\n"
|
||||
" -d, --debug Show developer debug messages\n"
|
||||
@@ -1158,11 +1170,13 @@ static int usage(int rc)
|
||||
|
||||
enum {
|
||||
OPT_EXCLUDE_PREFIX = 256,
|
||||
OPT_BOOT,
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct option long_options[] = {
|
||||
{ "boot", 0, NULL, OPT_BOOT },
|
||||
{ "clean", 0, NULL, 'C' },
|
||||
{ "create", 0, NULL, 'c' },
|
||||
{ "debug", 0, NULL, 'd' },
|
||||
@@ -1195,6 +1209,10 @@ int main(int argc, char *argv[])
|
||||
add_exclude_prefix("/sys");
|
||||
break;
|
||||
|
||||
case OPT_BOOT:
|
||||
boot_flag = 1;
|
||||
break;
|
||||
|
||||
case OPT_EXCLUDE_PREFIX:
|
||||
add_exclude_prefix(optarg);
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user