dslm4515 / Musl-LFS

Linux From Scratch using Musl as Libc
GNU General Public License v3.0
170 stars 21 forks source link

utmp implementation #33

Open dslm4515 opened 4 years ago

dslm4515 commented 4 years ago

The Musl Libc does not have utmp functionality built-in like glibc.

Perhaps skarnet’s utmps should be built before coreutils? Without it, some commands like last will report /dev/null/utmp is not a directory

firasuke commented 3 years ago

Oh also:

The wtmpd example now uses /var/log/wtmp instead of /run/utmps/wtmp
since wtmp is supposed to survive across reboots.
dslm4515 commented 3 years ago

You are right, still need to patch those paths in musl libc headers... perhaps change paths to:

#define _PATH_UTMP      "/var/log/utmp"
#define _PATH_WTMP      "/var/log/wtmp"
dslm4515 commented 3 years ago

I rebuilt MLFS with latest SW as of June 2021... I accidentally packaged the whole rootfs instead of just my stage directory (where i fakeroot install)... which bricked the MLFS build.... nothing works (first bash couldnt resolved symbols then no commands and be found) unless i prefix every command with LD_LIBRARY_PATH=/lib:/usr/lib. I tried to re-create my build from the packages i made, but same issue. So I decided to scrap the build, and re-compile everything.

I get to util-linux and build fails. Same build instructions as before (no issue from what i can remember):

  CC       login-utils/lslogins-lslogins.o
In file included from login-utils/lslogins.c:39:
/usr/include/lastlog.h:1:10: fatal error: utmp.h: No such file or directory
    1 | #include <utmp.h>
      |          ^~~~~~~~
compilation terminated.
make[2]: *** [Makefile:11388: login-utils/lslogins-lslogins.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/sources/util-linux-2.36.2'
make[1]: *** [Makefile:13801: all-recursive] Error 1
make[1]: Leaving directory '/sources/util-linux-2.36.2'
make: *** [Makefile:5901: all] Error 2
(mlfs chroot) root:/sources/util-linux-2.36.2# 

Not sure why util-linux needs utmp.h. Check the source (of util-linux):

#include <lastlog.h>

Then i check that header, as it belongs to musl (version 1.2.2 in this build):

 #include <utmp.h>

wth. I removed that header, as i thought I am using skarnet's utmps to provide utmpx and not use musl's utmp.h

So i check lastlog.h from musl 1.2.1 source:

#ifndef _LASTLOG_H
#define _LASTLOG_H

#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

#define UT_HOSTSIZE 256
#define UT_LINESIZE 32

struct lastlog {
        time_t ll_time;
        char ll_line[UT_LINESIZE];
        char ll_host[UT_HOSTSIZE];
};

#ifdef __cplusplus
}
#endif

#endif

I thought musl only had stubs for utmp because it's hard to secure an implementation. Starting with musl-1.2.2, should I not remove headers utmp.h and utmpx.h? Skarnet's utmps installs it's headers in /usr/include/utmps

dslm4515 commented 3 years ago

Looking back at the beginning of this discussion, i should only need to remove musl's utmpx.h header in favor of skarnet's utmps utmpx.h...

firasuke commented 8 months ago

@dslm4515 So it seems that this is still an issue... After Y2038 many upstream software developers are moving with systemd's logind and disabling utmp/utmpx entirely, which is making it harder to maintain this.

What are your thoughts on this? Also is w (from util-linux) and login (from shadow) still working? Should we consider different alternatives that work with utmps?

firasuke commented 8 months ago

It seems that newer versions of shadow (starting from 4.14.0) have disabled utmpx entirely regardless of whether a distro is using utmps or not and they have switched to logind. This means that login is no longer storing utmp entries.

I opened an issue upstream to track this. Perhaps we can have support for utmps as well.

dslm4515 commented 8 months ago

Thank you for bringing it up.

I still have issues getting wtmp and/or utmp working. File itself is empty. But 'w' still works (somewhat-- lists users via ssh sessions but not on ttys? Maybe forgot to turn on support in shadow for utmpx?).

S6-Linux-init no longer has a built in boot script for running utmps daemon, so I'm trying to figure it out. S6+S6-RC booting appears complex to me... tempted to back to runnit.

But I do need to develop test(s) to make sure utmp/wtmp works.

For me, I like to stay away from systemd. I've been using seatd and turnstile instead of logind/elogind for a year or two so far.

firasuke commented 8 months ago

Thank you for bringing it up.

No worries, thought I'd ask for your input on this.

I still have issues getting wtmp and/or utmp working. File itself is empty. But 'w' still works (somewhat-- lists users via ssh sessions but not on ttys? Maybe forgot to turn on support in shadow for utmpx?).

shadow no longer has an option for utmpx (--enable-utmpx got removed).

S6-Linux-init no longer has a built in boot script for running utmps daemon, so I'm trying to figure it out. S6+S6-RC booting appears complex to me... tempted to back to runnit.

True, utmpd service was removed and was left to the user to implement. You can check the examples/ directory under the project utmps and see how you can get it to work.

For me, I like to stay away from systemd. I've been using seatd and turnstile instead of logind/elogind for a year or two so far.

I believe Chimera is moving in the right direction. I have to say your projects are somewhat similar.

dslm4515 commented 8 months ago

I believe Chimera is moving in the right direction. I have to say your projects are somewhat similar.

I would like to think, I developed CMLFS first before Chimera, but of course that doesnt matter. lol BUT I owe Chimera Linux a lot of thanks. Without them, I probably would be stuck on LLVM 12 or 13.

shadow no longer has an option for utmpx (--enable-utmpx got removed).

I think, I noticed that with by latest build of CMLFS. I can't remember. I'm using that build now to update BMLFS and see what breaks. I am behind on the 'base' repo, MLFS.

you can check the examples/ directory under the project utmps and see how you can get it to work.

Yes,I did check that... I haven't saved my boot scripts to a git repo yet. But seems my script seems to work as w does report users on ssh sessions. I have to figure out more tests to see if my boot script for utmps is doing its job

dslm4515 commented 8 months ago

Worse case scenario, I may end up [in far future] installing systemd/logind in /opt/systemd as a fallback... kind of how I still use libreSSL but have openSSL in /opt/openssl for software like Python 3.10+ that do not support libreSSL without heavy patching.