Nerves: erinit

2020/02/21import

erlinit at 2020-02-14

リポジトリ

依存関係

libc

機能

initの置き換えとなる実行ファイル.

nerves_system_br(buildroot)上の busyboxベースで作られる rootfsに対して、 /sbin/initへシンボリックリンクが張られる. コマンドラインオプションでコマンド実行、マウント設定も行うことができる。

設定ファイル

/etc/erlinit.config

nerves_system_brの設定ファイルを参照するとよい。マウントオプションやerlangインタプリタ、サーチパスの設定がある。

引数の格納用に固定長配列(要素数 MAX_ARGC(=32))を使っているようで、ファイル中の設定とコマンドライン引数の総和がこれを超えられない。

FILE: src/options.c
Func: void parse_args(int argc, char *argv[])

ドキュメント(README.md)の以下の見出しにも明文化されている。迷ったらソースを読むと漏れはないだろう...

## Configuration and Command line options

主な流れ

FILE: src/erlinit.c Func: main()

    merge_config(argc, argv, &merged_argc, merged_argv);
    parse_args(merged_argc, merged_argv);

    /*
     * Mount devpts on /dev/pts, procfs on /proc, sysfs on /sys
     */
    setup_pseudo_filesystems();

    // Create symlinks for partitions on the drive containing the
    // root filesystem.
    create_rootdisk_symlinks();

    // Fix the terminal settings so output goes to the right
    // terminal and the CTRL keys work in the shell..
    set_ctty();

    fork_and_wait(&is_intentional_exit, &desired_reboot_cmd);

この中で child processを起こして、zombie processの回収を行う.

    // Set up a controlling terminal for Erlang so that
    // it's possible to get to shell management mode.
    // See http://www.busybox.net/FAQ.html#job_control

erl実行のための loopback i/f設定は netlink socketを触って設定している.. ipコマンドのたぐいではない...

FILE: src/network.c

static void configure_loopback(int ifindex)

という感じなので デフォルトで sshとかなんとかが使える状態ではない. erlinitの設定ファイルで、以下を使えば 任意のデーモンを起こしておくことはできそう. ただしネットワークインタフェースの設定は shoehornとかで行われるのかもしれないから, この時点では 外向けのinterfaceは死んでいると思ったほうがいいだろうな.

--pre-run-exec