1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

tmpfiles: use an enum instead of plain char for item type

For better safety. gcc can warn about missing values in switch statements.
This commit is contained in:
Michal Schmidt 2011-12-15 21:31:14 +01:00
parent c971700e41
commit 66ccd0387e

View File

@ -50,7 +50,7 @@
* properly owned directories beneath /tmp, /var/tmp, /run, which are * properly owned directories beneath /tmp, /var/tmp, /run, which are
* volatile and hence need to be recreated on bootup. */ * volatile and hence need to be recreated on bootup. */
enum { typedef enum ItemType {
/* These ones take file names */ /* These ones take file names */
CREATE_FILE = 'f', CREATE_FILE = 'f',
TRUNCATE_FILE = 'F', TRUNCATE_FILE = 'F',
@ -62,10 +62,10 @@ enum {
IGNORE_PATH = 'x', IGNORE_PATH = 'x',
REMOVE_PATH = 'r', REMOVE_PATH = 'r',
RECURSIVE_REMOVE_PATH = 'R' RECURSIVE_REMOVE_PATH = 'R'
}; } ItemType;
typedef struct Item { typedef struct Item {
char type; ItemType type;
char *path; char *path;
uid_t uid; uid_t uid;
@ -90,7 +90,7 @@ static const char *arg_prefix = NULL;
#define MAX_DEPTH 256 #define MAX_DEPTH 256
static bool needs_glob(int t) { static bool needs_glob(ItemType t) {
return t == IGNORE_PATH || t == REMOVE_PATH || t == RECURSIVE_REMOVE_PATH; return t == IGNORE_PATH || t == REMOVE_PATH || t == RECURSIVE_REMOVE_PATH;
} }
@ -701,6 +701,7 @@ static bool item_equal(Item *a, Item *b) {
static int parse_line(const char *fname, unsigned line, const char *buffer) { static int parse_line(const char *fname, unsigned line, const char *buffer) {
Item *i, *existing; Item *i, *existing;
char *mode = NULL, *user = NULL, *group = NULL, *age = NULL; char *mode = NULL, *user = NULL, *group = NULL, *age = NULL;
char type;
Hashmap *h; Hashmap *h;
int r; int r;
@ -720,7 +721,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
"%ms " "%ms "
"%ms " "%ms "
"%ms", "%ms",
&i->type, &type,
&i->path, &i->path,
&mode, &mode,
&user, &user,
@ -730,6 +731,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
r = -EIO; r = -EIO;
goto finish; goto finish;
} }
i->type = type;
if (i->type != CREATE_FILE && if (i->type != CREATE_FILE &&
i->type != TRUNCATE_FILE && i->type != TRUNCATE_FILE &&