mirror of
https://github.com/pygos/init.git
synced 2024-11-21 10:49:46 +01:00
Cleanup: remove flag mechanism from config parser entirely
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
70ea16b0b4
commit
5307b95b93
3 changed files with 15 additions and 24 deletions
|
@ -27,7 +27,7 @@ typedef struct {
|
|||
*/
|
||||
unsigned int allow_block : 1;
|
||||
|
||||
int (*handle)(void *obj, char *arg, rdline_t *rd, int flags);
|
||||
int (*handle)(void *obj, char *arg, rdline_t *rd);
|
||||
} cfg_param_t;
|
||||
|
||||
/*
|
||||
|
@ -92,11 +92,10 @@ int pack_argv(char *str);
|
|||
|
||||
/*
|
||||
Parse a configuration file containing '<keyword> [arguments...]' lines.
|
||||
The cfgobj and flags are passed to the callback in the params array.
|
||||
The cfgobj is passed to the callback in the params array.
|
||||
|
||||
Returns zero on success.
|
||||
*/
|
||||
int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count,
|
||||
int flags);
|
||||
int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count);
|
||||
|
||||
#endif /* LIBCONFIG_H */
|
||||
|
|
|
@ -43,10 +43,9 @@ static int try_pack_argv(char *str, rdline_t *rd)
|
|||
return count;
|
||||
}
|
||||
|
||||
static int svc_desc(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_desc(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
(void)flags;
|
||||
|
||||
if (try_unescape(arg, rd))
|
||||
return -1;
|
||||
|
@ -54,10 +53,9 @@ static int svc_desc(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return svc->desc == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
static int svc_tty(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_tty(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
(void)flags;
|
||||
|
||||
if (strncmp(arg, "truncate", 8) == 0 && isspace(arg[8])) {
|
||||
svc->flags |= SVC_FLAG_TRUNCATE_OUT;
|
||||
|
@ -73,11 +71,10 @@ static int svc_tty(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return svc->ctty == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
static int svc_exec(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_exec(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
exec_t *e, *end;
|
||||
(void)flags;
|
||||
|
||||
svc->flags |= SVC_FLAG_HAS_EXEC;
|
||||
|
||||
|
@ -104,10 +101,9 @@ static int svc_exec(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int svc_before(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_before(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
(void)flags;
|
||||
|
||||
if (svc->before != NULL) {
|
||||
fprintf(stderr, "%s: %zu: 'before' dependencies respecified\n",
|
||||
|
@ -123,10 +119,9 @@ static int svc_before(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return (svc->num_before < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
static int svc_after(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_after(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
(void)flags;
|
||||
|
||||
if (svc->after != NULL) {
|
||||
fprintf(stderr, "%s: %zu: 'after' dependencies respecified\n",
|
||||
|
@ -142,11 +137,10 @@ static int svc_after(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return (svc->num_after < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
static int svc_type(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_type(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
int count = try_pack_argv(arg, rd);
|
||||
(void)flags;
|
||||
|
||||
if (count < 1)
|
||||
return -1;
|
||||
|
@ -190,11 +184,10 @@ fail_limit:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int svc_target(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_target(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
int target;
|
||||
(void)flags;
|
||||
|
||||
if (try_unescape(arg, rd))
|
||||
return -1;
|
||||
|
@ -253,7 +246,7 @@ service_t *rdsvc(int dirfd, const char *filename)
|
|||
svc->id = -1;
|
||||
|
||||
if (rdcfg(svc, &rd, svc_params,
|
||||
sizeof(svc_params) / sizeof(svc_params[0]), 0)) {
|
||||
sizeof(svc_params) / sizeof(svc_params[0]))) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,7 @@ static int splitkv(rdline_t *rd, char **k, char **v)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count,
|
||||
int flags)
|
||||
int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count)
|
||||
{
|
||||
const cfg_param_t *p;
|
||||
char *key, *value;
|
||||
|
@ -67,7 +66,7 @@ int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count,
|
|||
;
|
||||
|
||||
if (*value != '\0') {
|
||||
ret = p->handle(cfgobj, value, rd, flags);
|
||||
ret = p->handle(cfgobj, value, rd);
|
||||
if (ret)
|
||||
return -1;
|
||||
}
|
||||
|
@ -75,7 +74,7 @@ int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count,
|
|||
while ((ret = rdline(rd)) == 0) {
|
||||
if (strcmp(rd->line, "}") == 0)
|
||||
break;
|
||||
if (p->handle(cfgobj, rd->line, rd, flags))
|
||||
if (p->handle(cfgobj, rd->line, rd))
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -83,7 +82,7 @@ int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count,
|
|||
return -1;
|
||||
if (ret > 0)
|
||||
goto fail_bra;
|
||||
} else if (p->handle(cfgobj, value, rd, flags)) {
|
||||
} else if (p->handle(cfgobj, value, rd)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue