|
|
17b0f1 |
From f2d7881cf56b2d1448b9e09c46c076a14a05011d Mon Sep 17 00:00:00 2001
|
|
|
17b0f1 |
From: Jan Synacek <jsynacek@redhat.com>
|
|
|
17b0f1 |
Date: Tue, 11 Apr 2017 11:20:36 +0200
|
|
|
17b0f1 |
Subject: [PATCH] tmpfiles: add new 'e' action which cleans up a dir without
|
|
|
17b0f1 |
creating it
|
|
|
17b0f1 |
|
|
|
17b0f1 |
I wanted to add a config line that would empty a directory
|
|
|
17b0f1 |
without creating it if doesn't exist. Existing actions don't allow
|
|
|
17b0f1 |
this.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
v2: properly add 'e' to needs_glob() and takes_ownership()
|
|
|
17b0f1 |
|
|
|
17b0f1 |
(cherry picked from commit df8dee85da5fa41e95dd7f536e67fcc6940a6488)
|
|
|
17b0f1 |
Resolves: #1225739
|
|
|
17b0f1 |
---
|
|
|
17b0f1 |
man/tmpfiles.d.xml | 9 +++++++-
|
|
|
17b0f1 |
src/tmpfiles/tmpfiles.c | 51 ++++++++++++-----------------------------
|
|
|
17b0f1 |
2 files changed, 23 insertions(+), 37 deletions(-)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/man/tmpfiles.d.xml b/man/tmpfiles.d.xml
|
|
|
17b0f1 |
index fc1fe13aca..fc9db622e5 100644
|
|
|
17b0f1 |
--- a/man/tmpfiles.d.xml
|
|
|
17b0f1 |
+++ b/man/tmpfiles.d.xml
|
|
|
17b0f1 |
@@ -161,6 +161,13 @@
|
|
|
17b0f1 |
<listitem><para>Create or empty a directory.</para></listitem>
|
|
|
17b0f1 |
</varlistentry>
|
|
|
17b0f1 |
|
|
|
17b0f1 |
+ <varlistentry>
|
|
|
17b0f1 |
+ <term><varname>e</varname></term>
|
|
|
17b0f1 |
+ <listitem><para>Clean directory contents based on the age argument.
|
|
|
17b0f1 |
+ Lines of this type accept shell-style globs in
|
|
|
17b0f1 |
+ place of normal path names.</para></listitem>
|
|
|
17b0f1 |
+ </varlistentry>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
<varlistentry>
|
|
|
17b0f1 |
<term><varname>v</varname></term>
|
|
|
17b0f1 |
<listitem><para>Create a subvolume if the path does not
|
|
|
17b0f1 |
@@ -467,7 +474,7 @@
|
|
|
17b0f1 |
|
|
|
17b0f1 |
<para>The age field only applies to lines
|
|
|
17b0f1 |
starting with <varname>d</varname>,
|
|
|
17b0f1 |
- <varname>D</varname>, and
|
|
|
17b0f1 |
+ <varname>D</varname>, <varname>e</varname> and
|
|
|
17b0f1 |
<varname>x</varname>. If omitted or set to
|
|
|
17b0f1 |
<literal>-</literal>, no automatic clean-up is
|
|
|
17b0f1 |
done.</para>
|
|
|
17b0f1 |
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
|
|
|
17b0f1 |
index bda89df5be..df7676b572 100644
|
|
|
17b0f1 |
--- a/src/tmpfiles/tmpfiles.c
|
|
|
17b0f1 |
+++ b/src/tmpfiles/tmpfiles.c
|
|
|
17b0f1 |
@@ -79,6 +79,7 @@ typedef enum ItemType {
|
|
|
17b0f1 |
|
|
|
17b0f1 |
/* These ones take globs */
|
|
|
17b0f1 |
WRITE_FILE = 'w',
|
|
|
17b0f1 |
+ EMPTY_DIRECTORY = 'e',
|
|
|
17b0f1 |
SET_XATTR = 't',
|
|
|
17b0f1 |
RECURSIVE_SET_XATTR = 'T',
|
|
|
17b0f1 |
SET_ACL = 'a',
|
|
|
17b0f1 |
@@ -150,6 +151,7 @@ static bool needs_glob(ItemType t) {
|
|
|
17b0f1 |
IGNORE_PATH,
|
|
|
17b0f1 |
IGNORE_DIRECTORY_PATH,
|
|
|
17b0f1 |
REMOVE_PATH,
|
|
|
17b0f1 |
+ EMPTY_DIRECTORY,
|
|
|
17b0f1 |
RECURSIVE_REMOVE_PATH,
|
|
|
17b0f1 |
ADJUST_MODE,
|
|
|
17b0f1 |
RELABEL_PATH,
|
|
|
17b0f1 |
@@ -165,6 +167,7 @@ static bool takes_ownership(ItemType t) {
|
|
|
17b0f1 |
CREATE_FILE,
|
|
|
17b0f1 |
TRUNCATE_FILE,
|
|
|
17b0f1 |
CREATE_DIRECTORY,
|
|
|
17b0f1 |
+ EMPTY_DIRECTORY,
|
|
|
17b0f1 |
TRUNCATE_DIRECTORY,
|
|
|
17b0f1 |
CREATE_SUBVOLUME,
|
|
|
17b0f1 |
CREATE_FIFO,
|
|
|
17b0f1 |
@@ -1059,6 +1062,9 @@ static int create_item(Item *i) {
|
|
|
17b0f1 |
|
|
|
17b0f1 |
log_debug("%s directory \"%s\".", creation_mode_verb_to_string(creation), i->path);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
+ /* fall through */
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ case EMPTY_DIRECTORY:
|
|
|
17b0f1 |
r = path_set_perms(i, i->path);
|
|
|
17b0f1 |
if (r < 0)
|
|
|
17b0f1 |
return r;
|
|
|
17b0f1 |
@@ -1285,43 +1291,19 @@ static int remove_item_instance(Item *i, const char *instance) {
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int remove_item(Item *i) {
|
|
|
17b0f1 |
- int r = 0;
|
|
|
17b0f1 |
-
|
|
|
17b0f1 |
assert(i);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
log_debug("Running remove action for entry %c %s", (char) i->type, i->path);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
switch (i->type) {
|
|
|
17b0f1 |
-
|
|
|
17b0f1 |
- case CREATE_FILE:
|
|
|
17b0f1 |
- case TRUNCATE_FILE:
|
|
|
17b0f1 |
- case CREATE_DIRECTORY:
|
|
|
17b0f1 |
- case CREATE_SUBVOLUME:
|
|
|
17b0f1 |
- case CREATE_FIFO:
|
|
|
17b0f1 |
- case CREATE_SYMLINK:
|
|
|
17b0f1 |
- case CREATE_CHAR_DEVICE:
|
|
|
17b0f1 |
- case CREATE_BLOCK_DEVICE:
|
|
|
17b0f1 |
- case IGNORE_PATH:
|
|
|
17b0f1 |
- case IGNORE_DIRECTORY_PATH:
|
|
|
17b0f1 |
- case ADJUST_MODE:
|
|
|
17b0f1 |
- case RELABEL_PATH:
|
|
|
17b0f1 |
- case RECURSIVE_RELABEL_PATH:
|
|
|
17b0f1 |
- case WRITE_FILE:
|
|
|
17b0f1 |
- case COPY_FILES:
|
|
|
17b0f1 |
- case SET_XATTR:
|
|
|
17b0f1 |
- case RECURSIVE_SET_XATTR:
|
|
|
17b0f1 |
- case SET_ACL:
|
|
|
17b0f1 |
- case RECURSIVE_SET_ACL:
|
|
|
17b0f1 |
- break;
|
|
|
17b0f1 |
-
|
|
|
17b0f1 |
case REMOVE_PATH:
|
|
|
17b0f1 |
case TRUNCATE_DIRECTORY:
|
|
|
17b0f1 |
case RECURSIVE_REMOVE_PATH:
|
|
|
17b0f1 |
- r = glob_item(i, remove_item_instance, false);
|
|
|
17b0f1 |
- break;
|
|
|
17b0f1 |
- }
|
|
|
17b0f1 |
+ return glob_item(i, remove_item_instance, false);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- return r;
|
|
|
17b0f1 |
+ default:
|
|
|
17b0f1 |
+ return 0;
|
|
|
17b0f1 |
+ }
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int clean_item_instance(Item *i, const char* instance) {
|
|
|
17b0f1 |
@@ -1377,8 +1359,6 @@ static int clean_item_instance(Item *i, const char* instance) {
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int clean_item(Item *i) {
|
|
|
17b0f1 |
- int r = 0;
|
|
|
17b0f1 |
-
|
|
|
17b0f1 |
assert(i);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
log_debug("Running clean action for entry %c %s", (char) i->type, i->path);
|
|
|
17b0f1 |
@@ -1386,19 +1366,17 @@ static int clean_item(Item *i) {
|
|
|
17b0f1 |
switch (i->type) {
|
|
|
17b0f1 |
case CREATE_DIRECTORY:
|
|
|
17b0f1 |
case CREATE_SUBVOLUME:
|
|
|
17b0f1 |
+ case EMPTY_DIRECTORY:
|
|
|
17b0f1 |
case TRUNCATE_DIRECTORY:
|
|
|
17b0f1 |
case IGNORE_PATH:
|
|
|
17b0f1 |
case COPY_FILES:
|
|
|
17b0f1 |
clean_item_instance(i, i->path);
|
|
|
17b0f1 |
- break;
|
|
|
17b0f1 |
+ return 0;
|
|
|
17b0f1 |
case IGNORE_DIRECTORY_PATH:
|
|
|
17b0f1 |
- r = glob_item(i, clean_item_instance, false);
|
|
|
17b0f1 |
- break;
|
|
|
17b0f1 |
+ return glob_item(i, clean_item_instance, false);
|
|
|
17b0f1 |
default:
|
|
|
17b0f1 |
- break;
|
|
|
17b0f1 |
+ return 0;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
-
|
|
|
17b0f1 |
- return r;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int process_item_array(ItemArray *array);
|
|
|
17b0f1 |
@@ -1642,6 +1620,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
|
|
|
17b0f1 |
case TRUNCATE_FILE:
|
|
|
17b0f1 |
case CREATE_DIRECTORY:
|
|
|
17b0f1 |
case CREATE_SUBVOLUME:
|
|
|
17b0f1 |
+ case EMPTY_DIRECTORY:
|
|
|
17b0f1 |
case TRUNCATE_DIRECTORY:
|
|
|
17b0f1 |
case CREATE_FIFO:
|
|
|
17b0f1 |
case IGNORE_PATH:
|