Beispiel #1
0
kern_return_t
_S_msg_set_env_variable (mach_port_t msgport, mach_port_t auth,
			 char *variable,
			 char *value,
			 int replace)
{
  AUTHCHECK;

  if (__setenv (variable, value, replace)) /* XXX name space */
    return errno;
  return 0;
}
Beispiel #2
0
/*
 * The exposed setenv() that peforms a few tests before calling the function
 * (__setenv()) that does the actual work of inserting a variable into the
 * environment.
 */
int
setenv(const char *name, const char *value, int overwrite)
{
    size_t nameLen;

    /* Check for malformed name. */
    if (name == NULL || (nameLen = __strleneq(name)) == 0) {
        errno = EINVAL;
        return (-1);
    }

    /* Initialize environment. */
    if (__merge_environ() == -1 || (envVars == NULL && __build_env() == -1))
        return (-1);

    return (__setenv(name, nameLen, value, overwrite));
}
Beispiel #3
0
/*
 * If the program attempts to replace the array of environment variables
 * (environ) environ or sets the first varible to NULL, then deactivate all
 * variables and merge in the new list from environ.
 */
static int
__merge_environ(void)
{
    char **env;
    char *equals;

    /*
     * Internally-built environ has been replaced or cleared (detected by
     * using the count of active variables against a NULL as the first value
     * in environ).  Clean up everything.
     */
    if (intEnviron != NULL && (environ != intEnviron || (envActive > 0 &&
                               environ[0] == NULL))) {
        /* Deactivate all environment variables. */
        if (envActive > 0) {
            origEnviron = NULL;
            __clean_env(false);
        }

        /*
         * Insert new environ into existing, yet deactivated,
         * environment array.
         */
        origEnviron = environ;
        if (origEnviron != NULL)
            for (env = origEnviron; *env != NULL; env++) {
                if ((equals = strchr(*env, '=')) == NULL) {
                    __env_warnx(CorruptEnvValueMsg, *env,
                                strlen(*env));
                    errno = EFAULT;
                    return (-1);
                }
                if (__setenv(*env, equals - *env, equals + 1,
                             1) == -1)
                    return (-1);
            }
    }

    return (0);
}