diff --git a/sched/environ/env_dup.c b/sched/environ/env_dup.c index 4f773d78e3e..ae58b2a63f8 100644 --- a/sched/environ/env_dup.c +++ b/sched/environ/env_dup.c @@ -66,7 +66,6 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) { FAR char **envp = NULL; - irqstate_t flags; size_t envc = 0; size_t size; int ret = OK; @@ -81,7 +80,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) * environment may be shared. */ - flags = enter_critical_section(); + nxrmutex_lock(&group->tg_mutex); /* Count the strings */ @@ -142,8 +141,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) /* Save the child environment allocation. */ group->tg_envp = envp; - - leave_critical_section(flags); + nxrmutex_unlock(&group->tg_mutex); } return ret; diff --git a/sched/environ/env_getenv.c b/sched/environ/env_getenv.c index 7cc2805f14e..4513fa347a0 100644 --- a/sched/environ/env_getenv.c +++ b/sched/environ/env_getenv.c @@ -63,11 +63,8 @@ FAR char *getenv(FAR const char *name) FAR struct tcb_s *rtcb; FAR struct task_group_s *group; FAR char *pvalue = NULL; - irqstate_t flags; ssize_t ret = OK; - flags = enter_critical_section(); - /* Verify that a string was passed */ if (name == NULL) @@ -83,16 +80,26 @@ FAR char *getenv(FAR const char *name) /* Check if the variable exists */ - if (group == NULL || (ret = env_findvar(group, name)) < 0) + if (group == NULL) { goto errout; } + nxrmutex_lock(&group->tg_mutex); + ret = env_findvar(group, name); + if (ret < 0) + { + nxrmutex_unlock(&group->tg_mutex); + goto errout; + } + /* It does! Get the value sub-string from the name=value string */ pvalue = strchr(group->tg_envp[ret], '='); if (pvalue == NULL) { + nxrmutex_unlock(&group->tg_mutex); + /* The name=value string has no '=' This is a bug! */ ret = -EINVAL; @@ -102,11 +109,10 @@ FAR char *getenv(FAR const char *name) /* Adjust the pointer so that it points to the value right after the '=' */ pvalue++; - leave_critical_section(flags); + nxrmutex_unlock(&group->tg_mutex); return pvalue; errout: - leave_critical_section(flags); set_errno(-ret); return NULL; } diff --git a/sched/environ/env_setenv.c b/sched/environ/env_setenv.c index a64906180ba..ea24bdad99e 100644 --- a/sched/environ/env_setenv.c +++ b/sched/environ/env_setenv.c @@ -76,7 +76,6 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) ssize_t envc; ssize_t envpc; ssize_t ret = OK; - irqstate_t flags; int varlen; /* Verify input parameter */ @@ -111,11 +110,12 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) /* Get a reference to the thread-private environ in the TCB. */ - flags = enter_critical_section(); rtcb = this_task(); group = rtcb->group; DEBUGASSERT(group); + nxrmutex_lock(&group->tg_mutex); + /* Check if the variable already exists */ if (group->tg_envp && (ret = env_findvar(group, name)) >= 0) @@ -126,7 +126,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) { /* No.. then just return success */ - leave_critical_section(flags); + nxrmutex_unlock(&group->tg_mutex); return OK; } @@ -197,13 +197,13 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) /* Now, put the new name=value string into the environment buffer */ snprintf(pvar, varlen, "%s=%s", name, value); - leave_critical_section(flags); + nxrmutex_unlock(&group->tg_mutex); return OK; errout_with_var: group_free(group, pvar); errout_with_lock: - leave_critical_section(flags); + nxrmutex_unlock(&group->tg_mutex); errout: set_errno(ret); return ERROR; diff --git a/sched/environ/env_unsetenv.c b/sched/environ/env_unsetenv.c index fb4a206c5a5..5008ef7e01b 100644 --- a/sched/environ/env_unsetenv.c +++ b/sched/environ/env_unsetenv.c @@ -63,7 +63,6 @@ int unsetenv(FAR const char *name) { FAR struct tcb_s *rtcb = this_task(); FAR struct task_group_s *group = rtcb->group; - irqstate_t flags; ssize_t idx; DEBUGASSERT(group); @@ -78,7 +77,7 @@ int unsetenv(FAR const char *name) /* Check if the variable exists */ - flags = enter_critical_section(); + nxrmutex_lock(&group->tg_mutex); if (group && (idx = env_findvar(group, name)) >= 0) { /* It does! Remove the name=value pair from the environment. */ @@ -86,7 +85,7 @@ int unsetenv(FAR const char *name) env_removevar(group, idx); } - leave_critical_section(flags); + nxrmutex_unlock(&group->tg_mutex); return OK; }