From 5191d68bb76129cb2a95c62ea18d2ef9ae6605f2 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 5 Jul 2023 10:42:03 -0700 Subject: setup: separate res_setup setup_func call This is just temporary until all the setup_funcs always return a res_setting on -EINVAL. Currently they only cover this requirement when res_setup is NULL... --- src/setup.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/setup.c b/src/setup.c index cf39f08..131c856 100644 --- a/src/setup.c +++ b/src/setup.c @@ -21,7 +21,12 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(const til_se /* TODO: regex and error handling */ - while ((r = setup_func(settings, &setting, &desc, res_setup)) > 0) { + /* until all the setup_funcs guarantee they return the failed setting on -EINVAL w/non-NULL res_setup (finalizing), + * this will be done in two steps; this first loop just constructs the settings heirarchy, and if it fails with + * -EINVAL we will use the setting for logging. Then after this loop, one last recurrence of setup_func() w/res_setup + * actually set. Once all setup_funcs behave well even in res_setup we'll go back to just the loop on setup_func(). + */ + while ((r = setup_func(settings, &setting, &desc, NULL)) > 0) { assert(desc); additions++; @@ -170,5 +175,14 @@ _next: til_setting_desc_free(desc); } + if (r < 0) { + if (r == -EINVAL) + *res_failed_desc = setting->desc; + + return r; + } + + r = setup_func(settings, &setting, &desc, res_setup); + return r < 0 ? r : additions; } -- cgit v1.2.3