summaryrefslogtreecommitdiffstats
path: root/src/tmpfiles
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-25 23:19:00 +0200
committerLennart Poettering <lennart@poettering.net>2018-11-08 09:52:16 +0100
commit1a967b6bb1f2f153f62908474ffce4873eaf59dc (patch)
treecc701804ee34e9eeaf7949d67541c00beda6bd88 /src/tmpfiles
parenttmpfiles: fix minor memory leak on error path (diff)
downloadsystemd-1a967b6bb1f2f153f62908474ffce4873eaf59dc.tar.xz
systemd-1a967b6bb1f2f153f62908474ffce4873eaf59dc.zip
tmpfiles: replace the three arg_create/arg_remove/arg_clean booleans with a single bitmask
No change in behaviour, just a bit of refactoring.
Diffstat (limited to 'src/tmpfiles')
-rw-r--r--src/tmpfiles/tmpfiles.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index cc5cbc382f..73e1271dad 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -65,6 +65,12 @@
* properly owned directories beneath /tmp, /var/tmp, /run, which are
* volatile and hence need to be recreated on bootup. */
+typedef enum OperationMask {
+ OPERATION_CREATE = 1 << 0,
+ OPERATION_REMOVE = 1 << 1,
+ OPERATION_CLEAN = 1 << 2,
+} OperationMask;
+
typedef enum ItemType {
/* These ones take file names */
CREATE_FILE = 'f',
@@ -149,9 +155,7 @@ typedef enum DirectoryType {
static bool arg_cat_config = false;
static bool arg_user = false;
-static bool arg_create = false;
-static bool arg_clean = false;
-static bool arg_remove = false;
+static OperationMask arg_operation = 0;
static bool arg_boot = false;
static bool arg_no_pager = false;
@@ -2272,13 +2276,14 @@ static int process_item(Item *i) {
if (chase_symlinks(i->path, NULL, CHASE_NO_AUTOFS, NULL) == -EREMOTE)
return t;
- r = arg_create ? create_item(i) : 0;
- q = arg_remove ? remove_item(i) : 0;
- p = arg_clean ? clean_item(i) : 0;
+ r = FLAGS_SET(arg_operation, OPERATION_CREATE) ? create_item(i) : 0;
/* Failure can only be tolerated for create */
if (i->allow_failure)
r = 0;
+ q = FLAGS_SET(arg_operation, OPERATION_REMOVE) ? remove_item(i) : 0;
+ p = FLAGS_SET(arg_operation, OPERATION_CLEAN) ? clean_item(i) : 0;
+
return t < 0 ? t :
r < 0 ? r :
q < 0 ? q :
@@ -2910,15 +2915,15 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_CREATE:
- arg_create = true;
+ arg_operation |= OPERATION_CREATE;
break;
case ARG_CLEAN:
- arg_clean = true;
+ arg_operation |= OPERATION_CLEAN;
break;
case ARG_REMOVE:
- arg_remove = true;
+ arg_operation |= OPERATION_REMOVE;
break;
case ARG_BOOT:
@@ -2962,7 +2967,7 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (!arg_clean && !arg_create && !arg_remove && !arg_cat_config) {
+ if (arg_operation == 0 && !arg_cat_config) {
log_error("You need to specify at least one of --clean, --create or --remove.");
return -EINVAL;
}