init_env_poweroff: make into executable to reduce system noise

This commit is contained in:
Ciro Santilli
2018-09-02 21:54:16 +01:00
parent 41922a37fe
commit a6a712acef
3 changed files with 84 additions and 11 deletions

View File

@@ -2664,17 +2664,68 @@ ____
And you can try it out with:
....
./run -e 'init=/init_env_poweroff.sh - asdf=qwer zxcv'
./run -e 'init=/init_env_poweroff.out - asdf=qwer zxcv'
....
Source: link:rootfs_overlay/init_env_poweroff.sh[].
Also note how the annoying dash `-` also gets passed as a parameter to `init`, which makes it impossible to use this method for most executables.
Finally, the docs are lying, arguments with dots that come after `-` are still treated specially (of the form `subsystem.somevalue`) and disappear:
Output:
....
./run -e 'init=/init_env_poweroff.sh - /poweroff.out'
args:
/init_env_poweroff.out
-
zxcv
env:
HOME=/
TERM=linux
asdf=qwer
....
Source: link:kernel_module/user/init_env_poweroff.c[].
==== init environment args
The annoying dash `-` gets passed as a parameter to `init`, which makes it impossible to use this method for most non custom executables.
Arguments with dots that come after `-` are still treated specially (of the form `subsystem.somevalue`) and disappear, from args, e.g.:
....
./run -e 'init=/init_env_poweroff.out - /poweroff.out'
....
outputs:
....
args
/init_env_poweroff.out
-
ab
....
so see how `a.b` is gone.
==== init environment env
Wait, where do `HOME` and `TERM` come from? (greps the kernel). Ah, OK, the kernel sets those by default: https://github.com/torvalds/linux/blob/94710cac0ef4ee177a63b5227664b38c95bbf703/init/main.c#L173
....
const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
....
Furthermore, if you run something inside a shell:
....
./run -E '/usr/bin/env'
....
BusyBox also defines `SHLVL` and `PWD=`:
....
SHLVL=1
HOME=/
TERM=linux
lkmc_eval=L3Vzci9iaW4vZW52
PWD=/
....
=== Networking

View File

@@ -0,0 +1,26 @@
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <sys/reboot.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int i;
puts("args:");
for (i = 0; i < argc; ++i)
puts(argv[i]);
puts("");
puts("env:");
extern char **environ;
char **env = environ;
while (*env) {
printf("%s\n", *env);
env++;
}
puts("");
/* Poweroff. */
reboot(RB_POWER_OFF);
}

View File

@@ -1,4 +0,0 @@
#!/bin/sh
echo "$@"
env
/poweroff.out