systemd/systemd-add-user-keep.patch
2015-03-27 08:39:40 +00:00

86 lines
3.8 KiB
Diff

---
man/tmpfiles.d.xml | 3 +++
src/tmpfiles/tmpfiles.c | 48 ++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 43 insertions(+), 8 deletions(-)
Index: systemd/man/tmpfiles.d.xml
===================================================================
--- systemd.orig/man/tmpfiles.d.xml
+++ systemd/man/tmpfiles.d.xml
@@ -489,6 +489,9 @@
<varname>f</varname>, <varname>F</varname>, and
<varname>w</varname> may be used to specify a short string that
is written to the file, suffixed by a newline. For
+ <varname>x</varname>, <varname>X</varname>, a comma separated list of
+ usernames. If given, only paths belonging to these users will be excluded
+ during directory cleanup. Ignored for all other lines. For
<varname>C</varname>, specifies the source file or
directory. For <varname>t</varname> determines extended
attributes to be set. For <varname>a</varname> determines
Index: systemd/src/tmpfiles/tmpfiles.c
===================================================================
--- systemd.orig/src/tmpfiles/tmpfiles.c
+++ systemd/src/tmpfiles/tmpfiles.c
@@ -345,6 +345,7 @@ static int dir_cleanup(
struct timespec times[2];
bool deleted = false;
int r = 0;
+ Item *found = NULL;
while ((dent = readdir(d))) {
struct stat s;
@@ -395,14 +396,45 @@ static int dir_cleanup(
}
/* Is there an item configured for this path? */
- if (hashmap_get(items, sub_path)) {
- log_debug("Ignoring \"%s\": a separate entry exists.", sub_path);
- continue;
- }
-
- if (find_glob(globs, sub_path)) {
- log_debug("Ignoring \"%s\": a separate glob exists.", sub_path);
- continue;
+ bool found_glob = false;
+ found = hashmap_get(items, sub_path);
+ if (!found) {
+ found_glob = true;
+ found = find_glob(globs, sub_path);
+ }
+ if (found) {
+ struct passwd *pw;
+ char *userfound = NULL, *args;
+ bool match = false;
+ uid_t uid = -1;
+
+ /* evaluate username arguments in ignore statements */
+ if ((found->type != IGNORE_PATH && found->type != IGNORE_DIRECTORY_PATH) ||
+ !found->argument) {
+ if (found_glob)
+ log_debug("Ignoring \"%s\": a separate glob exists.", sub_path);
+ else
+ log_debug("Ignoring \"%s\": a separate entry exists.", sub_path);
+ continue;
+ }
+ args = strdup(found->argument);
+ assert_se(args != NULL);
+ while ((userfound = strsep(&args, ",")) != NULL) {
+ pw = getpwnam(userfound);
+ if (pw == NULL) {
+ log_error("Unknown user '%s' in ignore statement.", userfound);
+ continue;
+ }
+ uid = pw->pw_uid;
+ if (s.st_uid == uid) {
+ match = true;
+ break;
+ }
+ }
+ if (match) {
+ found = NULL;
+ continue;
+ }
}
if (S_ISDIR(s.st_mode)) {