utmpx and struct futx - replicating who

I am in the process of learning systems programming in FreeBSD 12.1. I'm reading and working through Bruce Molay's 2002 book, "Understanding Unix/Linux Programming: A Guide to Theory and Practice." The author says the best way to learn systems programming is to think about, investigate, and emulate existing systems programs. I agree with him and have started doing this with FreeBSD. It's been fun and informative, but I'm dissatisfied with my work on the who command. I did my investigation man who man utx, etc. I specifically chose not to look at the who.c source code until after I've tried to implement it from the man pages and include files. It seemed like it should be as simple as reading in a utmpx struct from /var/run/utx.active and displaying it's fields. It didn't take long to realize that the file /var/run/utx.active doesn't contain utmpx structs... However, this was only apparent after I pulled it up in a debugger and looked at the alignment of the fields. After a search on the internet, I found a reference to struct futx. Then I dug around the source and found its header and c implementation. OK... it seems like I have 2 choices:

1. Use the getutxent access function and its cousins to read /var/run/utx.active into utmpx structures and print those out (works ok)
2. Read the file directly into futx structures and convert those to utmpx's (should work)

Unfortunately, while the second option is appealing as it doesn't rely on intermediary access functions, it isn't documented, as far as I can tell. So, I have a couple of questions :):

1. Why doesn't /var/run/utx.active contain utmpx records?
2. Why, if futx is a better format, isn't it documented and its functions available in the system libraries?

Forgive me if I misstated the situation, but it's all pretty new territory to me and the learning curve is awe inspiring. I look forward to any help y'all can give.

Thanks,

Will
 
Daemon book, second edition, page 800. I didn't actually read the page, I just looked at the index.

P.S. "Daemon book" means: Kirk McKusick et al., The Design and Implementation of the FreeBSD operating system. Everyone has to have one.
 
I've got it, a fine book, for sure. That page just says, "login is responsible for performing a variety of accounting functions including adding entries to the system lastlog and utmpx files" This, I know :).
 
That page just says, ...
Oops, not very helpful. Sorry about that. It's an interesting observation on the complexity of an operating system (which includes user-space utilities like who, file formats, and file system layouts) that a nearly 1000-page book only has 1 sentence for a topic on which many pages could be written.
 
Back
Top