From c3f6525854bbc664ce9fbed9754af1daf56ba08e Mon Sep 17 00:00:00 2001 From: Gerlando Falauto Date: Fri, 24 Aug 2012 00:11:37 +0000 Subject: env: unify logic to check and apply changes The logic of checking special parameters (e.g. baudrate, stdin, stdout, for a valid value and/or whether can be overwritten) and applying the new value to the running system is now all within a single function env_check_apply() which can be called whenever changes are made to the environment, no matter if by set, default or import. With this patch env_check_apply() is only called by "env set", retaining previous behavior. Signed-off-by: Gerlando Falauto Reviewed-by: Marek Vasut --- include/search.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/search.h') diff --git a/include/search.h b/include/search.h index ef53edb..a4a5ef4 100644 --- a/include/search.h +++ b/include/search.h @@ -99,6 +99,7 @@ extern int himport_r(struct hsearch_data *__htab, int __flag); /* Flags for himport_r() */ -#define H_NOCLEAR 1 /* do not clear hash table before importing */ +#define H_NOCLEAR (1 << 0) /* do not clear hash table before importing */ +#define H_FORCE (1 << 1) /* overwrite read-only/write-once variables */ #endif /* search.h */ -- cgit v1.1 From 348b1f1c6064990210a6797c86514fd358b73062 Mon Sep 17 00:00:00 2001 From: Gerlando Falauto Date: Fri, 24 Aug 2012 00:11:38 +0000 Subject: env: make himport_r() selective on variables Add 2 new arguments to himport_r(): o "nvars", "vars": number and list of variables to take into account (0 means ALL) NOTE: This patch does not change the current behaviour. Signed-off-by: Gerlando Falauto Reviewed-by: Marek Vasut --- include/search.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include/search.h') diff --git a/include/search.h b/include/search.h index a4a5ef4..94d75fc 100644 --- a/include/search.h +++ b/include/search.h @@ -94,9 +94,13 @@ extern ssize_t hexport_r(struct hsearch_data *__htab, const char __sep, char **__resp, size_t __size, int argc, char * const argv[]); +/* + * nvars: length of vars array + * vars: array of strings (variable names) to import (nvars == 0 means all) + */ extern int himport_r(struct hsearch_data *__htab, const char *__env, size_t __size, const char __sep, - int __flag); + int __flag, int nvars, char * const vars[]); /* Flags for himport_r() */ #define H_NOCLEAR (1 << 0) /* do not clear hash table before importing */ -- cgit v1.1 From c5983592e912835fe9ed00b9d98b05580c460eae Mon Sep 17 00:00:00 2001 From: Gerlando Falauto Date: Fri, 24 Aug 2012 00:11:39 +0000 Subject: env: add check/apply logic to himport_r() Change hashtable so that a callback function will decide whether a variable can be overwritten, and possibly apply the changes. So add a new field to struct hsearch_data: o "apply" callback function to check whether a variable can be overwritten, and possibly immediately apply the changes; when NULL, no check is performed. And a new argument to himport_r(): o "do_apply": whether to call the apply callback function NOTE: This patch does not change the current behavior. Signed-off-by: Gerlando Falauto Reviewed-by: Marek Vasut --- include/search.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'include/search.h') diff --git a/include/search.h b/include/search.h index 94d75fc..721c8ac 100644 --- a/include/search.h +++ b/include/search.h @@ -57,6 +57,16 @@ struct hsearch_data { struct _ENTRY *table; unsigned int size; unsigned int filled; +/* + * Callback function which will check whether the given change for variable + * "name" from "oldval" to "newval" may be applied or not, and possibly apply + * such change. + * When (flag & H_FORCE) is set, it shall not print out any error message and + * shall force overwriting of write-once variables. +.* Must return 0 for approval, 1 for denial. + */ + int (*apply)(const char *name, const char *oldval, + const char *newval, int flag); }; /* Create a new hashing table which will at most contain NEL elements. */ @@ -97,10 +107,12 @@ extern ssize_t hexport_r(struct hsearch_data *__htab, /* * nvars: length of vars array * vars: array of strings (variable names) to import (nvars == 0 means all) + * do_apply: whether to call callback function to check the new argument, + * and possibly apply changes (false means accept everything) */ extern int himport_r(struct hsearch_data *__htab, const char *__env, size_t __size, const char __sep, - int __flag, int nvars, char * const vars[]); + int __flag, int nvars, char * const vars[], int do_apply); /* Flags for himport_r() */ #define H_NOCLEAR (1 << 0) /* do not clear hash table before importing */ -- cgit v1.1 From 152874b65b8060e7b026933ce332a9687256e28c Mon Sep 17 00:00:00 2001 From: Gerlando Falauto Date: Fri, 24 Aug 2012 00:11:40 +0000 Subject: env: check and apply changes on delete/destroy Signed-off-by: Gerlando Falauto Reviewed-by: Marek Vasut --- include/search.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include/search.h') diff --git a/include/search.h b/include/search.h index 721c8ac..93e1cbc 100644 --- a/include/search.h +++ b/include/search.h @@ -73,7 +73,7 @@ struct hsearch_data { extern int hcreate_r(size_t __nel, struct hsearch_data *__htab); /* Destroy current internal hashing table. */ -extern void hdestroy_r(struct hsearch_data *__htab); +extern void hdestroy_r(struct hsearch_data *__htab, int do_apply); /* * Search for entry matching ITEM.key in internal hash table. If @@ -98,7 +98,8 @@ extern int hstrstr_r(const char *__match, int __last_idx, ENTRY ** __retval, struct hsearch_data *__htab); /* Search and delete entry matching ITEM.key in internal hash table. */ -extern int hdelete_r(const char *__key, struct hsearch_data *__htab); +extern int hdelete_r(const char *__key, struct hsearch_data *__htab, + int do_apply); extern ssize_t hexport_r(struct hsearch_data *__htab, const char __sep, char **__resp, size_t __size, -- cgit v1.1