* Allow init to delte extra environment variables (was local bug
#35858) * Avoid that init double environment variables for its childs (was local bug #35855)
This commit is contained in:
parent
2f904f7848
commit
d1a0609ab0
@ -1,6 +1,10 @@
|
|||||||
sysvinit (2.89dsf) UNRELEASED; urgency=low
|
sysvinit (2.89dsf) UNRELEASED; urgency=low
|
||||||
|
|
||||||
[ Werner Fink ]
|
[ Werner Fink ]
|
||||||
|
* Allow init to delte extra environment variables (was local bug
|
||||||
|
#35858)
|
||||||
|
* Avoid that init double environment variables for its childs
|
||||||
|
(was local bug #35855)
|
||||||
* Remove man-db tag for encoding for canonical man
|
* Remove man-db tag for encoding for canonical man
|
||||||
* Sulogin: try to detect the real device(s) used for the system console
|
* Sulogin: try to detect the real device(s) used for the system console
|
||||||
/dev/console if but only if /dev/console is used. On Linux this can
|
/dev/console if but only if /dev/console is used. On Linux this can
|
||||||
|
75
src/init.c
75
src/init.c
@ -248,7 +248,7 @@ void *imalloc(size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
char *istrdup(char *s)
|
char *istrdup(const char *s)
|
||||||
{
|
{
|
||||||
char *m;
|
char *m;
|
||||||
int l;
|
int l;
|
||||||
@ -880,6 +880,27 @@ void initlog(int loglevel, char *s, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add or replace specific environment value
|
||||||
|
*/
|
||||||
|
int addnewenv(const char *new, char **curr, int n)
|
||||||
|
{
|
||||||
|
size_t nlen = strcspn(new, "=");
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
if (nlen != strcspn(curr[i], "="))
|
||||||
|
continue;
|
||||||
|
if (strncmp (new, curr[i], nlen) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i >= n)
|
||||||
|
curr[n++] = istrdup(new);
|
||||||
|
else {
|
||||||
|
free(curr[i]);
|
||||||
|
curr[i] = istrdup(new);
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build a new environment for execve().
|
* Build a new environment for execve().
|
||||||
@ -888,7 +909,7 @@ char **init_buildenv(int child)
|
|||||||
{
|
{
|
||||||
char i_lvl[] = "RUNLEVEL=x";
|
char i_lvl[] = "RUNLEVEL=x";
|
||||||
char i_prev[] = "PREVLEVEL=x";
|
char i_prev[] = "PREVLEVEL=x";
|
||||||
char i_cons[32];
|
char i_cons[128];
|
||||||
char i_shell[] = "SHELL=" SHELL;
|
char i_shell[] = "SHELL=" SHELL;
|
||||||
char **e;
|
char **e;
|
||||||
int n, i;
|
int n, i;
|
||||||
@ -898,25 +919,30 @@ char **init_buildenv(int child)
|
|||||||
n += NR_EXTRA_ENV;
|
n += NR_EXTRA_ENV;
|
||||||
if (child)
|
if (child)
|
||||||
n += 8;
|
n += 8;
|
||||||
e = calloc(n, sizeof(char *));
|
|
||||||
|
while ((e = (char**)calloc(n, sizeof(char *))) == NULL) {
|
||||||
|
initlog(L_VB, "out of memory");
|
||||||
|
do_sleep(5);
|
||||||
|
}
|
||||||
|
|
||||||
for (n = 0; environ[n]; n++)
|
for (n = 0; environ[n]; n++)
|
||||||
e[n] = istrdup(environ[n]);
|
e[n] = istrdup(environ[n]);
|
||||||
|
|
||||||
for (i = 0; i < NR_EXTRA_ENV; i++) {
|
for (i = 0; i < NR_EXTRA_ENV; i++) {
|
||||||
if (extra_env[i])
|
if (extra_env[i] == NULL || *extra_env[i] == '\0')
|
||||||
e[n++] = istrdup(extra_env[i]);
|
continue;
|
||||||
|
n = addnewenv(extra_env[i], e, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child) {
|
if (child) {
|
||||||
snprintf(i_cons, sizeof(i_cons), "CONSOLE=%s", console_dev);
|
snprintf(i_cons, sizeof(i_cons), "CONSOLE=%s", console_dev);
|
||||||
i_lvl[9] = thislevel;
|
i_lvl[9] = thislevel;
|
||||||
i_prev[10] = prevlevel;
|
i_prev[10] = prevlevel;
|
||||||
e[n++] = istrdup(i_shell);
|
n = addnewenv(i_shell, e, n);
|
||||||
e[n++] = istrdup(i_lvl);
|
n = addnewenv(i_lvl, e, n);
|
||||||
e[n++] = istrdup(i_prev);
|
n = addnewenv(i_prev, e, n);
|
||||||
e[n++] = istrdup(i_cons);
|
n = addnewenv(i_cons, e, n);
|
||||||
e[n++] = istrdup(E_VERSION);
|
n = addnewenv(E_VERSION, e, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
e[n++] = NULL;
|
e[n++] = NULL;
|
||||||
@ -2133,41 +2159,46 @@ void fifo_new_level(int level)
|
|||||||
static
|
static
|
||||||
void initcmd_setenv(char *data, int size)
|
void initcmd_setenv(char *data, int size)
|
||||||
{
|
{
|
||||||
char *env, *p, *e, *eq;
|
char *env, *p, *e;
|
||||||
int i, sz;
|
size_t sz;
|
||||||
|
int i, eq;
|
||||||
|
|
||||||
e = data + size;
|
e = data + size;
|
||||||
|
|
||||||
while (*data && data < e) {
|
while (*data && data < e) {
|
||||||
eq = NULL;
|
|
||||||
for (p = data; *p && p < e; p++)
|
for (p = data; *p && p < e; p++)
|
||||||
if (*p == '=') eq = p;
|
;
|
||||||
if (*p) break;
|
if (*p) break;
|
||||||
env = data;
|
env = data;
|
||||||
data = ++p;
|
data = ++p;
|
||||||
|
|
||||||
sz = eq ? (eq - env) : (p - env);
|
|
||||||
|
|
||||||
/*initlog(L_SY, "init_setenv: %s, %s, %d", env, eq, sz);*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We only allow INIT_* to be set.
|
* We only allow INIT_* to be set.
|
||||||
*/
|
*/
|
||||||
if (strncmp(env, "INIT_", 5) != 0)
|
if (strncmp(env, "INIT_", 5) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
sz = strcspn(env, "=");
|
||||||
|
eq = (env[sz] == '=');
|
||||||
|
|
||||||
|
/*initlog(L_SY, "init_setenv: %s, %d, %d", env, eq, sz);*/
|
||||||
|
|
||||||
/* Free existing vars. */
|
/* Free existing vars. */
|
||||||
for (i = 0; i < NR_EXTRA_ENV; i++) {
|
for (i = 0; i < NR_EXTRA_ENV; i++) {
|
||||||
if (extra_env[i] == NULL) continue;
|
if (extra_env[i] == NULL)
|
||||||
if (!strncmp(extra_env[i], env, sz) &&
|
continue;
|
||||||
extra_env[i][sz] == '=') {
|
if (sz != strcspn(extra_env[i], "="))
|
||||||
|
continue;
|
||||||
|
if (strncmp(extra_env[i], env, sz) == 0) {
|
||||||
free(extra_env[i]);
|
free(extra_env[i]);
|
||||||
extra_env[i] = NULL;
|
extra_env[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eq == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Set new vars if needed. */
|
/* Set new vars if needed. */
|
||||||
if (eq == NULL) continue;
|
|
||||||
for (i = 0; i < NR_EXTRA_ENV; i++) {
|
for (i = 0; i < NR_EXTRA_ENV; i++) {
|
||||||
if (extra_env[i] == NULL) {
|
if (extra_env[i] == NULL) {
|
||||||
extra_env[i] = istrdup(env);
|
extra_env[i] = istrdup(env);
|
||||||
|
Loading…
Reference in New Issue
Block a user