troglobit / finit

Fast init for Linux. Cookies included
https://troglobit.com/projects/finit/
MIT License
632 stars 63 forks source link

Getty doesn't preserve environment variables set in finit #286

Closed hongkongkiwi closed 2 years ago

hongkongkiwi commented 2 years ago

So I'm trying to figure out how to pass variables to the /bin/login invoked by the getting. Specifically I need to pass the -p option to /bin/login so that it preserves variables.

My finit config looks like this:

EDITOR=/usr/bin/nano
LANG=C.UTF-8
TERM=linux

tty [S1234578] /sbin/getty -L 0 /dev/ttyS0 nowait noclear linux

(p.s. is nowait noclear and linux settings passed to finit or to the getting? I was confused)

I'm using Busybox Getty and Busybox Login.

So if I was to try this normally I (think) I could do: /sbin/getty -L 0 -l /bin/login -- -p

But as finit specially parses -- as the start of the description I'm at a bit of a loss (!). Any ideas?

hongkongkiwi commented 2 years ago

FYR incase your not running busybox getty:

# /bin/login --help
BusyBox v1.33.0 () multi-call binary.

Usage: login [-p] [-h HOST] [[-f] USER]

Begin a new session on the system

    -f  Don't authenticate (user already authenticated)
    -h HOST Host user came from (for network logins)
    -p  Preserve environment

# /sbin/getty --help
BusyBox v1.33.0 () multi-call binary.

Usage: getty [OPTIONS] BAUD_RATE[,BAUD_RATE]... TTY [TERMTYPE]

Open TTY, prompt for login name, then invoke /bin/login

    -h      Enable hardware RTS/CTS flow control
    -L      Set CLOCAL (ignore Carrier Detect state)
    -m      Get baud rate from modem's CONNECT status message
    -n      Don't prompt for login name
    -w      Wait for CR or LF before sending /etc/issue
    -i      Don't display /etc/issue
    -f ISSUE_FILE   Display ISSUE_FILE instead of /etc/issue
    -l LOGIN    Invoke LOGIN instead of /bin/login
    -t SEC      Terminate after SEC if no login name is read
    -I INITSTR  Send INITSTR before anything else
    -H HOST     Log HOST into the utmp file as the hostname

BAUD_RATE of 0 leaves it unchanged
hongkongkiwi commented 2 years ago

Perhaps we could modify finit so if there are multiple -- then it looks for the last one as the description ? That way you can run commands with -- in the args ?

troglobit commented 2 years ago

There's unfortunately no way to do what you want to do at the moment. I'm not very keen on changing the parser in such a fundamental way eiter. The format is frozen until we move to the next-gen format, which likely will not be in the next release, more like 5.0. I was expecting -l '/bin/login -p' to work, but using quotes seem to have broke.

What I can do, however, for this particular use-case is add a specific tty option flag that can be passed to at least the built-in/bundled getty. E.g.,

tty [12345] console noclear passenv

Which would add -p when it calls /bin/login.

Something like That, or maybe you can call BusyBox getty with -l /bin/login-wrapper.sh which does exec /bin/login -p?

troglobit commented 2 years ago

Commit d904ec1 adds support for passenv, as mentioned in the previous comment. I hope that helps work around the problem at least short term.

I remain a bit curious though, is there anything wrong with the bundled getty, or is there some feature in BusyBox getty that I'm not aware of?

hongkongkiwi commented 2 years ago

Thank you very much.

To answer your question, Until very recently I didn't realise that finit provided a getty. Now I'm aware I wasn't sure if I should switch incase of unintended consequences.

I think I missed it because it's installed into: /libexec/finit/getty whereas the busybox getty is installed into /sbin/getty so when I used the finit getty command it was using the busybox getty by default as it was in the path.

(this may have been fixed with a make install from finit, but instead I have the config file something like this and I was missing the getty symlink:

define FINIT_POST_INSTALL_SBIN_INIT
  ln -s "../usr/sbin/finit" "$(TARGET_DIR)/sbin/telinit"
  ln -s "../usr/sbin/finit" "$(TARGET_DIR)/sbin/init"
  ln -s "initctl" "$(TARGET_DIR)/sbin/reboot"
  ln -s "initctl" "$(TARGET_DIR)/sbin/halt"
  ln -s "initctl" "$(TARGET_DIR)/sbin/shutdown"
  ln -s "initctl" "$(TARGET_DIR)/sbin/suspend"
  ln -s "initctl" "$(TARGET_DIR)/sbin/poweroff"
endef
hongkongkiwi commented 2 years ago

I may consider to change this now to make install as I'm using the full potential of finit, I think origionally I had it this way so I could separate out what was actually installed .e.g I was testing without having it as the default init, so I had an option in my Config.in to set it as the default init (which puts it in /sbin/init)

troglobit commented 2 years ago

Great, then maybe we can close this issue? I'll consider opening a new one for the malfunctioning '' arguments instead.

Yeah, the Finit getty used to be actually built-into the finit binary and then forked off from it on launch. It's in libexec mostly because of that logical separation, and that I don't want users mistaking it from a full-blown getty (for serial links etc.). It's only just enough to get you logged in basically. It lives in libexec with its siblinks logit and sulogin. The latter of which is also a cut-down version of the real thing.

hongkongkiwi commented 2 years ago

I've switched to the built in getty now, works well! thanks! :)

troglobit commented 2 years ago

Awesome to hear! 😎👍