Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 913613a5 authored by Elliott Hughes's avatar Elliott Hughes Committed by Android Git Automerger
Browse files

am ecba4dc0: am 85dfe988: am 796fccb8: Merge "Fix environment variable assignment in init"

* commit 'ecba4dc0':
  Fix environment variable assignment in init
parents e07d77e4 ecba4dc0
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@

#include <private/android_filesystem_config.h>

void add_environment(const char *name, const char *value);
int add_environment(const char *name, const char *value);

extern int init_module(void *, unsigned long, const char *);

@@ -261,8 +261,7 @@ int do_exec(int nargs, char **args)

int do_export(int nargs, char **args)
{
    add_environment(args[1], args[2]);
    return 0;
    return add_environment(args[1], args[2]);
}

int do_hostname(int nargs, char **args)
+20 −5
Original line number Diff line number Diff line
@@ -96,11 +96,24 @@ static const char *ENV[32];
/* add_environment - add "key=value" to the current environment */
int add_environment(const char *key, const char *val)
{
    int n;
    size_t n;
    size_t key_len = strlen(key);

    /* The last environment entry is reserved to terminate the list */
    for (n = 0; n < (ARRAY_SIZE(ENV) - 1); n++) {

    for (n = 0; n < 31; n++) {
        if (!ENV[n]) {
            size_t len = strlen(key) + strlen(val) + 2;
        /* Delete any existing entry for this key */
        if (ENV[n] != NULL) {
            size_t entry_key_len = strcspn(ENV[n], "=");
            if ((entry_key_len == key_len) && (strncmp(ENV[n], key, entry_key_len) == 0)) {
                free((char*)ENV[n]);
                ENV[n] = NULL;
            }
        }

        /* Add entry if a free slot is available */
        if (ENV[n] == NULL) {
            size_t len = key_len + strlen(val) + 2;
            char *entry = malloc(len);
            snprintf(entry, len, "%s=%s", key, val);
            ENV[n] = entry;
@@ -108,7 +121,9 @@ int add_environment(const char *key, const char *val)
        }
    }

    return 1;
    ERROR("No env. room to store: '%s':'%s'\n", key, val);

    return -1;
}

static void zap_stdio(void)