Here, we will write a simple kernel module to show a few members of the task structure and reveal the process context that its init and cleanup code paths run in. To do so, we cook up a show_ctx() function that uses current to access a few members of the task structure and display their values. It's invoked from both the init as well as the cleanup methods, as follows:
For reasons of readability and space constraints, only key parts of the source code are displayed here. The entire source tree for this book is available in its GitHub repository; we expect you to clone and use it: git clone https://github.com/PacktPublishing/Linux-Kernel-Programming.git.
/* code: ch6/current_affairs/current_affairs.c */
[ ... ]
#include <linux/sched.h> /* current */
#include <linux/cred.h> /* current_{e}{u,g}id() */
#include <linux/uidgid.h> /* {from,make}_kuid() */
[...]
#define OURMODNAME "...