Skip to content

Commit 3fd4e33

Browse files
committed
lib: Make parameter of ebg_env_getglobalstate obsolete
ebg_env_getglobalstate neither used nor needs a concrete environment for retrieving the effective state over all envs. The passed parameter has always been ignored and was probably only introduced to have a consistent signature compared to ebg_env_setglobalstate or other functions. At the same time, opening and closing an env via ebg_env_open_current and ebg_env_close is unfortunately not side-effect free which can cause surprises to users, see e.g. [1]. It is therefore better to avoid any needless opening of envs by officially declaring the parameter as reserved, just asking the user to pass NULL from now on. We do not want to change our API for existing users, though, and therefore do not enforce the parameter to be actually NULL. Thus, users can continue to pass valid envs as well. However, we now need to make sure that bgenv_init is also called from ebg_env_getglobalstate as this is otherwise done by ebg_env_create_new or ebg_env_open_current. [1] https://groups.google.com/g/efibootguard-dev/c/hAFE-LQ5cvc Signed-off-by: Jan Kiszka <[email protected]>
1 parent 4520209 commit 3fd4e33

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

env/env_api.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,16 @@ uint32_t ebg_env_user_free(ebgenv_t *e)
176176
return bgenv_user_free(((BGENV *)e->bgenv)->data->userdata);
177177
}
178178

179-
uint16_t ebg_env_getglobalstate(ebgenv_t __attribute__((unused)) *e)
179+
uint16_t ebg_env_getglobalstate(void __attribute__((unused)) *reserved)
180180
{
181181
BGENV *env;
182182
int res = USTATE_UNKNOWN;
183183

184+
if (!bgenv_init()) {
185+
errno = EIO;
186+
return res;
187+
}
188+
184189
/* Test for rolled-back condition. */
185190
for (int i = 0; i < ENV_NUM_CONFIG_PARTS; i++) {
186191
env = bgenv_open_by_index(i);

include/ebgenv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ int ebg_env_get_ex(ebgenv_t *e, char *key, uint64_t *datatype, uint8_t *buffer,
136136
uint32_t ebg_env_user_free(ebgenv_t *e);
137137

138138
/** @brief Get global ustate value, accounting for all environments
139-
* @param e A pointer to an ebgenv_t context.
139+
* @param reserved Historic parameter, must be NULL.
140140
* @return ustate value
141141
*/
142-
uint16_t ebg_env_getglobalstate(ebgenv_t *e);
142+
uint16_t ebg_env_getglobalstate(void *reserved);
143143

144144
/** @brief Set global ustate value, accounting for all environments
145145
* if state is set to zero and updating only current environment if

0 commit comments

Comments
 (0)