]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rm-rf: fix up chmod in the _cleanup_ rm_rf() destructors
authorLennart Poettering <lennart@poettering.net>
Thu, 4 Mar 2021 15:03:07 +0000 (16:03 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 4 Mar 2021 20:50:07 +0000 (20:50 +0000)
REMOVE_CHMOD is necessary to remove files/dirs that are owned by us but
have an access mode that would not allow us to remove them. In generic
destructor calls for use with `_cleanup_` that are "fire-and-forget"
style we should make use of that, to maximize the chance we can actually
remove the files/dirs.

(Also, add in REMOVE_MISSING_OK. Just because prettier, we ignore the
return codes anyway, but it' a bit nicer to ignore a bit fewer errors.)

src/basic/rm-rf.h

index 6483b30d7e0cfeb45d4d90fe1f3116ae0104bf17..d954146a2ebdef7fc3eeaa4c7ce9e8ed1eec5c9a 100644 (file)
@@ -24,7 +24,7 @@ static inline char *rm_rf_physical_and_free(char *p) {
         if (!p)
                 return NULL;
 
-        (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
+        (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_MISSING_OK|REMOVE_CHMOD);
         free(p);
         return NULL;
 }
@@ -37,7 +37,7 @@ static inline char *rm_rf_subvolume_and_free(char *p) {
         if (!p)
                 return NULL;
 
-        (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
+        (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME|REMOVE_MISSING_OK|REMOVE_CHMOD);
         free(p);
         return NULL;
 }