WSL icon indicating copy to clipboard operation
WSL copied to clipboard

/init does not create /var/run/utmp

Open christoh opened this issue 10 years ago • 15 comments

An empty (0 bytes) /var/run/utmp file should be created by /init

This would help with certain failures and/or warning messages of various programs (not only /bin/who).

My current workaround: Use 'touch /var/run/utmp' in some "system startup script".

christoh avatar Jun 23 '16 23:06 christoh

Certain files that are laid down by init or updated by the system during runtime are not yet supported. We are evaluating which ones we will be adding in the future.

Just out of curiosity, of what use are the errors/warnings typically available in utmp?

jackchammons avatar Jun 29 '16 22:06 jackchammons

Today i got an error message during apt-get upgrade which referenced the utmp file, just for the records (the full error message is no longer available since i cloded the terminal in the meantime).

fehrin avatar Aug 30 '16 14:08 fehrin

An empty (0 bytes) /var/run/utmp file should be created by /init

Not an empty one. One that establishes a runlevel, ref #1761. Goes spirituality to #2530 and #994 (depending on your disposition).

therealkenc avatar Jun 01 '18 10:06 therealkenc

From #1761 (message), a runlevel can be established with something along the lines of:

sudo bash -c "echo '[1] [00049] [~~  ] [runlevel] [~           ] [4.4.0-17115-Micoroso] [0.0.0.0        ] [Wed Feb 28 13:27:14 2018 STD]' | utmpdump -r > /var/run/utmp"

The ask here is that WSL brand /init establish a runlevel. It is a high value low cost ask that would quash longstanding errors/warnings that manifest in both WSL 1 and WSL 2. A minimalist (by-design ) init doesn't have to do much, but setting up /var/run/utmp is kind of on the short-list of things init has to do. The OP issue was submitted when WSL was largely a no-daemon affair (great for git/gcc/sed/awk, but not necessarily sshd/nginx/mongod) but that hasn't been the case for a long time now.

therealkenc avatar Jun 03 '20 20:06 therealkenc

The OP issue was submitted when WSL was largely a no-daemon affair (great for git/gcc/sed/awk, but not necessarily sshd/nginx/mongod) but that hasn't been the case for a long time now.

I was actually hoping this issue was mooted by WSL2 with its more full Linux support. I'm sad to see the wsl2 label applied. This issue is incredibly old with a seemingly 1-line fix possible. Is there a reason it's not getting addressed?

cbenard avatar Nov 02 '20 19:11 cbenard

Any progress? Is there a workaround available that would make commands like who, w, users etc. work?

viliml avatar Jan 03 '21 21:01 viliml

image

It would take a little more effort to make that phancy.

therealkenc avatar Jan 04 '21 01:01 therealkenc

sudo bash -c "echo '[1] [00049] [~~ ] [runlevel] [~ ] [4.4.0-17115-Micoroso] [0.0.0.0 ] [Wed Feb 28 13:27:14 2018 STD]' | utmpdump -r > /var/run/utmp"

running the above on 5.4.72-microsoft-standard-WSL2, returns: Utmp undump of /dev/stdin

running exit closes that terminal bash tab, instead of logout.

underlying issue: w, who -H, who -u returns 0 users!

newcanopies avatar Apr 09 '21 08:04 newcanopies

Try:

$ sudo bash -c "echo '[1] [00053] [~~  ] [runlevel] [~       ] [5.4.91-microsoft-standard-WSL2] [0.0.0.0    ] [2021-04-05T23:10:15,040218+00:00]' | utmpdump -r > /var/run/utmp" 2> /dev/null

Which sets up the runlevel, not the login user. You don't need it for who.

running exit closes that terminal bash tab, instead of logout.

That is by-design unless you start the terminal from a Windows shell.

image

All of which is for illustration to set up /var/run/utmp. No one would actually type these commands. It would take a little more effort to make that phancy.

therealkenc avatar Apr 09 '21 21:04 therealkenc

and $ w still returns 0 users

That is because the sudo bash line cited (quoth) "sets up the runlevel, not the login user". The login(1) command sets up the user for the login session.

I am having a bunch of user-permission issues due to this.

It is unlikely that you are having a bunch of user-permission issues due to a zero-thumbs-up feature request from 2016. Possible, but unlikely.

therealkenc avatar Apr 22 '21 18:04 therealkenc

@therealkenc

Which sets up the runlevel, not the login user. You don't need it for who.

and

and $ w still returns 0 users

That is because the sudo bash line cited (quoth) "sets up the runlevel, not the login user". The login(1) command sets up the user for the login session.

Are you saying that this issue is not directly related to the problem of who not working? If so, why were all of the issues (#913, #2806, #6393) closed as duplicates of this one?

who still doesn't work after doing this; is the solution to that to set up login as part of the uh, login process (which doesn't appear to be happening)?

klugerama avatar Aug 29 '22 19:08 klugerama

we could run a startup script form a automation who runs the touch /var/run/utmp

samohtGTO avatar Jan 10 '23 11:01 samohtGTO

Also who -m is unusable because of missing support for utmp/wtmp from WSL2 side.

oldium avatar Jun 29 '23 08:06 oldium

Could be this related to the fact that write or wall does not seem to work?

borjamunozf avatar Jul 12 '23 08:07 borjamunozf

you can use .bashrc to automaticly do the cmd

samohtGTO avatar Nov 06 '23 11:11 samohtGTO