0

I am writing an LKM (loadable kernel Module) in C, I want to fetch information about users logged in currently and who is going to logout and login while LKM loaded.

Problem is LKM uses only system calls not library calls.
I have read utmp.h it uses library calls but LKM need system calls for this purpose.
I have also used strace who but I didn't get solution.

Claudio
  • 10,614
  • 4
  • 31
  • 71
Muhammad Azam
  • 535
  • 7
  • 12
  • 4
    The linux kernel doesn't really know and/or support the concept of logged-in users, this is all done purely in userspace. You could however find out if and how many processes associated with a certain userid are running – Ctx Jun 28 '18 at 14:32
  • That does not make sense to me. Do it in user space, let your kernel module provide an interface and your user space code communicates the results to your kernel module. – Adrian W Jun 28 '18 at 14:36
  • @AdrianW how can I provide interface to user space program in kernel module? – Muhammad Azam Jun 28 '18 at 14:49
  • One possibility is to create [sysfs](https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt) entries. That allows user space code to talk to your kernel module. There are [other solutions](https://stackoverflow.com/q/10816801/2311167) too, – Adrian W Jun 28 '18 at 14:55
  • **/var/log/wtmp** or **/var/run/utmp** files carry about logged users but these are binary files. which struct is used to read these files. – Muhammad Azam Jun 28 '18 at 17:18

0 Answers0