From: Andreas Reichel <
andreas.r...@siemens.com>
Provide possibility to register user variables that are deleted
on finalization of an update.
Signed-off-by: Andreas Reichel <
andreas.r...@siemens.com>
---
env/env_api.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
include/ebgenv.h | 8 ++++++++
include/env_api.h | 5 +++++
3 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/env/env_api.c b/env/env_api.c
index 75695d1..fa32a15 100644
--- a/env/env_api.c
+++ b/env/env_api.c
@@ -240,10 +240,55 @@ int ebg_env_close(ebgenv_t *e)
return 0;
}
-int ebg_env_finalize_update(ebgenv_t *e) {
+int ebg_env_gc_register_var(ebgenv_t *e, char *key)
+{
+ GC_ITEM **pgci;
+ pgci = (GC_ITEM **)&e->gc_registry;
+
+ if (!key) {
+ return EINVAL;
+ }
+ while (*pgci) {
+ pgci = &((*pgci)->next);
+ }
+ *pgci = (GC_ITEM *)calloc(1, sizeof(GC_ITEM));
+ if (!*pgci) {
+ return ENOMEM;
+ }
+ if (asprintf(&((*pgci)->key), "%s", key) == -1) {
+ free(*pgci);
+ *pgci = NULL;
+ return ENOMEM;
+ }
+ return 0;
+}
+
+int ebg_env_finalize_update(ebgenv_t *e)
+{
if (!e->bgenv || !((BGENV *)e->bgenv)->data) {
return EIO;
}
+
+ GC_ITEM **pgci, *tmp;
+ uint8_t *udata;
+
+ pgci = (GC_ITEM **)&e->gc_registry;
+ udata = ((BGENV *)e->bgenv)->data->userdata;
+ while (*pgci) {
+ if ((*pgci)->key) {
+ uint8_t *var;
+ var = bgenv_find_uservar(udata, (*pgci)->key);
+ if (var) {
+ bgenv_del_uservar(udata, var);
+ }
+ free((*pgci)->key);
+ }
+ tmp = (*pgci)->next;
+ free(*pgci);
+ *pgci = NULL;
+ pgci = &tmp;
+ }
+
((BGENV *)e->bgenv)->data->in_progress = 0;
((BGENV *)e->bgenv)->data->ustate = USTATE_INSTALLED;
return 0;
diff --git a/include/ebgenv.h b/include/ebgenv.h
index 46e692c..8b158b7 100644
--- a/include/ebgenv.h
+++ b/include/ebgenv.h
@@ -35,6 +35,7 @@
typedef struct {
void *bgenv;
+ void *gc_registry;
} ebgenv_t;
/** @brief Tell the library to output information for the user.
@@ -128,6 +129,13 @@ int ebg_env_setglobalstate(ebgenv_t *e, uint16_t ustate);
*/
int ebg_env_close(ebgenv_t *e);
+/** @brief Register a variable that will be deleted on finalize
+ * @param e A pointer to an ebgenv_t context.
+ * @param key A string containing the variable key
+ * @return 0 on success, errno on failure
+ */
+int ebg_env_gc_register_var(ebgenv_t *e, char *key);
+
/** @brief Finalizes a currently running update procedure
* @param e A pointer to an ebgenv_t context.
* @return 0 on success, errno on failure
diff --git a/include/env_api.h b/include/env_api.h
index 4d652ff..ec73a64 100644
--- a/include/env_api.h
+++ b/include/env_api.h
@@ -66,6 +66,11 @@ typedef struct {
BG_ENVDATA *data;
} BGENV;
+typedef struct gc_item {
+ char *key;
+ struct gc_item *next;
+} GC_ITEM;
+
extern void bgenv_be_verbose(bool v);
extern char *str16to8(char *buffer, wchar_t *src);
--
2.16.2