conf-parser: make use of DEFINE_PARSER macro to parse mode_t

Let's unify more code.

Also, rework the macro to accept a trailing semicolon, to make the code
prettier.
This commit is contained in:
Lennart Poettering 2015-09-30 20:28:51 +02:00
parent e5aa2f71b7
commit 94d75d6423

View file

@ -415,16 +415,17 @@ int config_parse_many(const char *conf_file,
} }
#define DEFINE_PARSER(type, vartype, conv_func) \ #define DEFINE_PARSER(type, vartype, conv_func) \
int config_parse_##type(const char *unit, \ int config_parse_##type( \
const char *filename, \ const char *unit, \
unsigned line, \ const char *filename, \
const char *section, \ unsigned line, \
unsigned section_line, \ const char *section, \
const char *lvalue, \ unsigned section_line, \
int ltype, \ const char *lvalue, \
const char *rvalue, \ int ltype, \
void *data, \ const char *rvalue, \
void *userdata) { \ void *data, \
void *userdata) { \
\ \
vartype *i = data; \ vartype *i = data; \
int r; \ int r; \
@ -441,16 +442,18 @@ int config_parse_many(const char *conf_file,
#type, rvalue); \ #type, rvalue); \
\ \
return 0; \ return 0; \
} } \
struct __useless_struct_to_allow_trailing_semicolon__
DEFINE_PARSER(int, int, safe_atoi) DEFINE_PARSER(int, int, safe_atoi);
DEFINE_PARSER(long, long, safe_atoli) DEFINE_PARSER(long, long, safe_atoli);
DEFINE_PARSER(uint32, uint32_t, safe_atou32) DEFINE_PARSER(uint32, uint32_t, safe_atou32);
DEFINE_PARSER(uint64, uint64_t, safe_atou64) DEFINE_PARSER(uint64, uint64_t, safe_atou64);
DEFINE_PARSER(unsigned, unsigned, safe_atou) DEFINE_PARSER(unsigned, unsigned, safe_atou);
DEFINE_PARSER(double, double, safe_atod) DEFINE_PARSER(double, double, safe_atod);
DEFINE_PARSER(nsec, nsec_t, parse_nsec) DEFINE_PARSER(nsec, nsec_t, parse_nsec);
DEFINE_PARSER(sec, usec_t, parse_sec) DEFINE_PARSER(sec, usec_t, parse_sec);
DEFINE_PARSER(mode, mode_t, parse_mode);
int config_parse_iec_size(const char* unit, int config_parse_iec_size(const char* unit,
const char *filename, const char *filename,
@ -739,35 +742,6 @@ int config_parse_strv(const char *unit,
return 0; return 0;
} }
int config_parse_mode(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
mode_t *m = data;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
r = parse_mode(rvalue, m);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse mode value, ignoring: %s", rvalue);
return 0;
}
return 0;
}
int config_parse_log_facility( int config_parse_log_facility(
const char *unit, const char *unit,
const char *filename, const char *filename,