/sbin/init overrides HOME and TERM env vars

jkm 8192 at wp.pl
Fri Mar 11 17:39:15 UTC 2022


Dear Paul

> I'm curious whether you can solve your problem by simply setting
> TERM and HOME in /etc/profile.  It looks to me like it should be
> read, given that you've started ash with "-/bin/ash" in inittab.

Of course, I have already done that, but I consider it
as a temporary workaround rather than a real solution.

> I haven't thought all that hard about this, but from looking at
> the code, and your requirements (which are surprising to me, but
> maybe shouldn't be), perhaps the best busybox change would be
> a new FEATURE_INIT_INHERIT_ENVIRONMENT, which prevents init from
> setting any environment at all.  I assume your boot code
> could set PATH and SHELL as well as TERM and HOME?
HOME and TERM environment variables are crucial for other programs
that init command is supposed to spawn. In my humble opinion,
user should be able to pass these env vars along with boot params
and expect init command to respect them. My proposal is to at least
add a check if HOME env var is set and only if HOME env var is not
passed, then set it to "/":

	/* Make sure environs is set to something sane */
-	putenv((char *) "HOME=/");
+	if (getenv("HOME") == NULL)
+		putenv((char *) "HOME=/");
+
	putenv((char *) bb_PATH_root_path);

What do you think?

Regards,
jkm


More information about the busybox mailing list