//------------------------------------------------------------------- // trynotif.c // // This driver is intented to investigate the statement made by // John O'Gorman about the 'notifier' field in the task_struct. // "A device driver can set up this pointer to a function to be // called when any of the signals specified in 'notifier_mask' // is generated. The driver can then decide whether to ignore // or handle this signal [Linux Process Manager, page 38]." // // Here is our plan for testing: // 1) create some stopped processes (e.g. using 'loadonly.cpp') // 2) install this device-driver // 3) this driver will install a pointer to a local function in // the 'notifier' field of every stopped task's task_struct, // and initialize the 'notifier_mask' field for all signals // 4) the 'kill' command will be issued by the user (to send a // signal to one of the 'stopped' tasks) // 5) check the log to see if our notifier-routine got called // // NOTE: Written and tested using Linux kernel version 2.4.26. // // programmer: ALLAN CRUSE // written on: 14 AUG 2004 //------------------------------------------------------------------- #include // for init_module() #include // for current #include // for sigset_t static char modname[] = "trynotif"; static sigset_t my_mask = { ~0LL }; static int my_notifier( void *priv ) { static int rep = 0; printk( "NOTIFICATION #%d: pid=%d \n", ++rep, current->pid ); return ~0; } int init_module( void ) { // install notifier-function in all stopped processes struct task_struct *tsk = current; while ( ( tsk = tsk->next_task ) != current ) if ( tsk->state == TASK_STOPPED ) { tsk->notifier = my_notifier; tsk->notifier_mask = &my_mask; printk( "pid=%5d %-16s \n", tsk->pid, tsk->comm ); } return 0; // SUCCESS } void cleanup_module( void ) { } MODULE_LICENSE("GPL");