Skip to content

Commit

Permalink
lib: Make parameter of ebg_env_getglobalstate obsolete
Browse files Browse the repository at this point in the history
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 <jan.kiszka@siemens.com>
  • Loading branch information
jan-kiszka committed Feb 25, 2025
1 parent 4520209 commit 3fd4e33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion env/env_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,16 @@ uint32_t ebg_env_user_free(ebgenv_t *e)
return bgenv_user_free(((BGENV *)e->bgenv)->data->userdata);
}

uint16_t ebg_env_getglobalstate(ebgenv_t __attribute__((unused)) *e)
uint16_t ebg_env_getglobalstate(void __attribute__((unused)) *reserved)
{
BGENV *env;
int res = USTATE_UNKNOWN;

if (!bgenv_init()) {
errno = EIO;
return res;
}

/* Test for rolled-back condition. */
for (int i = 0; i < ENV_NUM_CONFIG_PARTS; i++) {
env = bgenv_open_by_index(i);
Expand Down
4 changes: 2 additions & 2 deletions include/ebgenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ int ebg_env_get_ex(ebgenv_t *e, char *key, uint64_t *datatype, uint8_t *buffer,
uint32_t ebg_env_user_free(ebgenv_t *e);

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

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

0 comments on commit 3fd4e33

Please sign in to comment.