+/*
+ * update_script_environment - process the list of set/unset options
+ * and update the script environment. Note that we intentionally do
+ * not update the TDB. These changes are layered on top right before
+ * exec. It is not possible to use script_setenv() or
+ * script_unsetenv() safely after this routine is run.
+ */
+static void
+update_script_environment()
+{
+ struct userenv *uep;
+
+ for (uep = userenv_list; uep != NULL; uep = uep->ue_next) {
+ int i;
+ char *p, *newstring;
+ int nlen = strlen(uep->ue_name);
+
+ for (i = 0; (p = script_env[i]) != NULL; i++) {
+ if (strncmp(p, uep->ue_name, nlen) == 0 && p[nlen] == '=')
+ break;
+ }
+ if (uep->ue_isset) {
+ nlen += strlen(uep->ue_value) + 2;
+ newstring = malloc(nlen + 1);
+ if (newstring == NULL)
+ continue;
+ *newstring++ = 0;
+ slprintf(newstring, nlen, "%s=%s", uep->ue_name, uep->ue_value);
+ if (p != NULL)
+ script_env[i] = newstring;
+ else
+ add_script_env(i, newstring);
+ } else {
+ remove_script_env(i);
+ }
+ }
+}
+